Changeset 903


Ignore:
Timestamp:
Sep 4, 2011, 10:11:43 PM (8 years ago)
Author:
sam
Message:

debug: add point sprite examples.

Location:
trunk
Files:
2 edited

Legend:

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

    r863 r903  
    7070    uint8_t image[1][TEX_SIZE * TEX_SIZE * 4];
    7171
     72    /* Cache a list of points for a quad at the proper coordinates. */
    7273    GLfloat const *GetVertexArray()
    7374    {
     
    7778        return vertices;
    7879    }
    79     GLfloat vertices[18]; /* To cache quad coordinates */
     80    GLfloat vertices[18];
     81
     82    /* Cache a list of points for a sine wave, ensuring constant spacing
     83     * between consecutive points. */
     84    static int const SINE_SIZE = 256;
     85    static float const SINE_SPACE = 0.01f;
     86    GLfloat const *GetSineArray()
     87    {
     88        float x = 0.0f;
     89        for (npoints = 0; npoints < SINE_SIZE && x <= 1.0f; npoints++)
     90        {
     91            float y = 0.5f + 0.5f * lol_sin(x * 2.0f * M_PI + time * 2e-3f);
     92            points[npoints * 2] = aa.x + (bb.x - aa.x) * x;
     93            points[npoints * 2 + 1] = aa.y + (bb.y - aa.y) * y;
     94
     95            float dy = M_PI * lol_cos(x * 2.0f * M_PI + time * 2e-3f);
     96            float dx = SINE_SPACE / sqrtf(1.0f + dy * dy);
     97            x += dx;
     98        }
     99        return points;
     100
     101    }
     102    GLfloat points[2 * SINE_SIZE];
     103    int npoints;
    80104};
    81105
     
    215239    GLuint *uni = data->uni;
    216240
    217     ResetState();
    218 
    219     /*
    220      * Test #1: simple glBegin code
     241    /* These may be shared across calls */
     242    GLfloat const *sine;
     243
     244    ResetState();
     245
     246    /*
     247     * Test #1: simple glBegin + GL_TRIANGLES code
    221248     *
    222249     * Renders an orange square.
     
    439466
    440467    /*
    441      * Test #7: simple vertex buffer
     468     * Test #7: glBegin + GL_POINTS
     469     *
     470     * Renders a green sine wave made of 1-pixel points.
     471     */
     472#if defined HAVE_GLBEGIN || defined USE_GLEW
     473    glColor3f(0.0f, 1.0f, 0.0f);
     474    glPointSize(1.0f);
     475
     476    sine = data->GetSineArray();
     477    glBegin(GL_POINTS);
     478        for (int i = 0; i < data->npoints; i++)
     479            glVertex3f(sine[i * 2], sine[i * 2 + 1], 0.0f);
     480    glEnd();
     481#endif
     482
     483    Advance();
     484    ResetState();
     485
     486    /*
     487     * Test #8: simple vertex buffer
    442488     *
    443489     * Renders an orange square.
     
    457503
    458504    /*
    459      * Test #8: vertex buffer + per-vertex coloring
     505     * Test #9: simple point buffer
     506     *
     507     * Renders a green sine wave made of 1-pixel points.
     508     */
     509#if !defined ANDROID_NDK && !defined __APPLE__
     510    glColor3f(0.0f, 1.0f, 0.0f);
     511    glPointSize(1.0f);
     512    glEnableClientState(GL_VERTEX_ARRAY);
     513
     514    glVertexPointer(2, GL_FLOAT, 0, data->GetSineArray());
     515    glDrawArrays(GL_POINTS, 0, data->npoints);
     516
     517    glDisableClientState(GL_VERTEX_ARRAY);
     518#endif
     519
     520    Advance();
     521    ResetState();
     522
     523    /*
     524     * Test #10: vertex buffer + per-vertex coloring
    460525     *
    461526     * Renders a multicoloured square with varying colors.
     
    477542
    478543    /*
    479      * Test #9: vertex buffer + per-vertex coloring + texture
     544     * Test #11: vertex buffer + per-vertex coloring + texture
    480545     *
    481546     * Renders a multicoloured square with varying colors multiplied with an
     
    505570
    506571    /*
    507      * Test #10: vertex buffer + hardcoded color in 1.10 fragment shader
     572     * Test #12: vertex buffer + hardcoded color in 1.10 fragment shader
    508573     * (GLSL) or in Cg fragment shader (PS3)
    509574     *
     
    551616
    552617    /*
    553      * Test #11: vertex buffer + uniform color in 1.10 fragment shader
     618     * Test #13: vertex buffer + uniform color in 1.10 fragment shader
    554619     * (GLSL) or in Cg fragment shader (PS3)
    555620     *
     
    604669
    605670    /*
    606      * Test #12: vertex buffer + color in 1.10 fragment shader (GLSL) or
     671     * Test #14: vertex buffer + color in 1.10 fragment shader (GLSL) or
    607672     * in Cg fragment shader (PS3)
    608673     *
     
    657722
    658723    /*
    659      * Test #13: vertex buffer + uniform matrix for color transform in 1.10
     724     * Test #15: vertex buffer + uniform matrix for color transform in 1.10
    660725     * or Cg fragment shader
    661726     *
     
    722787
    723788    /*
    724      * Test #14: vertex buffer + texture & color in 1.10 fragment shader
    725      *
    726      * Renders a multicoloured square with varying colors xored with an
    727      * animated distorted checkerboard.
     789     * Test #16: simple point buffer
     790     *
     791     * Renders an antialiased green sine wave made of 1-pixel points.
    728792     */
    729793#if !defined ANDROID_NDK && !defined __APPLE__
     
    731795#if !defined __CELLOS_LV2__
    732796        shader[0] = Shader::Create(
    733             "#version 110\n"
     797            "#version 120\n"
    734798            "varying vec4 pass_Color;"
    735799            "void main()"
    736800            "{"
    737             "    gl_TexCoord[0] = gl_MultiTexCoord0;"
    738             "    pass_Color = gl_Color;"
     801            "    pass_Color = vec4(0.0, 1.0, 0.0, 1.0);"
    739802            "    gl_Position = gl_Vertex;"
    740803            "}",
    741804
    742             "#version 110\n"
     805            "#version 120\n"
    743806            "varying vec4 pass_Color;"
    744             "uniform sampler2D tex;"
    745             "void main()"
    746             "{"
    747             "    vec4 tmp = texture2D(tex, gl_TexCoord[0].xy * 0.25);"
    748             "    gl_FragColor = vec4(abs(tmp.xyz - pass_Color.xyz), 1.0);"
     807            "void main()"
     808            "{"
     809            "    vec2 d = gl_PointCoord.st - vec2(0.5, 0.5);"
     810            "    float k = max(0.0, 2.0 * (0.5 - sqrt(dot(d, d))));"
     811            "    gl_FragColor = vec4(pass_Color.xyz, k);"
    749812            "}");
    750813#else
     
    775838    shader++;
    776839
     840    glEnable(GL_POINT_SPRITE);
     841    glEnable(GL_BLEND);
     842    glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
     843    glPointSize(3.0f);
     844    glEnableClientState(GL_VERTEX_ARRAY);
     845
     846    glVertexPointer(2, GL_FLOAT, 0, data->GetSineArray());
     847    glDrawArrays(GL_POINTS, 0, data->npoints);
     848
     849    glDisableClientState(GL_VERTEX_ARRAY);
     850    glDisable(GL_POINT_SPRITE);
     851    glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);
     852#endif
     853
     854    Advance();
     855    ResetState();
     856
     857    /*
     858     * Test #17: vertex buffer + texture & color in 1.10 fragment shader
     859     *
     860     * Renders a multicoloured square with varying colors xored with an
     861     * animated distorted checkerboard.
     862     */
     863#if !defined ANDROID_NDK && !defined __APPLE__
     864    if (!shader[0])
     865#if !defined __CELLOS_LV2__
     866        shader[0] = Shader::Create(
     867            "#version 110\n"
     868            "varying vec4 pass_Color;"
     869            "void main()"
     870            "{"
     871            "    gl_TexCoord[0] = gl_MultiTexCoord0;"
     872            "    pass_Color = gl_Color;"
     873            "    gl_Position = gl_Vertex;"
     874            "}",
     875
     876            "#version 110\n"
     877            "varying vec4 pass_Color;"
     878            "uniform sampler2D tex;"
     879            "void main()"
     880            "{"
     881            "    vec4 tmp = texture2D(tex, gl_TexCoord[0].xy * 0.25);"
     882            "    gl_FragColor = vec4(abs(tmp.xyz - pass_Color.xyz), 1.0);"
     883            "}");
     884#else
     885        shader[0] = Shader::Create(
     886            "void main(float4 in_Position : POSITION,"
     887            "          float2 in_TexCoord : TEXCOORD0,"
     888            "          float4 in_Color : COLOR,"
     889            "          out float4 out_Color : COLOR,"
     890            "          out float4 out_Position : POSITION,"
     891            "          out float2 out_TexCoord : TEXCOORD0)"
     892            "{"
     893            "    out_TexCoord = in_TexCoord;"
     894            "    out_Color = in_Color;"
     895            "    out_Position = in_Position;"
     896            "}",
     897
     898            "void main(float2 in_TexCoord : TEXCOORD0,"
     899            "          float4 in_Color : COLOR,"
     900            "          uniform sampler2D tex,"
     901            "          out float4 out_FragColor : COLOR)"
     902            "{"
     903            "    float4 tmp = tex2D(tex, in_TexCoord * 0.25);"
     904            "    out_FragColor = float4(abs(tmp.xyz - in_Color.xyz), 1);"
     905            "}");
     906#endif
     907
     908    shader[0]->Bind();
     909    shader++;
     910
    777911    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
    778912
     
    795929
    796930    /*
    797      * Test #15: vertex buffer + texture & color in 1.20 fragment shader
     931     * Test #18: vertex buffer + texture & color in 1.20 fragment shader
    798932     *
    799933     * Renders a multicoloured square with varying colors xored with an
     
    865999
    8661000    /*
    867      * Test #16: vertex buffer + texture & color in 1.30 fragment shader
     1001     * Test #19: vertex buffer + texture & color in 1.30 fragment shader
    8681002     *
    8691003     * Renders a multicoloured square with varying colors xored with an
     
    9671101    glClientActiveTexture(GL_TEXTURE0);
    9681102#endif
     1103    glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);
    9691104    glDisable(GL_TEXTURE_2D);
     1105
     1106    glDisable(GL_BLEND);
     1107    glDisable(GL_POINT_SPRITE);
    9701108
    9711109    glBindBuffer(GL_ARRAY_BUFFER, 0);
     
    9761114    cgGLDisableProfile(cgGLGetLatestProfile(CG_GL_FRAGMENT));
    9771115#endif
     1116
     1117    glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
    9781118}
    9791119
  • trunk/test/debug/quad.cpp

    r865 r903  
    4747    new SdlInput();
    4848#endif
    49     //new DebugFps(20, 20);
     49    new DebugFps(5, 5);
    5050    new DebugQuad();
    5151
Note: See TracChangeset for help on using the changeset viewer.