source: trunk/src/debug/quad.cpp @ 818

Last change on this file since 818 was 818, checked in by sam, 8 years ago

ps3: some compilation fixes to accomodate for recent debug additions.

  • Property svn:keywords set to Id
File size: 20.1 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cmath>
16#include <cstdio>
17
18#include "core.h"
19#include "lolgl.h"
20#include "loldebug.h"
21
22using namespace std;
23
24namespace lol
25{
26
27/*
28 * DebugQuad implementation class
29 */
30
31static int const NUM_ARRAYS = 2;
32static int const NUM_BUFFERS = 6;
33static int const NUM_ATTRS = 6;
34static int const NUM_SHADERS = 6;
35static int const NUM_TEXTURES = 1;
36
37static int const TEX_SIZE = 32;
38
39class DebugQuadData
40{
41    friend class DebugQuad;
42
43private:
44    vec2 orig, step, aa, bb;
45
46    int initialised;
47    float time;
48#if !defined __CELLOS_LV2__
49    GLuint array[NUM_ARRAYS];
50#endif
51    GLuint buffer[NUM_BUFFERS];
52    Shader *shader[NUM_SHADERS];
53    GLuint attr[NUM_ATTRS];
54    GLuint texture[NUM_TEXTURES];
55    uint8_t image[1][TEX_SIZE * TEX_SIZE * 4];
56};
57
58/*
59 * Public DebugQuad class
60 */
61
62DebugQuad::DebugQuad()
63  : data(new DebugQuadData())
64{
65    data->initialised = 0;
66    data->time = RandF(10000.0f);
67
68    drawgroup = DRAWGROUP_HUD;
69}
70
71void DebugQuad::TickGame(float deltams)
72{
73    Entity::TickGame(deltams);
74
75    data->time += deltams;
76}
77
78void DebugQuad::TickDraw(float deltams)
79{
80    Entity::TickDraw(deltams);
81
82    if (!data->initialised && !IsDestroying())
83    {
84#if !defined __CELLOS_LV2__
85        glGenVertexArrays(NUM_ARRAYS, data->array);
86#endif
87        glGenBuffers(NUM_BUFFERS, data->buffer);
88        glGenTextures(NUM_TEXTURES, data->texture);
89        for (int i = 0; i < NUM_SHADERS; i++)
90            data->shader[i] = NULL;
91
92        /* Checkerboard texture */
93        glEnable(GL_TEXTURE_2D);
94        glBindTexture(GL_TEXTURE_2D, data->texture[0]);
95        for (int j = 0; j < TEX_SIZE; j++)
96            for (int i = 0; i < TEX_SIZE; i++)
97            {
98                uint8_t wb = (((i / 2) ^ (j / 2)) & 1) * 0xff;
99                data->image[0][(j * TEX_SIZE + i) * 4 + 0] = wb;
100                data->image[0][(j * TEX_SIZE + i) * 4 + 1] = wb;
101                data->image[0][(j * TEX_SIZE + i) * 4 + 2] = wb;
102                data->image[0][(j * TEX_SIZE + i) * 4 + 3] = 0xff;
103            }
104        /* Use GL_RGBA instead of 4 for the internal format (Android) */
105        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0,
106                     GL_RGBA, GL_UNSIGNED_BYTE, data->image[0]);
107        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
108        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
109
110        data->initialised = 1;
111    }
112    else if (data->initialised && IsDestroying())
113    {
114#if !defined __CELLOS_LV2__
115        glDeleteVertexArrays(NUM_ARRAYS, data->array);
116#endif
117        glDeleteBuffers(NUM_BUFFERS, data->buffer);
118        glDeleteTextures(NUM_TEXTURES, data->texture);
119
120        for (int i = 0; i < NUM_SHADERS; i++)
121            if (data->shader[i])
122                Shader::Destroy(data->shader[i]);
123
124        data->initialised = 0;
125    }
126
127    /* Prepare our quad coordinates */
128    vec2i const layout(4, 3);
129    data->step = vec2(2.0f, -2.0f) / (3 * layout + vec2i(1));
130    data->orig = vec2(-1.0f, 1.0f) + data->step;
131    data->aa = data->orig;
132    data->bb = data->orig + 2.0f * data->step;
133
134    /* Generate a few random numbers */
135    float f1 = 0.5f + 0.5f * sinf(0.00034f * data->time);
136    float f2 = 0.5f + 0.5f * sinf(0.00053f * data->time + 1.0f);
137    float f3 = 0.5f + 0.5f * sinf(0.00072f * data->time + 4.0f);
138    float f4 = 0.5f + 0.5f * sinf(0.00091f * data->time + 8.0f);
139
140    GLfloat const colors[] = { f1, f2, f3, f4, f2, f1, f3, f1, f4,
141                               f3, f1, f4, f4, f3, f2, f1, f2, f3 };
142    GLfloat const texcoords[] = { f1, f3, f3, f2, f2, f4,
143                                  f2, f4, f4, f1, f1, f3 };
144
145    ResetState();
146
147#if defined HAVE_GLBEGIN || defined USE_GLEW
148    /*
149     * Test #1: simple glBegin code
150     *
151     * Renders an orange square.
152     */
153    glColor3f(0.8f, 0.5f, 0.2f);
154    glBegin(GL_TRIANGLES);
155        glVertex3f(data->aa.x, data->bb.y, 0.0f);
156        glVertex3f(data->bb.x, data->bb.y, 0.0f);
157        glVertex3f(data->bb.x, data->aa.y, 0.0f);
158
159        glVertex3f(data->bb.x, data->aa.y, 0.0f);
160        glVertex3f(data->aa.x, data->aa.y, 0.0f);
161        glVertex3f(data->aa.x, data->bb.y, 0.0f);
162    glEnd();
163
164    Advance();
165    ResetState();
166
167    /*
168     * Test #2: glBegin + per-vertex coloring
169     *
170     * Renders a multicolored square with varying colors.
171     */
172
173    glBegin(GL_TRIANGLES);
174        glColor3f(f1, f2, f3);
175        glVertex3f(data->aa.x, data->bb.y, 0.0f);
176        glColor3f(f4, f2, f1);
177        glVertex3f(data->bb.x, data->bb.y, 0.0f);
178        glColor3f(f3, f1, f4);
179        glVertex3f(data->bb.x, data->aa.y, 0.0f);
180
181        glVertex3f(data->bb.x, data->aa.y, 0.0f);
182        glColor3f(f4, f3, f2);
183        glVertex3f(data->aa.x, data->aa.y, 0.0f);
184        glColor3f(f1, f2, f3);
185        glVertex3f(data->aa.x, data->bb.y, 0.0f);
186    glEnd();
187
188    Advance();
189    ResetState();
190
191    /*
192     * Test #3: glBegin + texture
193     *
194     * Renders an animated black-and-white distorted checkerboard.
195     */
196    glEnable(GL_TEXTURE_2D);
197    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
198    glColor3f(1.0f, 1.0f, 1.0f);
199    glBegin(GL_TRIANGLES);
200        glTexCoord2f(f1, f3);
201        glVertex3f(data->aa.x, data->bb.y, 0.0f);
202        glTexCoord2f(f3, f2);
203        glVertex3f(data->bb.x, data->bb.y, 0.0f);
204        glTexCoord2f(f2, f4);
205        glVertex3f(data->bb.x, data->aa.y, 0.0f);
206
207        glTexCoord2f(f2, f4);
208        glVertex3f(data->bb.x, data->aa.y, 0.0f);
209        glTexCoord2f(f4, f1);
210        glVertex3f(data->aa.x, data->aa.y, 0.0f);
211        glTexCoord2f(f1, f3);
212        glVertex3f(data->aa.x, data->bb.y, 0.0f);
213    glEnd();
214    glDisable(GL_TEXTURE_2D);
215
216    Advance();
217    ResetState();
218
219    /*
220     * Test #4: glBegin + color in fragment shader
221     *
222     * Renders a static, coloured and tiled pattern.
223     */
224#if !defined __CELLOS_LV2__
225    if (!data->shader[0])
226        data->shader[0] = Shader::Create(
227            "#version 110\n"
228            "void main()"
229            "{"
230            "    gl_Position = gl_Vertex;"
231            "}",
232
233            "#version 110\n"
234            "void main()"
235            "{"
236            "    float dx = mod(gl_FragCoord.x * gl_FragCoord.y, 2.0);"
237            "    float dy = mod(gl_FragCoord.x * 0.125, 1.0);"
238            "    float dz = mod(gl_FragCoord.y * 0.125, 1.0);"
239            "    gl_FragColor = vec4(dx, dy, dz, 1.0);"
240            "}");
241    data->shader[0]->Bind();
242    glColor3f(0.0f, 1.0f, 1.0f);
243    glBegin(GL_TRIANGLES);
244        glVertex3f(data->aa.x, data->bb.y, 0.0f);
245        glVertex3f(data->bb.x, data->bb.y, 0.0f);
246        glVertex3f(data->bb.x, data->aa.y, 0.0f);
247
248        glVertex3f(data->bb.x, data->aa.y, 0.0f);
249        glVertex3f(data->aa.x, data->aa.y, 0.0f);
250        glVertex3f(data->aa.x, data->bb.y, 0.0f);
251    glEnd();
252    glUseProgram(0);
253
254    Advance();
255    ResetState();
256#endif
257
258    /*
259     * Test #5: glBegin + pass vertex coord from vertex shader to fragment
260     * shader for use as color information.
261     *
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(
267            "#version 110\n"
268            "varying vec4 pass_Color;"
269            "void main()"
270            "{"
271            "    float r = gl_MultiTexCoord0.x;"
272            "    float g = gl_MultiTexCoord0.y;"
273            "    float b = gl_MultiTexCoord0.z;"
274            "    pass_Color = vec4(r, g, b, 1.0);"
275            "    gl_Position = gl_Vertex;"
276            "}",
277
278            "#version 110\n"
279            "varying vec4 pass_Color;"
280            "void main()"
281            "{"
282            "    gl_FragColor = pass_Color;"
283            "}");
284    data->shader[1]->Bind();
285    glColor3f(0.0f, 1.0f, 1.0f);
286    glBegin(GL_TRIANGLES);
287        glTexCoord3f(f1, f2, f3);
288        glVertex3f(data->aa.x, data->bb.y, 0.0f);
289        glTexCoord3f(f4, f2, f1);
290        glVertex3f(data->bb.x, data->bb.y, 0.0f);
291        glTexCoord3f(f3, f1, f4);
292        glVertex3f(data->bb.x, data->aa.y, 0.0f);
293
294        glVertex3f(data->bb.x, data->aa.y, 0.0f);
295        glTexCoord3f(f4, f3, f2);
296        glVertex3f(data->aa.x, data->aa.y, 0.0f);
297        glTexCoord3f(f1, f2, f3);
298        glVertex3f(data->aa.x, data->bb.y, 0.0f);
299    glEnd();
300    glUseProgram(0);
301
302    Advance();
303    ResetState();
304#endif
305
306    /*
307     * Test #6: glBegin + apply texture in fragment shader
308     *
309     * Renders an animated black-and-white distorted checkerboard with a
310     * zoom ratio twice the one in test #3.
311     *
312     * Note: there is no need to glEnable(GL_TEXTURE_2D) when the
313     * texture lookup is done in a shader.
314     */
315#if !defined __CELLOS_LV2__
316    if (!data->shader[2])
317        data->shader[2] = Shader::Create(
318            "#version 110\n"
319            "void main()"
320            "{"
321            "    gl_TexCoord[0] = gl_MultiTexCoord0;"
322            "    gl_Position = gl_Vertex;"
323            "}",
324
325            "#version 110\n"
326            "uniform sampler2D tex;"
327            "void main()"
328            "{"
329            "    gl_FragColor = texture2D(tex, gl_TexCoord[0].xy * 0.25);"
330            "}");
331    data->shader[2]->Bind();
332    glColor3f(0.0f, 1.0f, 1.0f);
333    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
334    glBegin(GL_TRIANGLES);
335        glTexCoord2f(f1, f3);
336        glVertex3f(data->aa.x, data->bb.y, 0.0f);
337        glTexCoord2f(f3, f2);
338        glVertex3f(data->bb.x, data->bb.y, 0.0f);
339        glTexCoord2f(f2, f4);
340        glVertex3f(data->bb.x, data->aa.y, 0.0f);
341
342        glTexCoord2f(f2, f4);
343        glVertex3f(data->bb.x, data->aa.y, 0.0f);
344        glTexCoord2f(f4, f1);
345        glVertex3f(data->aa.x, data->aa.y, 0.0f);
346        glTexCoord2f(f1, f3);
347        glVertex3f(data->aa.x, data->bb.y, 0.0f);
348    glEnd();
349    glUseProgram(0);
350
351    Advance();
352    ResetState();
353#endif
354#endif
355
356    /*
357     * Test #7: vertex buffer + per-vertex coloring
358     *
359     * Renders a multicolored square with varying colors.
360     */
361    GLfloat const vertices1[] = { data->aa.x, data->bb.y, 0.0f,
362                                  data->bb.x, data->bb.y, 0.0f,
363                                  data->bb.x, data->aa.y, 0.0f,
364                                  data->bb.x, data->aa.y, 0.0f,
365                                  data->aa.x, data->aa.y, 0.0f,
366                                  data->aa.x, data->bb.y, 0.0f };
367
368    glEnableClientState(GL_COLOR_ARRAY);
369    glEnableClientState(GL_VERTEX_ARRAY);
370
371    glColorPointer(3, GL_FLOAT, 0, colors);
372    glVertexPointer(3, GL_FLOAT, 0, vertices1);
373    glDrawArrays(GL_TRIANGLES, 0, 6);
374
375    glDisableClientState(GL_VERTEX_ARRAY);
376    glDisableClientState(GL_COLOR_ARRAY);
377
378    Advance();
379    ResetState();
380
381    /*
382     * Test #8: vertex buffer + per-vertex coloring + texture
383     *
384     * Renders a multicolored square with varying colors multiplied with an
385     * animated distorted checkerboard.
386     */
387    GLfloat const vertices2[] = { data->aa.x, data->bb.y, 0.0f,
388                                  data->bb.x, data->bb.y, 0.0f,
389                                  data->bb.x, data->aa.y, 0.0f,
390                                  data->bb.x, data->aa.y, 0.0f,
391                                  data->aa.x, data->aa.y, 0.0f,
392                                  data->aa.x, data->bb.y, 0.0f };
393
394    glEnable(GL_TEXTURE_2D);
395    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
396    glEnableClientState(GL_COLOR_ARRAY);
397    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
398    glEnableClientState(GL_VERTEX_ARRAY);
399
400    glColorPointer(3, GL_FLOAT, 0, colors);
401    glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
402    glVertexPointer(3, GL_FLOAT, 0, vertices2);
403    glDrawArrays(GL_TRIANGLES, 0, 6);
404
405    glDisableClientState(GL_VERTEX_ARRAY);
406    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
407    glDisableClientState(GL_COLOR_ARRAY);
408    glDisable(GL_TEXTURE_2D);
409
410    Advance();
411    ResetState();
412
413    /*
414     * Test #9: vertex buffer + texture & color in 1.10 fragment shader
415     *
416     * Renders a multicolored square with varying colors xored with an
417     * animated distorted checkerboard.
418     */
419#if !defined __CELLOS_LV2__
420    if (!data->shader[3])
421        data->shader[3] = Shader::Create(
422            "#version 110\n"
423            "varying vec4 pass_Color;"
424            "void main()"
425            "{"
426            "    gl_TexCoord[0] = gl_MultiTexCoord0;"
427            "    pass_Color = gl_Color;"
428            "    gl_Position = gl_Vertex;"
429            "}",
430
431            "#version 110\n"
432            "varying vec4 pass_Color;"
433            "uniform sampler2D tex;"
434            "void main()"
435            "{"
436            "    vec4 tmp = texture2D(tex, gl_TexCoord[0].xy * 0.25);"
437            "    gl_FragColor = vec4(abs(tmp.xyz - pass_Color.xyz), 1.0);"
438            "}");
439
440    data->shader[3]->Bind();
441    GLfloat const vertices3[] = { data->aa.x, data->bb.y, 0.0f,
442                                  data->bb.x, data->bb.y, 0.0f,
443                                  data->bb.x, data->aa.y, 0.0f,
444                                  data->bb.x, data->aa.y, 0.0f,
445                                  data->aa.x, data->aa.y, 0.0f,
446                                  data->aa.x, data->bb.y, 0.0f };
447
448    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
449
450    glEnableClientState(GL_VERTEX_ARRAY);
451    glEnableClientState(GL_COLOR_ARRAY);
452    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
453
454    glVertexPointer(3, GL_FLOAT, 0, vertices3);
455    glColorPointer(3, GL_FLOAT, 0, colors);
456    glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
457    glDrawArrays(GL_TRIANGLES, 0, 6);
458
459    glDisableClientState(GL_VERTEX_ARRAY);
460    glDisableClientState(GL_COLOR_ARRAY);
461    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
462    glUseProgram(0);
463
464    Advance();
465    ResetState();
466#endif
467
468    /*
469     * Test #10: vertex buffer + texture & color in 1.20 fragment shader
470     *
471     * Renders a multicolored square with varying colors xored with an
472     * animated distorted checkerboard.
473     */
474#if !defined __CELLOS_LV2__
475    if (!data->shader[4])
476    {
477        data->shader[4] = Shader::Create(
478            "#version 120\n"
479            "attribute vec3 in_Vertex;"
480            "attribute vec3 in_Color;"
481            "attribute vec2 in_MultiTexCoord0;"
482            "varying vec4 pass_Color;"
483            "void main()"
484            "{"
485            "    gl_TexCoord[0] = vec4(in_MultiTexCoord0, 0.0, 0.0);"
486            "    pass_Color = vec4(in_Color, 1.0);"
487            "    gl_Position = vec4(in_Vertex, 1.0);"
488            "}",
489
490            "#version 120\n"
491            "varying vec4 pass_Color;"
492            "uniform sampler2D tex;"
493            "void main()"
494            "{"
495            "    vec4 tmp = texture2D(tex, gl_TexCoord[0].xy * 0.25);"
496            "    gl_FragColor = vec4(abs(tmp.xyz - pass_Color.xyz), 1.0);"
497            "}");
498        data->attr[0] = data->shader[4]->GetAttribLocation("in_Vertex");
499        data->attr[1] = data->shader[4]->GetAttribLocation("in_Color");
500        data->attr[2] = data->shader[4]->GetAttribLocation("in_MultiTexCoord0");
501    }
502    data->shader[4]->Bind();
503    GLfloat const vertices4[] = { data->aa.x, data->bb.y, 0.0f,
504                                  data->bb.x, data->bb.y, 0.0f,
505                                  data->bb.x, data->aa.y, 0.0f,
506                                  data->bb.x, data->aa.y, 0.0f,
507                                  data->aa.x, data->aa.y, 0.0f,
508                                  data->aa.x, data->bb.y, 0.0f };
509
510    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
511
512    glBindVertexArray(data->array[0]);
513
514    glBindBuffer(GL_ARRAY_BUFFER, data->buffer[0]);
515    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices4), vertices4,
516                 GL_DYNAMIC_DRAW);
517    glVertexAttribPointer(data->attr[0], 3, GL_FLOAT, GL_FALSE, 0, 0);
518    glEnableVertexAttribArray(data->attr[0]);
519
520    glBindBuffer(GL_ARRAY_BUFFER, data->buffer[1]);
521    glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors,
522                 GL_DYNAMIC_DRAW);
523    glVertexAttribPointer(data->attr[1], 3, GL_FLOAT, GL_FALSE, 0, 0);
524    glEnableVertexAttribArray(data->attr[1]);
525
526    glBindBuffer(GL_ARRAY_BUFFER, data->buffer[2]);
527    glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords,
528                 GL_DYNAMIC_DRAW);
529    glVertexAttribPointer(data->attr[2], 2, GL_FLOAT, GL_FALSE, 0, 0);
530    glEnableVertexAttribArray(data->attr[2]);
531
532    glDrawArrays(GL_TRIANGLES, 0, 6);
533    glBindVertexArray(0);
534
535    glDisableVertexAttribArray(data->attr[0]);
536    glDisableVertexAttribArray(data->attr[1]);
537    glDisableVertexAttribArray(data->attr[2]);
538    glUseProgram(0);
539
540    Advance();
541    ResetState();
542#endif
543
544    /*
545     * Test #11: vertex buffer + texture & color in 1.30 fragment shader
546     *
547     * Renders a multicolored square with varying colors xored with an
548     * animated distorted checkerboard.
549     */
550#if !defined __CELLOS_LV2__
551    if (!data->shader[5])
552    {
553        data->shader[5] = Shader::Create(
554            "#version 130\n"
555            "in vec3 in_Vertex;"
556            "in vec3 in_Color;"
557            "in vec2 in_MultiTexCoord0;"
558            "out vec4 pass_Color;"
559            "void main()"
560            "{"
561            "    gl_TexCoord[0] = vec4(in_MultiTexCoord0, 0.0, 0.0);"
562            "    pass_Color = vec4(in_Color, 1.0);"
563            "    gl_Position = vec4(in_Vertex, 1.0);"
564            "}",
565
566            "#version 130\n"
567            "in vec4 pass_Color;"
568            "uniform sampler2D tex;"
569            "void main()"
570            "{"
571            "    vec4 tmp = texture2D(tex, gl_TexCoord[0].xy * 0.25);"
572            "    gl_FragColor = vec4(abs(tmp.xyz - pass_Color.xyz), 1.0);"
573            "}");
574        data->attr[3] = data->shader[4]->GetAttribLocation("in_Vertex");
575        data->attr[4] = data->shader[4]->GetAttribLocation("in_Color");
576        data->attr[5] = data->shader[4]->GetAttribLocation("in_MultiTexCoord0");
577    }
578    data->shader[5]->Bind();
579    GLfloat const vertices5[] = { data->aa.x, data->bb.y, 0.0f,
580                                  data->bb.x, data->bb.y, 0.0f,
581                                  data->bb.x, data->aa.y, 0.0f,
582                                  data->bb.x, data->aa.y, 0.0f,
583                                  data->aa.x, data->aa.y, 0.0f,
584                                  data->aa.x, data->bb.y, 0.0f };
585
586    glBindTexture(GL_TEXTURE_2D, data->texture[0]);
587
588    glBindVertexArray(data->array[1]);
589
590    glBindBuffer(GL_ARRAY_BUFFER, data->buffer[3]);
591    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices5), vertices5,
592                 GL_DYNAMIC_DRAW);
593    glVertexAttribPointer(data->attr[3], 3, GL_FLOAT, GL_FALSE, 0, 0);
594    glEnableVertexAttribArray(data->attr[3]);
595
596    glBindBuffer(GL_ARRAY_BUFFER, data->buffer[4]);
597    glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors,
598                 GL_DYNAMIC_DRAW);
599    glVertexAttribPointer(data->attr[4], 3, GL_FLOAT, GL_FALSE, 0, 0);
600    glEnableVertexAttribArray(data->attr[4]);
601
602    glBindBuffer(GL_ARRAY_BUFFER, data->buffer[5]);
603    glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords,
604                 GL_DYNAMIC_DRAW);
605    glVertexAttribPointer(data->attr[5], 2, GL_FLOAT, GL_FALSE, 0, 0);
606    glEnableVertexAttribArray(data->attr[5]);
607
608    glDrawArrays(GL_TRIANGLES, 0, 6);
609    glBindVertexArray(0);
610
611    glDisableVertexAttribArray(data->attr[3]);
612    glDisableVertexAttribArray(data->attr[4]);
613    glDisableVertexAttribArray(data->attr[5]);
614    glUseProgram(0);
615
616    Advance();
617    ResetState();
618#endif
619}
620
621void DebugQuad::ResetState()
622{
623    /* Reset GL states to something reasonably safe */
624    glMatrixMode(GL_PROJECTION);
625    glLoadIdentity();
626    glMatrixMode(GL_MODELVIEW);
627    glLoadIdentity();
628
629    glEnable(GL_TEXTURE_2D);
630    glBindTexture(GL_TEXTURE_2D, 0);
631    glClientActiveTexture(GL_TEXTURE0);
632    glDisable(GL_TEXTURE_2D);
633
634    glBindBuffer(GL_ARRAY_BUFFER, 0);
635#if !defined __CELLOS_LV2__
636    glUseProgram(0);
637#endif
638}
639
640void DebugQuad::Advance()
641{
642    data->aa.x += 3.0f * data->step.x;
643    data->bb.x += 3.0f * data->step.x;
644    if (data->bb.x > 1.0f)
645    {
646        data->aa.x = data->orig.x;
647        data->bb.x = data->orig.x + 2.0f * data->step.x;
648        data->aa.y += 3.0f * data->step.y;
649        data->bb.y += 3.0f * data->step.y;
650    }
651}
652
653DebugQuad::~DebugQuad()
654{
655    delete data;
656}
657
658} /* namespace lol */
659
Note: See TracBrowser for help on using the repository browser.