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

Last change on this file since 783 was 783, checked in by sam, 10 years ago

build: put debug stuff and shader stuff in subdirectories.

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