Changeset 814


Ignore:
Timestamp:
Aug 11, 2011, 2:35:13 PM (8 years ago)
Author:
sam
Message:

debug: reset the GL state more aggressively between quad renderings; this
helped find a few bugs such as textures not bound.

Location:
trunk/src/debug
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debug/quad.cpp

    r809 r814  
    119119    }
    120120
    121     /* Reset GL states to something reasonably safe */
    122     glMatrixMode(GL_PROJECTION);
    123     glLoadIdentity();
    124     glMatrixMode(GL_MODELVIEW);
    125     glLoadIdentity();
    126     glDisable(GL_TEXTURE_2D);
    127     glClientActiveTexture(GL_TEXTURE0);
    128     glBindBuffer(GL_ARRAY_BUFFER, 0);
    129     glUseProgram(0);
    130 
    131121    /* Prepare our quad coordinates */
    132122    vec2i const layout(4, 3);
     
    147137                                  f2, f4, f4, f1, f1, f3 };
    148138
     139    ResetState();
     140
    149141#if defined HAVE_GLBEGIN || defined USE_GLEW
    150142    /*
    151143     * Test #1: simple glBegin code
     144     *
    152145     * Renders an orange square.
    153146     */
     
    164157
    165158    Advance();
     159    ResetState();
    166160
    167161    /*
    168162     * Test #2: glBegin + per-vertex coloring
     163     *
    169164     * Renders a multicolored square with varying colors.
    170165     */
     166
    171167    glBegin(GL_TRIANGLES);
    172168        glColor3f(f1, f2, f3);
     
    185181
    186182    Advance();
     183    ResetState();
    187184
    188185    /*
    189186     * Test #3: glBegin + texture
     187     *
    190188     * Renders an animated black-and-white distorted checkerboard.
    191189     */
     
    211209
    212210    Advance();
     211    ResetState();
    213212
    214213    /*
    215214     * Test #4: glBegin + color in fragment shader
     215     *
    216216     * Renders a static, coloured and tiled pattern.
    217217     */
     
    246246
    247247    Advance();
    248 
    249     /*
    250      * Test #5: glBegin + pass color from vertex shader to fragment shader
     248    ResetState();
     249
     250    /*
     251     * Test #5: glBegin + pass vertex coord from vertex shader to fragment
     252     * shader for use as color information.
     253     *
    251254     * Renders a multicolored square with varying colors.
    252255     */
     
    259262            "    float r = gl_MultiTexCoord0.x;"
    260263            "    float g = gl_MultiTexCoord0.y;"
    261             "    pass_Color = vec4(1.0 - r, 1.0 - g, r, 1.0);"
     264            "    float b = gl_MultiTexCoord0.z;"
     265            "    pass_Color = vec4(r, g, b, 1.0);"
    262266            "    gl_Position = gl_Vertex;"
    263267            "}",
     
    272276    glColor3f(0.0f, 1.0f, 1.0f);
    273277    glBegin(GL_TRIANGLES);
    274         glTexCoord2f(f1, f3);
    275         glVertex3f(data->aa.x, data->bb.y, 0.0f);
    276         glTexCoord2f(f3, f2);
     278        glTexCoord3f(f1, f2, f3);
     279        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     280        glTexCoord3f(f4, f2, f1);
    277281        glVertex3f(data->bb.x, data->bb.y, 0.0f);
    278         glTexCoord2f(f2, f4);
    279         glVertex3f(data->bb.x, data->aa.y, 0.0f);
    280 
    281         glTexCoord2f(f2, f4);
    282         glVertex3f(data->bb.x, data->aa.y, 0.0f);
    283         glTexCoord2f(f4, f1);
     282        glTexCoord3f(f3, f1, f4);
     283        glVertex3f(data->bb.x, data->aa.y, 0.0f);
     284
     285        glVertex3f(data->bb.x, data->aa.y, 0.0f);
     286        glTexCoord3f(f4, f3, f2);
    284287        glVertex3f(data->aa.x, data->aa.y, 0.0f);
    285         glTexCoord2f(f1, f3);
    286         glVertex3f(data->aa.x, data->bb.y, 0.0f);
     288        glTexCoord3f(f1, f2, f3);
     289        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     290    glEnd();
    287291    glEnd();
    288292    glUseProgram(0);
    289293
    290294    Advance();
     295    ResetState();
    291296
    292297    /*
    293298     * Test #6: glBegin + apply texture in fragment shader
     299     *
    294300     * Renders an animated black-and-white distorted checkerboard with a
    295301     * zoom ratio twice the one in test #3.
     302     *
     303     * Note: there is no need to glEnable(GL_TEXTURE_2D) when the
     304     * texture lookup is done in a shader.
    296305     */
    297306    if (!data->shader[2])
     
    312321    data->shader[2]->Bind();
    313322    glColor3f(0.0f, 1.0f, 1.0f);
    314     glEnable(GL_TEXTURE_2D);
    315323    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
    316324    glBegin(GL_TRIANGLES);
     
    330338    glEnd();
    331339    glUseProgram(0);
    332     glDisable(GL_TEXTURE_2D);
    333 
    334     Advance();
     340
     341    Advance();
     342    ResetState();
    335343#endif
    336344
    337345    /*
    338346     * Test #7: vertex buffer + per-vertex coloring
     347     *
    339348     * Renders a multicolored square with varying colors.
    340349     */
     
    357366
    358367    Advance();
     368    ResetState();
    359369
    360370    /*
    361371     * Test #8: vertex buffer + per-vertex coloring + texture
     372     *
    362373     * Renders a multicolored square with varying colors multiplied with an
    363374     * animated distorted checkerboard.
     
    387398
    388399    Advance();
     400    ResetState();
    389401
    390402    /*
    391403     * Test #9: vertex buffer + texture & color in 1.10 fragment shader
     404     *
    392405     * Renders a multicolored square with varying colors xored with an
    393406     * animated distorted checkerboard.
     
    421434                                  data->aa.x, data->bb.y, 0.0f };
    422435
     436    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
     437
    423438    glEnableClientState(GL_VERTEX_ARRAY);
    424439    glEnableClientState(GL_COLOR_ARRAY);
     
    436451
    437452    Advance();
     453    ResetState();
    438454
    439455    /*
    440456     * Test #10: vertex buffer + texture & color in 1.20 fragment shader
     457     *
    441458     * Renders a multicolored square with varying colors xored with an
    442459     * animated distorted checkerboard.
     
    477494                                  data->aa.x, data->bb.y, 0.0f };
    478495
     496    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
     497
    479498    glBindVertexArray(data->array[0]);
    480499
     
    506525
    507526    Advance();
     527    ResetState();
    508528
    509529    /*
    510530     * Test #11: vertex buffer + texture & color in 1.30 fragment shader
     531     *
    511532     * Renders a multicolored square with varying colors xored with an
    512533     * animated distorted checkerboard.
     
    547568                                  data->aa.x, data->bb.y, 0.0f };
    548569
     570    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
     571
    549572    glBindVertexArray(data->array[1]);
    550573
     
    576599
    577600    Advance();
     601    ResetState();
     602}
     603
     604void DebugQuad::ResetState()
     605{
     606    /* Reset GL states to something reasonably safe */
     607    glMatrixMode(GL_PROJECTION);
     608    glLoadIdentity();
     609    glMatrixMode(GL_MODELVIEW);
     610    glLoadIdentity();
     611
     612    glEnable(GL_TEXTURE_2D);
     613    glBindTexture(GL_TEXTURE_2D, 0);
     614    glClientActiveTexture(GL_TEXTURE0);
     615    glDisable(GL_TEXTURE_2D);
     616
     617    glBindBuffer(GL_ARRAY_BUFFER, 0);
     618    glUseProgram(0);
    578619}
    579620
  • trunk/src/debug/quad.h

    r783 r814  
    3535
    3636private:
     37    void ResetState();
    3738    void Advance();
    3839
Note: See TracChangeset for help on using the changeset viewer.