Changeset 822


Ignore:
Timestamp:
Aug 12, 2011, 6:33:30 PM (8 years ago)
Author:
sam
Message:

debug: refactor quad test.

File:
1 edited

Legend:

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

    r819 r822  
    3030
    3131static int const NUM_ARRAYS = 2;
    32 static int const NUM_BUFFERS = 6;
     32static int const NUM_BUFFERS = 9;
    3333static int const NUM_ATTRS = 6;
    3434static int const NUM_SHADERS = 6;
     
    4646    int initialised;
    4747    float time;
    48 #if !defined __CELLOS_LV2__
     48#if !defined __CELLOS_LV2__ && !defined ANDROID_NDK
    4949    GLuint array[NUM_ARRAYS];
    5050#endif
     
    143143                                  f2, f4, f4, f1, f1, f3 };
    144144
     145    /* Cheap iterators */
     146#if !defined __CELLOS_LV2__ && !defined ANDROID_NDK
     147    GLuint *array = data->array;
     148#endif
     149    GLuint *buffer = data->buffer;
     150    Shader **shader = data->shader;
     151    GLuint *attr = data->attr;
     152
    145153    ResetState();
    146154
     
    168176     * Test #2: glBegin + per-vertex coloring
    169177     *
    170      * Renders a multicolored square with varying colors.
     178     * Renders a multicoloured square with varying colors.
    171179     */
    172180
     
    222230     * Renders a static, coloured and tiled pattern.
    223231     */
    224 #if !defined __CELLOS_LV2__
    225     if (!data->shader[0])
    226         data->shader[0] = Shader::Create(
     232    if (!shader[0])
     233        shader[0] = Shader::Create(
    227234            "#version 110\n"
    228235            "void main()"
     
    239246            "    gl_FragColor = vec4(dx, dy, dz, 1.0);"
    240247            "}");
    241     data->shader[0]->Bind();
     248    shader[0]->Bind();
     249    shader++;
    242250    glColor3f(0.0f, 1.0f, 1.0f);
    243251    glBegin(GL_TRIANGLES);
     
    254262    Advance();
    255263    ResetState();
    256 #endif
    257264
    258265    /*
     
    260267     * shader for use as color information.
    261268     *
    262      * Renders a multicolored square with varying colors.
    263      */
    264 #if !defined __CELLOS_LV2__
    265     if (!data->shader[1])
    266         data->shader[1] = Shader::Create(
     269     * Renders a multicoloured square with varying colors.
     270     */
     271    if (!shader[0])
     272        shader[0] = Shader::Create(
    267273            "#version 110\n"
    268274            "varying vec4 pass_Color;"
     
    282288            "    gl_FragColor = pass_Color;"
    283289            "}");
    284     data->shader[1]->Bind();
     290    shader[0]->Bind();
     291    shader++;
    285292    glColor3f(0.0f, 1.0f, 1.0f);
    286293    glBegin(GL_TRIANGLES);
     
    302309    Advance();
    303310    ResetState();
    304 #endif
    305311
    306312    /*
     
    313319     * texture lookup is done in a shader.
    314320     */
    315 #if !defined __CELLOS_LV2__
    316     if (!data->shader[2])
    317         data->shader[2] = Shader::Create(
     321    if (!shader[0])
     322        shader[0] = Shader::Create(
    318323            "#version 110\n"
    319324            "void main()"
     
    329334            "    gl_FragColor = texture2D(tex, gl_TexCoord[0].xy * 0.25);"
    330335            "}");
    331     data->shader[2]->Bind();
     336    shader[0]->Bind();
     337    shader++;
    332338    glColor3f(0.0f, 1.0f, 1.0f);
    333339    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
     
    352358    ResetState();
    353359#endif
    354 #endif
    355 
     360
     361    /*
     362     * Test #7: simple vertex buffer
     363     *
     364     * Renders an orange square.
     365     */
    356366#if !defined ANDROID_NDK
    357     /*
    358      * Test #7: vertex buffer + per-vertex coloring
    359      *
    360      * Renders a multicolored square with varying colors.
    361      */
    362367    GLfloat const vertices1[] = { data->aa.x, data->bb.y, 0.0f,
    363368                                  data->bb.x, data->bb.y, 0.0f,
     
    367372                                  data->aa.x, data->bb.y, 0.0f };
    368373
    369     glEnableClientState(GL_COLOR_ARRAY);
     374    glColor4f(0.8f, 0.5f, 0.2f, 1.0f);
    370375    glEnableClientState(GL_VERTEX_ARRAY);
    371376
    372     glColorPointer(3, GL_FLOAT, 0, colors);
    373377    glVertexPointer(3, GL_FLOAT, 0, vertices1);
    374378    glDrawArrays(GL_TRIANGLES, 0, 6);
    375379
    376380    glDisableClientState(GL_VERTEX_ARRAY);
    377     glDisableClientState(GL_COLOR_ARRAY);
    378 
    379     Advance();
    380     ResetState();
    381 #endif
    382 
    383     /*
    384      * Test #8: vertex buffer + per-vertex coloring + texture
    385      *
    386      * Renders a multicolored square with varying colors multiplied with an
    387      * animated distorted checkerboard.
     381
     382    Advance();
     383    ResetState();
     384#endif
     385
     386    /*
     387     * Test #8: vertex buffer + per-vertex coloring
     388     *
     389     * Renders a multicoloured square with varying colors.
    388390     */
    389391#if !defined ANDROID_NDK
     
    395397                                  data->aa.x, data->bb.y, 0.0f };
    396398
     399    glEnableClientState(GL_VERTEX_ARRAY);
     400    glEnableClientState(GL_COLOR_ARRAY);
     401
     402    glVertexPointer(3, GL_FLOAT, 0, vertices2);
     403    glColorPointer(3, GL_FLOAT, 0, colors);
     404    glDrawArrays(GL_TRIANGLES, 0, 6);
     405
     406    glDisableClientState(GL_VERTEX_ARRAY);
     407    glDisableClientState(GL_COLOR_ARRAY);
     408
     409    Advance();
     410    ResetState();
     411#endif
     412
     413    /*
     414     * Test #9: vertex buffer + per-vertex coloring + texture
     415     *
     416     * Renders a multicoloured square with varying colors multiplied with an
     417     * animated distorted checkerboard.
     418     */
     419#if !defined ANDROID_NDK
     420    GLfloat const vertices3[] = { data->aa.x, data->bb.y, 0.0f,
     421                                  data->bb.x, data->bb.y, 0.0f,
     422                                  data->bb.x, data->aa.y, 0.0f,
     423                                  data->bb.x, data->aa.y, 0.0f,
     424                                  data->aa.x, data->aa.y, 0.0f,
     425                                  data->aa.x, data->bb.y, 0.0f };
     426
    397427    glEnable(GL_TEXTURE_2D);
    398428    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
     429    glEnableClientState(GL_VERTEX_ARRAY);
    399430    glEnableClientState(GL_COLOR_ARRAY);
    400431    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    401     glEnableClientState(GL_VERTEX_ARRAY);
    402 
     432
     433    glVertexPointer(3, GL_FLOAT, 0, vertices3);
    403434    glColorPointer(3, GL_FLOAT, 0, colors);
    404435    glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
    405     glVertexPointer(3, GL_FLOAT, 0, vertices2);
     436
    406437    glDrawArrays(GL_TRIANGLES, 0, 6);
    407438
    408439    glDisableClientState(GL_VERTEX_ARRAY);
     440    glDisableClientState(GL_COLOR_ARRAY);
    409441    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    410     glDisableClientState(GL_COLOR_ARRAY);
    411442    glDisable(GL_TEXTURE_2D);
    412443
     
    416447
    417448    /*
    418      * Test #9: vertex buffer + texture & color in 1.10 fragment shader
    419      *
    420      * Renders a multicolored square with varying colors xored with an
     449     * Test #10: vertex buffer + texture & color in 1.10 fragment shader
     450     *
     451     * Renders a multicoloured square with varying colors xored with an
    421452     * animated distorted checkerboard.
    422453     */
    423454#if !defined __CELLOS_LV2__ && !defined ANDROID_NDK
    424     if (!data->shader[3])
    425         data->shader[3] = Shader::Create(
     455    if (!shader[0])
     456        shader[0] = Shader::Create(
    426457            "#version 110\n"
    427458            "varying vec4 pass_Color;"
     
    442473            "}");
    443474
    444     data->shader[3]->Bind();
    445     GLfloat const vertices3[] = { data->aa.x, data->bb.y, 0.0f,
     475    shader[0]->Bind();
     476    shader++;
     477    GLfloat const vertices4[] = { data->aa.x, data->bb.y, 0.0f,
    446478                                  data->bb.x, data->bb.y, 0.0f,
    447479                                  data->bb.x, data->aa.y, 0.0f,
     
    456488    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    457489
    458     glVertexPointer(3, GL_FLOAT, 0, vertices3);
     490    glVertexPointer(3, GL_FLOAT, 0, vertices4);
    459491    glColorPointer(3, GL_FLOAT, 0, colors);
    460492    glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
     
    471503
    472504    /*
    473      * Test #10: vertex buffer + texture & color in 1.20 fragment shader
    474      *
    475      * Renders a multicolored square with varying colors xored with an
     505     * Test #11: vertex buffer + texture & color in 1.20 fragment shader
     506     *
     507     * Renders a multicoloured square with varying colors xored with an
    476508     * animated distorted checkerboard.
    477509     */
    478510#if !defined __CELLOS_LV2__ && !defined ANDROID_NDK
    479     if (!data->shader[4])
     511    if (!shader[0])
    480512    {
    481         data->shader[4] = Shader::Create(
     513        shader[0] = Shader::Create(
    482514            "#version 120\n"
    483515            "attribute vec3 in_Vertex;"
     
    500532            "    gl_FragColor = vec4(abs(tmp.xyz - pass_Color.xyz), 1.0);"
    501533            "}");
    502         data->attr[0] = data->shader[4]->GetAttribLocation("in_Vertex");
    503         data->attr[1] = data->shader[4]->GetAttribLocation("in_Color");
    504         data->attr[2] = data->shader[4]->GetAttribLocation("in_MultiTexCoord0");
     534        attr[0] = shader[0]->GetAttribLocation("in_Vertex");
     535        attr[1] = shader[0]->GetAttribLocation("in_Color");
     536        attr[2] = shader[0]->GetAttribLocation("in_MultiTexCoord0");
    505537    }
    506     data->shader[4]->Bind();
    507     GLfloat const vertices4[] = { data->aa.x, data->bb.y, 0.0f,
     538    shader[0]->Bind();
     539    shader++;
     540    GLfloat const vertices5[] = { data->aa.x, data->bb.y, 0.0f,
    508541                                  data->bb.x, data->bb.y, 0.0f,
    509542                                  data->bb.x, data->aa.y, 0.0f,
     
    514547    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
    515548
    516     glBindVertexArray(data->array[0]);
    517 
    518     glBindBuffer(GL_ARRAY_BUFFER, data->buffer[0]);
    519     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices4), vertices4,
     549    glBindVertexArray(*array++);
     550
     551    glBindBuffer(GL_ARRAY_BUFFER, *buffer++);
     552    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices5), vertices5,
    520553                 GL_DYNAMIC_DRAW);
    521     glVertexAttribPointer(data->attr[0], 3, GL_FLOAT, GL_FALSE, 0, 0);
    522     glEnableVertexAttribArray(data->attr[0]);
    523 
    524     glBindBuffer(GL_ARRAY_BUFFER, data->buffer[1]);
     554    glVertexAttribPointer(attr[0], 3, GL_FLOAT, GL_FALSE, 0, 0);
     555    glEnableVertexAttribArray(attr[0]);
     556
     557    glBindBuffer(GL_ARRAY_BUFFER, *buffer++);
    525558    glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors,
    526559                 GL_DYNAMIC_DRAW);
    527     glVertexAttribPointer(data->attr[1], 3, GL_FLOAT, GL_FALSE, 0, 0);
    528     glEnableVertexAttribArray(data->attr[1]);
    529 
    530     glBindBuffer(GL_ARRAY_BUFFER, data->buffer[2]);
     560    glVertexAttribPointer(attr[1], 3, GL_FLOAT, GL_FALSE, 0, 0);
     561    glEnableVertexAttribArray(attr[1]);
     562
     563    glBindBuffer(GL_ARRAY_BUFFER, *buffer++);
    531564    glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords,
    532565                 GL_DYNAMIC_DRAW);
    533     glVertexAttribPointer(data->attr[2], 2, GL_FLOAT, GL_FALSE, 0, 0);
    534     glEnableVertexAttribArray(data->attr[2]);
     566    glVertexAttribPointer(attr[2], 2, GL_FLOAT, GL_FALSE, 0, 0);
     567    glEnableVertexAttribArray(attr[2]);
    535568
    536569    glDrawArrays(GL_TRIANGLES, 0, 6);
    537570    glBindVertexArray(0);
    538571
    539     glDisableVertexAttribArray(data->attr[0]);
    540     glDisableVertexAttribArray(data->attr[1]);
    541     glDisableVertexAttribArray(data->attr[2]);
     572    glDisableVertexAttribArray(*attr++);
     573    glDisableVertexAttribArray(*attr++);
     574    glDisableVertexAttribArray(*attr++);
    542575    glUseProgram(0);
    543576
     
    547580
    548581    /*
    549      * Test #11: vertex buffer + texture & color in 1.30 fragment shader
    550      *
    551      * Renders a multicolored square with varying colors xored with an
     582     * Test #12: vertex buffer + texture & color in 1.30 fragment shader
     583     *
     584     * Renders a multicoloured square with varying colors xored with an
    552585     * animated distorted checkerboard.
    553586     */
    554587#if !defined __CELLOS_LV2__ && !defined ANDROID_NDK
    555     if (!data->shader[5])
     588    if (!shader[0])
    556589    {
    557         data->shader[5] = Shader::Create(
     590        shader[0] = Shader::Create(
    558591            "#version 130\n"
    559592            "in vec3 in_Vertex;"
     
    576609            "    gl_FragColor = vec4(abs(tmp.xyz - pass_Color.xyz), 1.0);"
    577610            "}");
    578         data->attr[3] = data->shader[4]->GetAttribLocation("in_Vertex");
    579         data->attr[4] = data->shader[4]->GetAttribLocation("in_Color");
    580         data->attr[5] = data->shader[4]->GetAttribLocation("in_MultiTexCoord0");
     611        attr[0] = shader[0]->GetAttribLocation("in_Vertex");
     612        attr[1] = shader[0]->GetAttribLocation("in_Color");
     613        attr[2] = shader[0]->GetAttribLocation("in_MultiTexCoord0");
    581614    }
    582     data->shader[5]->Bind();
    583     GLfloat const vertices5[] = { data->aa.x, data->bb.y, 0.0f,
     615    shader[0]->Bind();
     616    shader++;
     617    GLfloat const vertices6[] = { data->aa.x, data->bb.y, 0.0f,
    584618                                  data->bb.x, data->bb.y, 0.0f,
    585619                                  data->bb.x, data->aa.y, 0.0f,
     
    590624    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
    591625
    592     glBindVertexArray(data->array[1]);
    593 
    594     glBindBuffer(GL_ARRAY_BUFFER, data->buffer[3]);
    595     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices5), vertices5,
     626    glBindVertexArray(*array++);
     627
     628    glBindBuffer(GL_ARRAY_BUFFER, *buffer++);
     629    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices6), vertices6,
    596630                 GL_DYNAMIC_DRAW);
    597     glVertexAttribPointer(data->attr[3], 3, GL_FLOAT, GL_FALSE, 0, 0);
    598     glEnableVertexAttribArray(data->attr[3]);
    599 
    600     glBindBuffer(GL_ARRAY_BUFFER, data->buffer[4]);
     631    glVertexAttribPointer(attr[0], 3, GL_FLOAT, GL_FALSE, 0, 0);
     632    glEnableVertexAttribArray(attr[0]);
     633
     634    glBindBuffer(GL_ARRAY_BUFFER, *buffer++);
    601635    glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors,
    602636                 GL_DYNAMIC_DRAW);
    603     glVertexAttribPointer(data->attr[4], 3, GL_FLOAT, GL_FALSE, 0, 0);
    604     glEnableVertexAttribArray(data->attr[4]);
    605 
    606     glBindBuffer(GL_ARRAY_BUFFER, data->buffer[5]);
     637    glVertexAttribPointer(attr[1], 3, GL_FLOAT, GL_FALSE, 0, 0);
     638    glEnableVertexAttribArray(attr[2]);
     639
     640    glBindBuffer(GL_ARRAY_BUFFER, *buffer++);
    607641    glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords,
    608642                 GL_DYNAMIC_DRAW);
    609     glVertexAttribPointer(data->attr[5], 2, GL_FLOAT, GL_FALSE, 0, 0);
    610     glEnableVertexAttribArray(data->attr[5]);
     643    glVertexAttribPointer(attr[2], 2, GL_FLOAT, GL_FALSE, 0, 0);
     644    glEnableVertexAttribArray(attr[2]);
    611645
    612646    glDrawArrays(GL_TRIANGLES, 0, 6);
    613647    glBindVertexArray(0);
    614648
    615     glDisableVertexAttribArray(data->attr[3]);
    616     glDisableVertexAttribArray(data->attr[4]);
    617     glDisableVertexAttribArray(data->attr[5]);
     649    glDisableVertexAttribArray(*attr++);
     650    glDisableVertexAttribArray(*attr++);
     651    glDisableVertexAttribArray(*attr++);
    618652    glUseProgram(0);
    619653
     
    621655    ResetState();
    622656#endif
     657
     658    /* Check that we didn't overflow our list */
     659#if !defined __CELLOS_LV2__ && !defined ANDROID_NDK
     660    if (array > data->array + NUM_ARRAYS)
     661        Log::Error("too many arrays used\n");
     662#endif
     663    if (buffer > data->buffer + NUM_BUFFERS)
     664        Log::Error("too many buffers used\n");
     665    if (shader > data->shader + NUM_SHADERS)
     666        Log::Error("too many shaders used\n");
     667    if (attr > data->attr + NUM_ATTRS)
     668        Log::Error("too many attributes used\n");
    623669}
    624670
     
    626672{
    627673    /* Reset GL states to something reasonably safe */
    628 #if defined HAVE_GLBEGIN || defined USE_GLEW
     674#if defined HAVE_GLBEGIN || defined USE_GLEW || defined __CELLOS_LV2__
    629675    glMatrixMode(GL_PROJECTION);
    630676    glLoadIdentity();
     
    635681    glEnable(GL_TEXTURE_2D);
    636682    glBindTexture(GL_TEXTURE_2D, 0);
    637 #if defined HAVE_GLBEGIN || defined USE_GLEW
     683#if defined HAVE_GLBEGIN || defined USE_GLEW || defined __CELLOS_LV2__
    638684    glClientActiveTexture(GL_TEXTURE0);
    639685#endif
Note: See TracChangeset for help on using the changeset viewer.