Difference between revisions of "Multisample Texture"

From OpenGL Wiki
Jump to navigation Jump to search
(Added linking, formatting, and improved descriptions.)
 
Line 1: Line 1:
A '''Multisample Texture''' is a [[Texture]] that can have multiple samples per pixel. This allows them to be used as [[Multisampling|multisample]] render targets and also as source data for [[Shader|shaders]].
+
A '''Multisample Texture''' is a [[Texture]] that can have [[Multisampling|multiple samples per pixel]], thereby allowing it to be used in multisampled rendering. As they are textures, their multiple samples can also be fetched from [[Shader|shaders]].
  
As you would use glTexImage2D , here we can use glTexImage2DMultisample.
+
{{stub}}
Primary use is for creating Frame buffers and providing them support for multi sampling:
 
  
        glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, t);
+
There are only two multisampled texture targets: 2D textures, and 2D array textures ({{enum|GL_TEXTURE_2D_MULTISAMPLE}} and {{enum|GL_TEXTURE_2D_ARRAY_MULTISAMPLE}} respectively).
        glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, w, h, GL_TRUE);
 
Now you may use this texture with your Frame buffer object:
 
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, t, 0);
 
  
Similar functions are provided for using multisample render buffer with your frame buffer: e.g.: '''glRenderbufferStorageMultisample'''
+
Creating a multisample texture requires using {{apifunc|glTexStorage2DMultisample}}, {{apifunc|glTexStorage3DMultisample}} for 2D array textures (or the {{code|glTexImage*Multisample}} equivalents:
  
You may use '''glBlitFramebuffer''' to copy this Frame buffer to any regular frame buffer.
+
<syntaxhighlight lang="cpp">
 +
GLuint tex;
 +
glGenTextures(1, &tex);
 +
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);
 +
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA8, w, h, GL_TRUE);
 +
 
 +
//Attach to an FBO:
 +
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);
 +
</syntaxhighlight>
 +
 
 +
Similar functions are provided for using multisample render buffer with your frame buffer: e.g.: {{apifunc|glRenderbufferStorageMultisample}}
 +
 
 +
You may use {{apifunc|glBlitFramebuffer}} to perform a [[Multisampling#Multisample_Resolve|multisample resolve operation]] by [[Framebuffer#Blitting|copying to a non-multisampled framebuffer object]].
  
 
[[Category:Textures]]
 
[[Category:Textures]]

Latest revision as of 18:25, 14 May 2021

A Multisample Texture is a Texture that can have multiple samples per pixel, thereby allowing it to be used in multisampled rendering. As they are textures, their multiple samples can also be fetched from shaders.

There are only two multisampled texture targets: 2D textures, and 2D array textures (GL_TEXTURE_2D_MULTISAMPLE and GL_TEXTURE_2D_ARRAY_MULTISAMPLE respectively).

Creating a multisample texture requires using glTexStorage2DMultisample, glTexStorage3DMultisample for 2D array textures (or the glTexImage*Multisample equivalents:

GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA8, w, h, GL_TRUE);

//Attach to an FBO:
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);

Similar functions are provided for using multisample render buffer with your frame buffer: e.g.: glRenderbufferStorageMultisample

You may use glBlitFramebuffer to perform a multisample resolve operation by copying to a non-multisampled framebuffer object.