OpenGL ES 3.0 Texturing texture of explanation

By Michelle Moore,2015-07-11 21:22
12 views 0
OpenGL ES 3.0 Texturing texture of explanation

    Texture Filtering and Mipmapping Texture Filtering and multilevel Texture

    We have about a single 2 d image in front of the 2 d texture's introduction, this article focused on multilevel texture.Texture coordinates are used to generate a 2 d index, when set to GL_NEAREST zoom in and out, will be a single texture will match to the texture coordinates, this is a recent sampling points.

    When using a multilevel texture, and we can set the filter model, in order to achieve the screen pixel of image pixel and texture more suitable proportion, reducing the sawtooth.Because of the success of the multilevel texture map filtering, when in the more distant observation, we move to the map after the chain, sawtooth, achieving high quality images.

// Load mipmap level 0

    glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGB, width, height,

    0 , GL_RGB, GL_UNSIGNED_BYTE, pixels);

    level = 1 ;

    prevImage = &pixels[ 0 ];

    while (width > 1 && height > 1 )


     int newWidth,


     // Generate the next mipmap level

     GenMipMap2D( prevImage, &newImage, width, height, & newWidth,

     & newHeight);

     // Load the mipmap level

     glTexImage2D(GL_TEXTURE_2D, level, GL_RGB,

     newWidth, newHeight, 0 , GL_RGB,

     GL_UNSIGNED_BYTE, newImage);

     // Free the previous image


     // Set the previous image for the next iteration

     prevImage = newImage;

     level ++ ;

     // Half the width and height

     width = newWidth;

     height = newHeight;



    GenMipMap2D used to used to implement multilevel texture.There are two kinds of texture filtering: zoom in and out.When the design on the screen of the polygon is less than the size of the texture image, we use to reduce the texture.Instead use amplification.Use filter type automatically selected by the specific hardware, but the API also provides filtration control, enhanced processing is irrelevant, because we always use the best

    The available level.For narrow, there are various sampling mode can be used.Which model to use to choose based on your need to implement the visual quality and how you want to achieve the performance of texture filtering.Filtering model using glTexParameter [I | f] [v] to specify.

    Amplification filter can be GL_NEAREST or GL_LINEAR.In enlarge GL_NEAREST filter model, texture recently single will do the texture coordinates.In GL_LINEAR model, double linear (four points on average) as the texture coordinates.

    Narrow filtering can be the following values:

    •• GL_NEARESTTakes a single point sample from the texture nearest to the texture coordinate.

    •• GL_LINEAR—Takes a bilinear sample from the texture nearest to the texture coordinate.

    •• GL_NEAREST_MIPMAP_NEAREST—Takes a single point sample from the closest

    mip level chosen.

     •• GL_NEAREST_MIPMAP_LINEAR—Takes a sample from the two closest mip

    levels and interpolates between those samples.

     •• GL_LINEAR_MIPMAP_NEAREST—Takes a bilinear fetch from the closest mip

    level chosen.

     •• GL_LINEAR_MIPMAP_LINEAR—Takes a bilinear fetch from each of the two

    closest mip levels and then interpolates between them. This last mode, which is typically referred to as trilinear filtering, produces the best quality of all modes.

    GL_NEAREST and GL_LINEAR is the only do not need to complete narrowing of the multilevel texture filtering model, other all need complete multilevel processing.


    It is worth mentioning some performance will influence your choice of texture filtering model.For most of the hardware, using multilevel texture is the best choice.

    Seamless Cubemap Filtering

    It is 3.0 new features.When a linear filter core in the border of a cube texture, the filter only online in one side of the cube.You don't need to set a Seamless Cubemap Filtering, linear filter will automatically use it.

    Multilevel texture generated automatically

    We've created a level of 0 in front of multilevel texture, this is a way.Also provides automatic multistage glGenerateMipmap texture generation function.

    Binding on our team call glGenerateMipmap texture object, it will generate for us from the original image to the level of 0 chain multilevel texture.When you use the framebuffer object, automatic multilevel texture generation is particularly important.When rendering a texture, we don't want to read back the CPU texture generated in the multilevel texture.GlGenerateMipmap can solve this problem.

    Texture Coordinate Wrapping

    When the texture coordinates exceeds the range of [0.0, 1.0], using texture packaging.Texture packaging mode using glTexParameter [I | f] [v] to specify.

    Texture packaging mode can be set individually for s coordinate and a

    coordinate.GL_TEXTURE_WRAP_S schema definition s coordinates are beyond the scope of [0.0, 1.0], GL_TEXTURE_WRAP_T set t coordinates are beyond the scope of [0.0, 1.0].There are three kinds of packaging mode choice

    Note that the texture packaging mode effect of filtering of behavior.The texture coordinates is edge, for example, bilinear filtering will scan the edges of the texture.When packing model will determine which texture is the edge of the outside and is applied to filter algorithm.If you don't want any form of duplication, should use GL_CLAMP_TO_EDGE.

    Below is the use of texture mapping a square in the effect of three kinds of packaging



    void Draw ( ESContext * esContext )


     UserData *userData = esContext-> userData;

     GLfloat vVertices[] = { - 0.3f , 0.3f , 0.0f , 1.0f , // Position 0

     - 1.0f , - 1.0f , // TexCoord 0

     - 0.3f , - 0.3f , 0.0f , 1.0f , // Position 1

     - 1.0f , 2.0f , // TexCoord 1

     0.3f , - 0.3f , 0.0f , 1.0f , // Position 2

     2.0f , 2.0f , // TexCoord 2

     0.3f , 0.3f , 0.0f , 1.0f , // Position 3

     2.0f , - 1.0f // TexCoord 3


     GLushort indices[] = { 0 , 1 , 2 , 0 , 2 , 3 };

     // Set the viewport

     glViewport ( 0 , 0 , esContext->width, esContext-> height );

     // Clear the color buffer

     glClear ( GL_COLOR_BUFFER_BIT );

     // Use the program object

     glUseProgram ( userData-> programObject );

     // Load the vertex position

     glVertexAttribPointer ( 0 , 4 , GL_FLOAT,

     GL_FALSE, 6 * sizeof ( GLfloat ), vVertices );

     // Load the texture coordinate

     glVertexAttribPointer ( 1 , 2 , GL_FLOAT,

     GL_FALSE, 6 * sizeof ( GLfloat ), &vVertices[ 4 ] );

     glEnableVertexAttribArray ( 0 );

     glEnableVertexAttribArray ( 1 );

     // Bind the texture

     glActiveTexture ( GL_TEXTURE0 );

     glBindTexture ( GL_TEXTURE_2D, userData -> textureId );

     // Set the sampler texture unit to 0

     glUniform1i ( userData->samplerLoc, 0 );

     // Draw quad with repeat wrap mode

     glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );

     glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

     glUniform1f ( userData ->offsetLoc, - 0.7f );

     glDrawElements ( GL_TRIANGLES, 6 , GL_UNSIGNED_SHORT, indices );

     // Draw quad with clamp to edge wrap mode



     glUniform1f ( userData ->offsetLoc, 0.0f );

     glDrawElements ( GL_TRIANGLES, 6 , GL_UNSIGNED_SHORT, indices );

     // Draw quad with mirrored repeat



     glUniform1f ( userData ->offsetLoc, 0.7f );

     glDrawElements ( GL_TRIANGLES, 6 , GL_UNSIGNED_SHORT, indices ); }

Report this document

For any questions or suggestions please email