Question

i want to use multisampled textures.

What will be the fragment shader and how to pass multiple samplers to shader?

Also, which API can be used to load texel data ?

I want to use default FBO for this.

Was it helpful?

Solution

Your topic is still quite broad and it would be hard to give a deep answer here.In fact you ask here 3 not so trivial questions for which you should read related literature.Whereas the best for you would be to start from here and probably acquire this book also. My answers assume you are using modern (programmable) OpenGL :

i want to use multisampled textures.

Assuming you need it when using your own frame buffer for using default ones you don't need multisampling because it is done for you automatically.All you need is to define a number of samples when creating OpenGL context (with GLFW lib for example). So if you have a custom framebuffer object (FBO) and want to multisample a texture to get rid of aliased edges you should create a multisampled texture object :

glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_TRUE);

Attach it to the FBO.Then the actual rendering process works like this:

You bind your FBO with MS texture attachment.Render your geometry.Then you RESOLVE the multisampled texture or into a regular texture or directly into the default backbuffer by blitting:

glBlitFramebuffer(
    0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
    0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
    GL_COLOR_BUFFER_BIT, GL_NEAREST);

The overall render procedure should be like this:

void display()
{
glProgramUniform1i(ProgramName, UniformDiffuse, 0);

// Clear the framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

glUseProgram(ProgramName);

// Pass 1
// Render the scene in a multisampled framebuffer
glEnable(GL_MULTISAMPLE);
renderFBO(ProgramName, FramebufferRenderName);
glDisable(GL_MULTISAMPLE);

// Resolved multisampling
glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferRenderName);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBlitFramebuffer(
    0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
    0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
    GL_COLOR_BUFFER_BIT, GL_NEAREST);





swapBuffers();
}

By the way these code snippets are taken from this great site where you can find OpenGL code example showcasing solution to many general problems (including yours).

What will be the fragment shader and how to pass multiple samplers to shader?

Download the examples from the above mentioned site and take a look at ogl-330-fbo-multisample.cpp and the enclosed fragment shader.

Also, which API can be used to load texel data ? Which APIs to be used to apply this texture?

You can use GLFW to load TGA textures easily.And if you want to load pretty any possible image format then take a look at DevIL

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top