~thumper/nux/next-changes

« back to all changes in this revision

Viewing changes to NuxGraphics/RenderingPipeGLSL.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 21:15:42 UTC
  • Revision ID: neil.patel@canonical.com-20100901211542-cw2ce3ak28unouwb
Add NuxGraphics with licensing

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it 
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but 
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of 
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public 
 
12
 * License for more details.
 
13
 * 
 
14
 * You should have received a copy of both the GNU Lesser General Public 
 
15
 * License version 3 along with this program.  If not, see 
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "NuxCore/NKernel.h"
 
24
 
 
25
#include "NuxImage/Tga.h"
 
26
#include "NuxImage/ImageSurface.h"
 
27
#include "NuxMesh/NTextureArchiveManager.h"
 
28
 
 
29
#include "GLDeviceFactory.h"
 
30
#include "GLDeviceObjects.h"
 
31
#include "GLResourceManager.h"
 
32
 
 
33
#include "GLTextureResourceManager.h"
 
34
#include "GLVertexResourceManager.h"
 
35
#include "RenderingPipe.h"
 
36
#include "OpenGLEngine.h"
 
37
 
 
38
 
 
39
NAMESPACE_BEGIN_OGL
 
40
 
 
41
// For some strange reason, make sure that the attribute holding the vertex position has a name that comes first in alphabetic order before all
 
42
// other attributes. Otherwise you get a bug on NVidia! Why is that???
 
43
// [Update]: it seems that the vertex attributes have to be declared in alphabetic order in the shader. It does not matter if the vertex
 
44
// attribute is declared first in the alphabetic order.
 
45
 
 
46
// For some other strange reason, on Intel GMA, the order in which attributes are used in the vertex shaders, is the order used to associated them with a 
 
47
// and attribute location. One has to make sure that the vertex attribute get index 0. So use the vertex attribute first. All of this does not make any sense.
 
48
// Need more info from driver developers.
 
49
 
 
50
#define USE_ARB 1
 
51
bool USE_ARB_SHADERS = true;
 
52
 
 
53
void GraphicsContext::InitSlColorShader()
 
54
{
 
55
    TRefGL<IOpenGLVertexShader> VS = m_GLWindow.m_DeviceFactory->CreateVertexShader();
 
56
    TRefGL<IOpenGLPixelShader> PS = m_GLWindow.m_DeviceFactory->CreatePixelShader();
 
57
    NString VSString;
 
58
    NString PSString;
 
59
 
 
60
    VSString =  TEXT("#version 110   \n\
 
61
                     uniform mat4 ViewProjectionMatrix;                 \n\
 
62
                     attribute vec4 AVertex;                            \n\
 
63
                     attribute vec4 VertexColor;                        \n\
 
64
                     void main()                                        \n\
 
65
                     {                                                  \n\
 
66
                         gl_Position = ViewProjectionMatrix * AVertex;  \n\
 
67
                         gl_FrontColor = VertexColor;                   \n\
 
68
                     }");
 
69
 
 
70
    VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
 
71
 
 
72
    PSString =  TEXT("#version 110                  \n\
 
73
                     void main()                    \n\
 
74
                     {                              \n\
 
75
                         gl_FragColor = gl_Color;   \n\
 
76
                     }");
 
77
    PS->SetShaderCode(TCHAR_TO_ANSI(*PSString));
 
78
 
 
79
    m_SlColor = m_GLWindow.m_DeviceFactory->CreateShaderProgram();
 
80
    m_SlColor->ClearShaderObjects();
 
81
    m_SlColor->AddShaderObject(VS);
 
82
    m_SlColor->AddShaderObject(PS);
 
83
    m_SlColor->Link();
 
84
}
 
85
 
 
86
void GraphicsContext::InitSlTextureShader()
 
87
{
 
88
    TRefGL<IOpenGLVertexShader> VS = m_GLWindow.m_DeviceFactory->CreateVertexShader();
 
89
    TRefGL<IOpenGLPixelShader> PS = m_GLWindow.m_DeviceFactory->CreatePixelShader();
 
90
    NString VSString;
 
91
    NString PSString;
 
92
 
 
93
    VSString =  TEXT("#version 110   \n\
 
94
                     attribute vec4 AVertex;                                 \n\
 
95
                     attribute vec4 MyTextureCoord0;                         \n\
 
96
                     attribute vec4 VertexColor;                             \n\
 
97
                     uniform mat4 ViewProjectionMatrix;                      \n\
 
98
                     varying vec4 varyTexCoord0;                             \n\
 
99
                     varying vec4 varyVertexColor;                           \n\
 
100
                     void main()                                             \n\
 
101
                     {                                                       \n\
 
102
                     gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
 
103
                     varyTexCoord0 = MyTextureCoord0;                        \n\
 
104
                     varyVertexColor = VertexColor;                          \n\
 
105
                     }");
 
106
 
 
107
    PSString =  TEXT("#version 110                                               \n\
 
108
                     #extension GL_ARB_texture_rectangle : enable                \n\
 
109
                     varying vec4 varyTexCoord0;                                 \n\
 
110
                     varying vec4 varyVertexColor;                               \n\
 
111
                     #ifdef SAMPLERTEX2D                                         \n\
 
112
                     uniform sampler2D TextureObject0;                           \n\
 
113
                     vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
 
114
                     {                                                           \n\
 
115
                     return texture2D(TexObject, TexCoord.st);                   \n\
 
116
                     }                                                           \n\
 
117
                     #elif defined SAMPLERTEX2DRECT                              \n\
 
118
                     uniform sampler2DRect TextureObject0;                       \n\
 
119
                     vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)  \n\
 
120
                     {                                                           \n\
 
121
                     return texture2DRect(TexObject, TexCoord.st);               \n\
 
122
                     }                                                           \n\
 
123
                     #endif                                                      \n\
 
124
                     void main()                                                 \n\
 
125
                     {                                                           \n\
 
126
                     vec4 v = SampleTexture(TextureObject0, varyTexCoord0);      \n\
 
127
                     gl_FragColor = v*varyVertexColor;                           \n\
 
128
                     }");
 
129
 
 
130
    // Textured 2D Primitive Shader
 
131
    m_SlTextureModColor = m_GLWindow.m_DeviceFactory->CreateShaderProgram();
 
132
    VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
 
133
    PS->SetShaderCode(TCHAR_TO_ANSI(*PSString), TEXT("#define SAMPLERTEX2D"));
 
134
 
 
135
    m_SlTextureModColor->ClearShaderObjects();
 
136
    m_SlTextureModColor->AddShaderObject(VS);
 
137
    m_SlTextureModColor->AddShaderObject(PS);
 
138
    CHECKGL( glBindAttribLocation(m_SlTextureModColor->GetOpenGLID(), 0, "AVertex") );
 
139
    m_SlTextureModColor->Link();
 
140
}
 
141
 
 
142
void GraphicsContext::InitSlColorModTexMaskAlpha()
 
143
{
 
144
    TRefGL<IOpenGLVertexShader> VS = m_GLWindow.m_DeviceFactory->CreateVertexShader();
 
145
    TRefGL<IOpenGLPixelShader> PS = m_GLWindow.m_DeviceFactory->CreatePixelShader();
 
146
    NString VSString;
 
147
    NString PSString;
 
148
 
 
149
    VSString =  TEXT("#version 110   \n\
 
150
                     attribute vec4 AVertex;                                 \n\
 
151
                     attribute vec4 MyTextureCoord0;                         \n\
 
152
                     attribute vec4 VertexColor;                             \n\
 
153
                     uniform mat4 ViewProjectionMatrix;                      \n\
 
154
                     varying vec4 varyTexCoord0;                             \n\
 
155
                     varying vec4 varyVertexColor;                           \n\
 
156
                     void main()                                             \n\
 
157
                     {                                                       \n\
 
158
                     gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
 
159
                     varyTexCoord0 = MyTextureCoord0;                        \n\
 
160
                     varyVertexColor = VertexColor;                          \n\
 
161
                     }");
 
162
 
 
163
    PSString =  TEXT("#version 110                                                      \n\
 
164
                     #extension GL_ARB_texture_rectangle : enable                       \n\
 
165
                     varying vec4 varyTexCoord0;                                        \n\
 
166
                     varying vec4 varyVertexColor;                                      \n\
 
167
                     #ifdef SAMPLERTEX2D                                                \n\
 
168
                     uniform sampler2D TextureObject0;                                  \n\
 
169
                     vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)             \n\
 
170
                     {                                                                  \n\
 
171
                     return texture2D(TexObject, TexCoord.st);                          \n\
 
172
                     }                                                                  \n\
 
173
                     #elif defined SAMPLERTEX2DRECT                                     \n\
 
174
                     uniform sampler2DRect TextureObject0;                              \n\
 
175
                     vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)         \n\
 
176
                     {                                                                  \n\
 
177
                     return texture2DRect(TexObject, TexCoord.st);                      \n\
 
178
                     }                                                                  \n\
 
179
                     #endif                                                             \n\
 
180
                     void main()                                                        \n\
 
181
                     {                                                                  \n\
 
182
                     float alpha = SampleTexture(TextureObject0, varyTexCoord0).w;      \n\
 
183
                     gl_FragColor = vec4(varyVertexColor.xyz, alpha*varyVertexColor.a); \n\
 
184
                     }");
 
185
 
 
186
    m_SlColorModTexMaskAlpha = m_GLWindow.m_DeviceFactory->CreateShaderProgram();
 
187
    VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
 
188
    PS->SetShaderCode(TCHAR_TO_ANSI(*PSString), TEXT("#define SAMPLERTEX2D"));
 
189
    m_SlColorModTexMaskAlpha->ClearShaderObjects();
 
190
    m_SlColorModTexMaskAlpha->AddShaderObject(VS);
 
191
    m_SlColorModTexMaskAlpha->AddShaderObject(PS);
 
192
    CHECKGL( glBindAttribLocation(m_SlColorModTexMaskAlpha->GetOpenGLID(), 0, "AVertex") );
 
193
    CHECKGL( glBindAttribLocation(m_SlColorModTexMaskAlpha->GetOpenGLID(), 1, "MyTextureCoord0") );
 
194
    CHECKGL( glBindAttribLocation(m_SlColorModTexMaskAlpha->GetOpenGLID(), 2, "VectexColor") );
 
195
    m_SlColorModTexMaskAlpha->Link();
 
196
 
 
197
    m_SlColorModTexRectMaskAlpha = m_GLWindow.m_DeviceFactory->CreateShaderProgram();
 
198
    VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
 
199
    PS->SetShaderCode(TCHAR_TO_ANSI(*PSString), TEXT("#define SAMPLERTEX2DRECT"));
 
200
    m_SlColorModTexRectMaskAlpha->ClearShaderObjects();
 
201
    m_SlColorModTexRectMaskAlpha->AddShaderObject(VS);
 
202
    m_SlColorModTexRectMaskAlpha->AddShaderObject(PS);
 
203
    CHECKGL( glBindAttribLocation(m_SlColorModTexRectMaskAlpha->GetOpenGLID(), 0, "AVertex") );
 
204
    CHECKGL( glBindAttribLocation(m_SlColorModTexRectMaskAlpha->GetOpenGLID(), 1, "MyTextureCoord0") );
 
205
    CHECKGL( glBindAttribLocation(m_SlColorModTexRectMaskAlpha->GetOpenGLID(), 2, "VectexColor") );
 
206
    m_SlColorModTexRectMaskAlpha->Link();
 
207
}
 
208
 
 
209
void GraphicsContext::InitSl2TextureAdd()
 
210
{
 
211
    TRefGL<IOpenGLVertexShader> VS = m_GLWindow.m_DeviceFactory->CreateVertexShader();
 
212
    TRefGL<IOpenGLPixelShader> PS = m_GLWindow.m_DeviceFactory->CreatePixelShader();
 
213
    NString VSString;
 
214
    NString PSString;
 
215
 
 
216
    // For some strange reason, make sure that the attribute holding the vertex position has a name that comes first in alphabetic order before all
 
217
    // other  attributes. Otherwise you get a bug on NVidia! Why is that???
 
218
 
 
219
    ////////////////////////////////////////////////////////////////////////////////////////////////////
 
220
    VSString =  TEXT(   "#version 110                                           \n\
 
221
                        uniform mat4 ViewProjectionMatrix;                      \n\
 
222
                        attribute vec4 AVertex;                                 \n\
 
223
                        attribute vec4 MyTextureCoord0;                         \n\
 
224
                        attribute vec4 MyTextureCoord1;                         \n\
 
225
                        varying vec4 varyTexCoord0;                             \n\
 
226
                        varying vec4 varyTexCoord1;                             \n\
 
227
                        void main()                                             \n\
 
228
                        {                                                       \n\
 
229
                        varyTexCoord0 = MyTextureCoord0;                        \n\
 
230
                        varyTexCoord1 = MyTextureCoord1;                        \n\
 
231
                        gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
 
232
                        }");
 
233
 
 
234
    PSString =  TEXT(   "#version 110                                               \n\
 
235
                        #extension GL_ARB_texture_rectangle : enable                \n\
 
236
                        varying vec4 varyTexCoord0;                                 \n\
 
237
                        varying vec4 varyTexCoord1;                                 \n\
 
238
                        uniform vec4 color0;                                        \n\
 
239
                        uniform vec4 color1;                                        \n\
 
240
                        #ifdef SAMPLERTEX2D                                         \n\
 
241
                        uniform sampler2D TextureObject0;                           \n\
 
242
                        uniform sampler2D TextureObject1;                           \n\
 
243
                        vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
 
244
                        {                                                           \n\
 
245
                        return texture2D(TexObject, TexCoord.st);                   \n\
 
246
                        }                                                           \n\
 
247
                        #elif defined SAMPLERTEX2DRECT                              \n\
 
248
                        uniform sampler2DRect TextureObject0;                       \n\
 
249
                        uniform sampler2DRect TextureObject1;                       \n\
 
250
                        vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)  \n\
 
251
                        {                                                           \n\
 
252
                        return texture2DRect(TexObject, TexCoord.st);               \n\
 
253
                        }                                                           \n\
 
254
                        #elif define MOD_TEX_COLOR_RGB                              \n\
 
255
                        \n\
 
256
                        #elif define MOD_TEX_COLOR_ALPHA                            \n\
 
257
                        \n\
 
258
                        #endif                                                      \n\
 
259
                        void main()                                                 \n\
 
260
                        {                                                           \n\
 
261
                        vec4 b0 = color0*SampleTexture(TextureObject0, varyTexCoord0);     \n\
 
262
                        vec4 b1 = color1*SampleTexture(TextureObject1, varyTexCoord1);     \n\
 
263
                        gl_FragColor = b0.a*b0 + b1;    \n\
 
264
                        }");
 
265
 
 
266
    //vec4(v.w, v.w, v.w, v.w)
 
267
 
 
268
    // Textured 2D Primitive Shader
 
269
    m_Sl2TextureAdd = m_GLWindow.m_DeviceFactory->CreateShaderProgram();
 
270
    VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
 
271
    PS->SetShaderCode(TCHAR_TO_ANSI(*PSString), TEXT("#define SAMPLERTEX2D"));
 
272
 
 
273
    m_Sl2TextureAdd->ClearShaderObjects();
 
274
    m_Sl2TextureAdd->AddShaderObject(VS);
 
275
    m_Sl2TextureAdd->AddShaderObject(PS);
 
276
    CHECKGL( glBindAttribLocation(m_Sl2TextureAdd->GetOpenGLID(), 0, "AVertex") );
 
277
    m_Sl2TextureAdd->Link();
 
278
}
 
279
 
 
280
void GraphicsContext::InitSl4TextureAdd()
 
281
{
 
282
    TRefGL<IOpenGLVertexShader> VS = m_GLWindow.m_DeviceFactory->CreateVertexShader();
 
283
    TRefGL<IOpenGLPixelShader> PS = m_GLWindow.m_DeviceFactory->CreatePixelShader();
 
284
    NString VSString;
 
285
    NString PSString;
 
286
 
 
287
    // For some strange reason, make sure that the attribute holding the vertex position has a name that comes first in alphabetic order before all
 
288
    // other  attributes. Otherwise you get a bug on NVidia! Why is that???
 
289
 
 
290
    ////////////////////////////////////////////////////////////////////////////////////////////////////
 
291
    VSString =  TEXT(   "#version 110                                           \n\
 
292
                        uniform mat4 ViewProjectionMatrix;                      \n\
 
293
                        attribute vec4 AVertex;                                 \n\
 
294
                        attribute vec4 MyTextureCoord0;                         \n\
 
295
                        attribute vec4 MyTextureCoord1;                         \n\
 
296
                        attribute vec4 MyTextureCoord2;                         \n\
 
297
                        attribute vec4 MyTextureCoord3;                         \n\
 
298
                        varying vec4 varyTexCoord0;                             \n\
 
299
                        varying vec4 varyTexCoord1;                             \n\
 
300
                        varying vec4 varyTexCoord2;                             \n\
 
301
                        varying vec4 varyTexCoord3;                             \n\
 
302
                        void main()                                             \n\
 
303
                        {                                                       \n\
 
304
                        varyTexCoord0 = MyTextureCoord0;                        \n\
 
305
                        varyTexCoord1 = MyTextureCoord1;                        \n\
 
306
                        varyTexCoord2 = MyTextureCoord2;                        \n\
 
307
                        varyTexCoord3 = MyTextureCoord3;                        \n\
 
308
                        gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
 
309
                        }");
 
310
 
 
311
    PSString =  TEXT(   "#version 110                                               \n\
 
312
                        #extension GL_ARB_texture_rectangle : enable                \n\
 
313
                        varying vec4 varyTexCoord0;                                 \n\
 
314
                        varying vec4 varyTexCoord1;                                 \n\
 
315
                        varying vec4 varyTexCoord2;                                 \n\
 
316
                        varying vec4 varyTexCoord3;                                 \n\
 
317
                        uniform vec4 color0;                                        \n\
 
318
                        uniform vec4 color1;                                        \n\
 
319
                        uniform vec4 color2;                                        \n\
 
320
                        uniform vec4 color3;                                        \n\
 
321
                        #ifdef SAMPLERTEX2D                                         \n\
 
322
                        uniform sampler2D TextureObject0;                           \n\
 
323
                        uniform sampler2D TextureObject1;                           \n\
 
324
                        uniform sampler2D TextureObject2;                           \n\
 
325
                        uniform sampler2D TextureObject3;                           \n\
 
326
                        vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
 
327
                        {                                                           \n\
 
328
                        return texture2D(TexObject, TexCoord.st);                   \n\
 
329
                        }                                                           \n\
 
330
                        #elif defined SAMPLERTEX2DRECT                              \n\
 
331
                        uniform sampler2DRect TextureObject0;                       \n\
 
332
                        uniform sampler2DRect TextureObject1;                       \n\
 
333
                        uniform sampler2DRect TextureObject2;                       \n\
 
334
                        uniform sampler2DRect TextureObject3;                       \n\
 
335
                        vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)  \n\
 
336
                        {                                                           \n\
 
337
                        return texture2DRect(TexObject, TexCoord.st);               \n\
 
338
                        }                                                           \n\
 
339
                        #endif                                                      \n\
 
340
                        void main()                                                 \n\
 
341
                        {                                                           \n\
 
342
                        vec4 b0 = color0*SampleTexture(TextureObject0, varyTexCoord0);  \n\
 
343
                        vec4 b1 = color1*SampleTexture(TextureObject1, varyTexCoord1);  \n\
 
344
                        vec4 b2 = color2*SampleTexture(TextureObject2, varyTexCoord2);  \n\
 
345
                        vec4 b3 = color3*SampleTexture(TextureObject3, varyTexCoord3);  \n\
 
346
                        gl_FragColor = b0+b1+b2+b3;                                     \n\
 
347
                        }");
 
348
 
 
349
    //vec4(v.w, v.w, v.w, v.w)
 
350
 
 
351
    // Textured 2D Primitive Shader
 
352
    m_Sl4TextureAdd = m_GLWindow.m_DeviceFactory->CreateShaderProgram();
 
353
    VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
 
354
    PS->SetShaderCode(TCHAR_TO_ANSI(*PSString), TEXT("#define SAMPLERTEX2D"));
 
355
 
 
356
    m_Sl4TextureAdd->ClearShaderObjects();
 
357
    m_Sl4TextureAdd->AddShaderObject(VS);
 
358
    m_Sl4TextureAdd->AddShaderObject(PS);
 
359
    CHECKGL( glBindAttribLocation(m_Sl4TextureAdd->GetOpenGLID(), 0, "AVertex") );
 
360
    m_Sl4TextureAdd->Link();
 
361
 
 
362
//     // Textured Rect Primitive Shader
 
363
//     m_4TexBlendRectProg = m_GLWindow.m_DeviceFactory->CreateShaderProgram();
 
364
//     VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
 
365
//     PS->SetShaderCode(TCHAR_TO_ANSI(*PSString), TEXT("#define SAMPLERTEX2DRECT"));
 
366
//     m_4TexBlendRectProg->ClearShaderObjects();
 
367
//     m_4TexBlendRectProg->AddShaderObject(VS);
 
368
//     m_4TexBlendRectProg->AddShaderObject(PS);
 
369
//     CHECKGL( glBindAttribLocation(m_4TexBlendRectProg->GetOpenGLID(), 0, "AVertex") );
 
370
//     m_4TexBlendRectProg->Link();
 
371
}
 
372
 
 
373
void GraphicsContext::QRP_GLSL_Color(int x, int y, int width, int height, const Color& color)
 
374
{
 
375
#if USE_ARB
 
376
    QRP_Color(x, y, width, height, color, color, color, color);
 
377
    return;
 
378
#endif
 
379
 
 
380
    QRP_GLSL_Color(x, y, width, height, color, color, color, color);
 
381
}
 
382
 
 
383
void GraphicsContext::QRP_GLSL_Color(int x, int y, int width, int height, const Color& c0, const Color& c1, const Color& c2, const Color& c3)
 
384
{
 
385
#if USE_ARB
 
386
    QRP_Color(x, y, width, height, c0, c1, c2, c3);
 
387
    return;
 
388
#endif
 
389
 
 
390
    m_quad_tex_stats++;
 
391
 
 
392
    float VtxBuffer[] =
 
393
    {
 
394
        x,          y,          0.0f, 1.0f, c0.R(), c0.G(), c0.B(), c0.A(),
 
395
        x,          y + height, 0.0f, 1.0f, c1.R(), c1.G(), c1.B(), c1.A(),
 
396
        x + width,  y + height, 0.0f, 1.0f, c2.R(), c2.G(), c2.B(), c2.A(),
 
397
        x + width,  y,          0.0f, 1.0f, c3.R(), c3.G(), c3.B(), c3.A(),
 
398
    };
 
399
 
 
400
    TRefGL<IOpenGLShaderProgram> ShaderProg = m_SlColor;
 
401
 
 
402
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
403
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
404
    ShaderProg->Begin();
 
405
 
 
406
    int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
 
407
    int VertexColorLocation = ShaderProg->GetAttributeLocation("VertexColor");
 
408
 
 
409
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
 
410
    ShaderProg->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(GetModelViewProjectionMatrix().m));
 
411
 
 
412
    CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
 
413
    CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer) );
 
414
 
 
415
    if(VertexColorLocation != -1)
 
416
    {
 
417
        CHECKGL( glEnableVertexAttribArrayARB(VertexColorLocation) );
 
418
        CHECKGL( glVertexAttribPointerARB((GLuint)VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4) );
 
419
    }
 
420
 
 
421
    CHECKGL( glDrawArrays(GL_QUADS, 0, 4) );
 
422
 
 
423
    CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
 
424
    if(VertexColorLocation != -1)
 
425
        CHECKGL( glDisableVertexAttribArrayARB(VertexColorLocation) );
 
426
    ShaderProg->End();
 
427
}
 
428
 
 
429
void GraphicsContext::QRP_GLSL_1Tex(int x, int y, int width, int height, TRefGL<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform0, const Color& color0)
 
430
{
 
431
#if USE_ARB
 
432
    QRP_1Tex(x, y, width, height, DeviceTexture, texxform0, color0);
 
433
    return;
 
434
#endif
 
435
 
 
436
    m_quad_tex_stats++;
 
437
    QRP_Compute_Texture_Coord(width, height, DeviceTexture, texxform0);
 
438
    float VtxBuffer[] =
 
439
    {
 
440
        x,          y,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0, color0.R(), color0.G(), color0.B(), color0.A(),
 
441
        x,          y + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0, color0.R(), color0.G(), color0.B(), color0.A(),
 
442
        x + width,  y + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0, color0.R(), color0.G(), color0.B(), color0.A(),
 
443
        x + width,  y,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0, color0.R(), color0.G(), color0.B(), color0.A(),
 
444
    };
 
445
 
 
446
    TRefGL<IOpenGLShaderProgram> ShaderProg;
 
447
    if(DeviceTexture->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType))
 
448
    {
 
449
        ShaderProg = m_SlTextureModColor;
 
450
    }
 
451
 
 
452
//     if(DeviceTexture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType) || 
 
453
//         DeviceTexture->Type().IsDerivedFromType(IOpenGLAnimatedTexture::StaticObjectType))
 
454
//     {
 
455
//         ShaderProg = m_TexturedRectProg;
 
456
//     }
 
457
 
 
458
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
459
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
460
    ShaderProg->Begin();
 
461
 
 
462
    int TextureObjectLocation = ShaderProg->GetUniformLocationARB("TextureObject0");
 
463
    int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
 
464
    int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0");
 
465
    int VertexColorLocation = ShaderProg->GetAttributeLocation("VertexColor");
 
466
 
 
467
    SetTexture(GL_TEXTURE0, DeviceTexture);
 
468
    CHECKGL( glUniform1iARB(TextureObjectLocation, 0) );
 
469
 
 
470
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
 
471
    ShaderProg->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(GetModelViewProjectionMatrix().m));
 
472
 
 
473
    CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
 
474
    CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
 
475
 
 
476
    if(TextureCoord0Location != -1)
 
477
    {
 
478
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord0Location) );
 
479
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
 
480
    }
 
481
 
 
482
    if(VertexColorLocation != -1)
 
483
    {
 
484
        CHECKGL( glEnableVertexAttribArrayARB(VertexColorLocation) );
 
485
        CHECKGL( glVertexAttribPointerARB((GLuint)VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
 
486
    }
 
487
 
 
488
    CHECKGL( glDrawArrays(GL_QUADS, 0, 4) );
 
489
 
 
490
    CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
 
491
    if(TextureCoord0Location != -1)
 
492
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord0Location) );
 
493
    if(VertexColorLocation != -1)
 
494
        CHECKGL( glDisableVertexAttribArrayARB(VertexColorLocation) );
 
495
    ShaderProg->End();
 
496
}
 
497
 
 
498
// Render the texture alpha into RGB and modulated by a color.
 
499
void GraphicsContext::QRP_GLSL_ColorModTexAlpha(int x, int y, int width, int height,
 
500
                                                TRefGL< IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& color)
 
501
{
 
502
#if USE_ARB
 
503
    QRP_ColorModTexAlpha(x, y, width, height, DeviceTexture, texxform, color);
 
504
    return;
 
505
#endif
 
506
 
 
507
    m_quad_tex_stats++;
 
508
    QRP_Compute_Texture_Coord(width, height, DeviceTexture, texxform);
 
509
 
 
510
    float VtxBuffer[] =
 
511
    {
 
512
        x,          y,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 0, color.R(), color.G(), color.B(), color.A(),
 
513
        x,          y + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 0, color.R(), color.G(), color.B(), color.A(),
 
514
        x + width,  y + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 0, color.R(), color.G(), color.B(), color.A(),
 
515
        x + width,  y,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 0, color.R(), color.G(), color.B(), color.A(),
 
516
    };
 
517
 
 
518
    TRefGL<IOpenGLShaderProgram> ShaderProg;
 
519
//     if(DeviceTexture->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType))
 
520
    {
 
521
        ShaderProg = m_SlColorModTexMaskAlpha;
 
522
    }
 
523
 
 
524
    if(DeviceTexture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType) || 
 
525
        DeviceTexture->Type().IsDerivedFromType(IOpenGLAnimatedTexture::StaticObjectType))
 
526
    {
 
527
        ShaderProg = m_SlColorModTexRectMaskAlpha;
 
528
    }
 
529
 
 
530
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
531
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
532
    ShaderProg->Begin();
 
533
 
 
534
    int TextureObjectLocation = ShaderProg->GetUniformLocationARB("TextureObject0");
 
535
    int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
 
536
    int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0");
 
537
    int VertexColorLocation = ShaderProg->GetAttributeLocation("VertexColor");
 
538
 
 
539
    SetTexture(GL_TEXTURE0, DeviceTexture);
 
540
 
 
541
    if(TextureObjectLocation != -1)
 
542
    {
 
543
        CHECKGL( glUniform1iARB(TextureObjectLocation, 0) );
 
544
    }
 
545
 
 
546
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
 
547
    ShaderProg->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(GetModelViewProjectionMatrix().m));
 
548
 
 
549
    if(VertexLocation != -1)
 
550
    {
 
551
        CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
 
552
        CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
 
553
    }
 
554
 
 
555
    if(TextureCoord0Location != -1)
 
556
    {
 
557
        CHECKGL( glEnableVertexAttribArray(TextureCoord0Location) );
 
558
        CHECKGL( glVertexAttribPointer((GLuint)TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
 
559
    }
 
560
 
 
561
    if(VertexColorLocation != -1)
 
562
    {
 
563
        CHECKGL( glEnableVertexAttribArrayARB(VertexColorLocation) );
 
564
        CHECKGL( glVertexAttribPointerARB((GLuint)VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
 
565
    }
 
566
 
 
567
    CHECKGL( glDrawArrays(GL_QUADS, 0, 4) );
 
568
 
 
569
    if(VertexLocation != -1)
 
570
        CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
 
571
    if(TextureCoord0Location != -1)
 
572
    {
 
573
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord0Location) );
 
574
    }
 
575
    if(VertexColorLocation != -1)
 
576
    {
 
577
        CHECKGL( glDisableVertexAttribArrayARB(VertexColorLocation) );
 
578
    }
 
579
    ShaderProg->End();
 
580
}
 
581
 
 
582
// Blend 2 textures together
 
583
void GraphicsContext::QRP_GLSL_2Tex(int x, int y, int width, int height,
 
584
                                    TRefGL<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
 
585
                                    TRefGL<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1)
 
586
{
 
587
#if USE_ARB
 
588
    QRP_2Tex(x, y, width, height, DeviceTexture0, texxform0, color0, DeviceTexture1, texxform1, color1);
 
589
    return;
 
590
#endif
 
591
 
 
592
    bool bRectangleTexture = false;
 
593
    TRefGL<IOpenGLShaderProgram> ShaderProg;
 
594
//     if(SrcTexture0->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType) &&
 
595
//        SrcTexture1->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType))
 
596
    {
 
597
        ShaderProg = m_Sl2TextureAdd;
 
598
    }
 
599
 
 
600
//     if((SrcTexture0->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType) &&
 
601
//         SrcTexture1->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType)) /*|| 
 
602
//         (SrcTexture0->Type().IsDerivedFromType(NAnimatedTexture::StaticObjectType) &&
 
603
//         SrcTexture1->Type().IsDerivedFromType(NAnimatedTexture::StaticObjectType)*/)
 
604
//     {
 
605
//         bRectangleTexture = true;
 
606
//         ShaderProg = m_2TexBlendRectProg;
 
607
//     }
 
608
 
 
609
    QRP_Compute_Texture_Coord(width, height, DeviceTexture0, texxform0);
 
610
    QRP_Compute_Texture_Coord(width, height, DeviceTexture1, texxform1);
 
611
 
 
612
    float VtxBuffer[] =
 
613
    {
 
614
        x,          y,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0.0f, 1.0f, texxform1.u0, texxform1.v0, 0.0f, 1.0f,
 
615
        x,          y + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0.0f, 1.0f, texxform1.u0, texxform1.v1, 0.0f, 1.0f,
 
616
        x + width,  y + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0.0f, 1.0f, texxform1.u1, texxform1.v1, 0.0f, 1.0f,
 
617
        x + width,  y,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0.0f, 1.0f, texxform1.u1, texxform1.v0, 0.0f, 1.0f,
 
618
    };
 
619
 
 
620
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
621
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
622
    ShaderProg->Begin();
 
623
 
 
624
    int TextureObjectLocation0 = ShaderProg->GetUniformLocationARB("TextureObject0");
 
625
    int TextureObjectLocation1 = ShaderProg->GetUniformLocationARB("TextureObject1");
 
626
    int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
 
627
    int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0");
 
628
    int TextureCoord1Location = ShaderProg->GetAttributeLocation("MyTextureCoord1");
 
629
 
 
630
    int TextureCoef0Location = ShaderProg->GetUniformLocationARB("color0");
 
631
    int TextureCoef1Location = ShaderProg->GetUniformLocationARB("color1");
 
632
 
 
633
 
 
634
    SetTexture(GL_TEXTURE0, DeviceTexture0);
 
635
    SetTexture(GL_TEXTURE1, DeviceTexture1);
 
636
 
 
637
    CHECKGL( glUniform1iARB(TextureObjectLocation0, 0) );
 
638
    CHECKGL( glUniform1iARB(TextureObjectLocation1, 1) );
 
639
 
 
640
    CHECKGL( glUniform4fARB(TextureCoef0Location, color0.R(), color0.G(), color0.B(), color0.A()) );
 
641
    CHECKGL( glUniform4fARB(TextureCoef1Location, color1.R(), color1.G(), color1.B(), color1.A()) );
 
642
 
 
643
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
 
644
    ShaderProg->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(GetModelViewProjectionMatrix().m));
 
645
 
 
646
    CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
 
647
    CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
 
648
 
 
649
    if(TextureCoord0Location != -1)
 
650
    {
 
651
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord0Location) );
 
652
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
 
653
    }
 
654
    if(TextureCoord1Location != -1)
 
655
    {
 
656
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord1Location) );
 
657
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
 
658
    }
 
659
 
 
660
    CHECKGL( glDrawArrays(GL_QUADS, 0, 4) );
 
661
 
 
662
    CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
 
663
    if(TextureCoord0Location != -1)
 
664
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord0Location) );
 
665
    if(TextureCoord1Location != -1)
 
666
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord1Location) );
 
667
 
 
668
    ShaderProg->End();
 
669
}
 
670
 
 
671
void GraphicsContext::QRP_GLSL_4Tex(int x, int y, int width, int height,
 
672
                   TRefGL<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
 
673
                   TRefGL<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1,
 
674
                   TRefGL<IOpenGLBaseTexture> DeviceTexture2, TexCoordXForm& texxform2, const Color& color2,
 
675
                   TRefGL<IOpenGLBaseTexture> DeviceTexture3, TexCoordXForm& texxform3, const Color& color3)
 
676
{
 
677
#if USE_ARB
 
678
    QRP_4Tex(x, y, width, height, DeviceTexture0, texxform0, color0, DeviceTexture1, texxform1, color1,
 
679
        DeviceTexture2, texxform2, color2, DeviceTexture3, texxform3, color3);
 
680
    return;
 
681
#endif
 
682
 
 
683
    QRP_Compute_Texture_Coord(width, height, DeviceTexture0, texxform0);
 
684
    QRP_Compute_Texture_Coord(width, height, DeviceTexture1, texxform1);
 
685
    QRP_Compute_Texture_Coord(width, height, DeviceTexture2, texxform2);
 
686
    QRP_Compute_Texture_Coord(width, height, DeviceTexture3, texxform3);
 
687
 
 
688
    bool bRectangleTexture = false;
 
689
    TRefGL<IOpenGLShaderProgram> ShaderProg;
 
690
//     if(SrcTexture0->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType) &&
 
691
//        SrcTexture1->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType) &&
 
692
//        SrcTexture2->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType) &&
 
693
//        SrcTexture3->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType))
 
694
    {
 
695
        ShaderProg = m_Sl4TextureAdd;
 
696
    }
 
697
 
 
698
//     if((SrcTexture0->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType) &&
 
699
//         SrcTexture1->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType) &&
 
700
//         SrcTexture2->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType) &&
 
701
//         SrcTexture3->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType)) /*|| 
 
702
//         (SrcTexture0->Type().IsDerivedFromType(NAnimatedTexture::StaticObjectType) &&
 
703
//         SrcTexture1->Type().IsDerivedFromType(NAnimatedTexture::StaticObjectType) &&
 
704
//         SrcTexture2->Type().IsDerivedFromType(NAnimatedTexture::StaticObjectType) &&
 
705
//         SrcTexture3->Type().IsDerivedFromType(NAnimatedTexture::StaticObjectType))*/)
 
706
//     {
 
707
//         bRectangleTexture = true;
 
708
//         ShaderProg = m_4TexBlendRectProg;
 
709
//     }
 
710
 
 
711
    float VtxBuffer[] =
 
712
    {
 
713
        x,          y,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 1.0f, texxform1.u0, texxform1.v0, 0, 1.0f, texxform2.u0, texxform2.v0, 0, 1.0f, texxform3.u0, texxform3.v0, 0, 1.0f,
 
714
        x,          y + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 1.0f, texxform1.u0, texxform1.v1, 0, 1.0f, texxform2.u0, texxform2.v1, 0, 1.0f, texxform3.u0, texxform3.v1, 0, 1.0f,
 
715
        x + width,  y + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 1.0f, texxform1.u1, texxform1.v1, 0, 1.0f, texxform2.u1, texxform2.v1, 0, 1.0f, texxform3.u1, texxform3.v1, 0, 1.0f,
 
716
        x + width,  y,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 1.0f, texxform1.u1, texxform1.v0, 0, 1.0f, texxform2.u1, texxform2.v0, 0, 1.0f, texxform3.u1, texxform3.v0, 0, 1.0f,
 
717
    };
 
718
 
 
719
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
720
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
721
    ShaderProg->Begin();
 
722
 
 
723
    int TextureObjectLocation0 = ShaderProg->GetUniformLocationARB("TextureObject0");
 
724
    int TextureObjectLocation1 = ShaderProg->GetUniformLocationARB("TextureObject1");
 
725
    int TextureObjectLocation2 = ShaderProg->GetUniformLocationARB("TextureObject2");
 
726
    int TextureObjectLocation3 = ShaderProg->GetUniformLocationARB("TextureObject3");
 
727
    int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
 
728
    int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0");
 
729
    int TextureCoord1Location = ShaderProg->GetAttributeLocation("MyTextureCoord1");
 
730
    int TextureCoord2Location = ShaderProg->GetAttributeLocation("MyTextureCoord2");
 
731
    int TextureCoord3Location = ShaderProg->GetAttributeLocation("MyTextureCoord3");
 
732
 
 
733
    int TextureCoef0Location = ShaderProg->GetUniformLocationARB("color0");
 
734
    int TextureCoef1Location = ShaderProg->GetUniformLocationARB("color1");
 
735
    int TextureCoef2Location = ShaderProg->GetUniformLocationARB("color2");
 
736
    int TextureCoef3Location = ShaderProg->GetUniformLocationARB("color3");
 
737
 
 
738
    SetTexture(GL_TEXTURE0, DeviceTexture0);
 
739
    SetTexture(GL_TEXTURE1, DeviceTexture1);
 
740
    SetTexture(GL_TEXTURE2, DeviceTexture2);
 
741
    SetTexture(GL_TEXTURE3, DeviceTexture3);
 
742
 
 
743
    CHECKGL( glUniform1iARB(TextureObjectLocation0, 0) );
 
744
    CHECKGL( glUniform1iARB(TextureObjectLocation1, 1) );
 
745
    CHECKGL( glUniform1iARB(TextureObjectLocation2, 2) );
 
746
    CHECKGL( glUniform1iARB(TextureObjectLocation3, 3) );
 
747
 
 
748
    CHECKGL( glUniform4fARB(TextureCoef0Location, color0.R(), color0.G(), color0.B(), color0.A()) );
 
749
    CHECKGL( glUniform4fARB(TextureCoef1Location, color1.R(), color1.G(), color1.B(), color1.A()) );
 
750
    CHECKGL( glUniform4fARB(TextureCoef0Location, color2.R(), color2.G(), color2.B(), color2.A()) );
 
751
    CHECKGL( glUniform4fARB(TextureCoef1Location, color3.R(), color3.G(), color3.B(), color3.A()) );
 
752
 
 
753
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
 
754
    ShaderProg->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(GetModelViewProjectionMatrix().m));
 
755
 
 
756
    CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
 
757
    CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer) );
 
758
 
 
759
    if(TextureCoord0Location != -1)
 
760
    {
 
761
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord0Location) );
 
762
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 4) );
 
763
    }
 
764
    if(TextureCoord1Location != -1)
 
765
    {
 
766
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord1Location) );
 
767
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 8) );
 
768
    }
 
769
    if(TextureCoord2Location != -1)
 
770
    {
 
771
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord2Location) );
 
772
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord2Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 12) );
 
773
    }
 
774
    if(TextureCoord3Location != -1)
 
775
    {
 
776
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord3Location) );
 
777
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord3Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 16) );
 
778
    }
 
779
 
 
780
    CHECKGL( glDrawArrays(GL_QUADS, 0, 4) );
 
781
 
 
782
    CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
 
783
    if(TextureCoord0Location != -1)
 
784
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord0Location) );
 
785
    if(TextureCoord1Location != -1)
 
786
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord1Location) );
 
787
    if(TextureCoord2Location != -1)
 
788
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord2Location) );
 
789
    if(TextureCoord3Location != -1)
 
790
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord3Location) );
 
791
 
 
792
    ShaderProg->End();
 
793
}
 
794
///////////////////////////////////////////
 
795
void GraphicsContext::QRP_GLSL_Triangle(int x0, int y0,
 
796
                                          int x1, int y1,
 
797
                                          int x2, int y2,
 
798
                                          Color c0)
 
799
{
 
800
#if USE_ARB
 
801
    QRP_Triangle(x0, y0, x1, y1, x2, y2, c0, c0, c0);
 
802
    return;
 
803
#endif
 
804
 
 
805
    QRP_GLSL_Triangle(x0, y0, x1, y1, x2, y2, c0, c0, c0);
 
806
}
 
807
 
 
808
void GraphicsContext::QRP_GLSL_Triangle(int x0, int y0,
 
809
                                          int x1, int y1,
 
810
                                          int x2, int y2,
 
811
                                          Color c0, Color c1, Color c2)
 
812
{
 
813
#if USE_ARB
 
814
    QRP_Triangle(x0, y0, x1, y1, x2, y2, c0, c1, c2);
 
815
    return;
 
816
#endif
 
817
 
 
818
    float VtxBuffer[] =     
 
819
    {
 
820
        x0, y0, 0.0f, 1.0f, c0.R(), c0.G(), c0.B(), c0.A(),
 
821
        x1, y1, 0.0f, 1.0f, c1.R(), c1.G(), c1.B(), c1.A(),
 
822
        x2, y2, 0.0f, 1.0f, c2.R(), c2.G(), c2.B(), c2.A(),
 
823
    };
 
824
 
 
825
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
826
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
827
 
 
828
    m_SlColor->Begin();
 
829
 
 
830
    int VertexLocation = m_SlColor->GetAttributeLocation("AVertex");
 
831
    int VertexColorLocation = m_SlColor->GetAttributeLocation("VertexColor");
 
832
 
 
833
    int VPMatrixLocation = m_SlColor->GetUniformLocationARB("ViewProjectionMatrix");
 
834
    m_SlColor->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(GetModelViewProjectionMatrix().m));
 
835
 
 
836
    CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
 
837
    CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer) );
 
838
 
 
839
    CHECKGL( glEnableVertexAttribArrayARB(VertexColorLocation) );
 
840
    CHECKGL( glVertexAttribPointerARB((GLuint)VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4) );
 
841
 
 
842
    CHECKGL( glDrawArrays(GL_TRIANGLES, 0, 3) );
 
843
 
 
844
    CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
 
845
    CHECKGL( glDisableVertexAttribArrayARB(VertexColorLocation) );
 
846
    m_SlColor->End();
 
847
 
 
848
    m_triangle_stats++;
 
849
}
 
850
 
 
851
//////////////////////
 
852
// DRAW LINES       //
 
853
//////////////////////
 
854
void GraphicsContext::QRP_GLSL_Line(int x0, int y0,
 
855
                                 int x1, int y1, Color c0)
 
856
{
 
857
#if USE_ARB
 
858
    QRP_Line(x0, y0, x1, y1, c0, c0);
 
859
    return;
 
860
#endif
 
861
 
 
862
    QRP_Line(x0, y0, x1, y1, c0, c0);
 
863
}
 
864
 
 
865
void GraphicsContext::QRP_GLSL_Line(int x0, int y0,
 
866
                                 int x1, int y1, Color c0, Color c1)
 
867
{
 
868
#if USE_ARB
 
869
    QRP_Line(x0, y0, x1, y1, c0, c1);
 
870
    return;
 
871
#endif
 
872
 
 
873
    float VtxBuffer[] =
 
874
    {
 
875
        x0, y0, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c0.R(), c0.G(), c0.B(), c0.A(),
 
876
        x1, y1, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c1.R(), c1.G(), c1.B(), c1.A(),
 
877
    };
 
878
 
 
879
    TRefGL<IOpenGLShaderProgram> ShaderProg = m_SlColor;
 
880
 
 
881
 
 
882
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
883
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
884
    ShaderProg->Begin();
 
885
 
 
886
    int TextureObjectLocation = ShaderProg->GetUniformLocationARB("TextureObject0");
 
887
    int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
 
888
    int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0");
 
889
    int VertexColorLocation = ShaderProg->GetAttributeLocation("VertexColor");
 
890
 
 
891
 
 
892
    CHECKGL( glUniform1iARB(TextureObjectLocation, 0) );
 
893
 
 
894
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
 
895
    ShaderProg->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(GetModelViewProjectionMatrix().m));
 
896
 
 
897
    CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
 
898
    CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
 
899
 
 
900
    if(TextureCoord0Location != -1)
 
901
    {
 
902
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord0Location) );
 
903
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
 
904
    }
 
905
 
 
906
    if(VertexColorLocation != -1)
 
907
    {
 
908
        CHECKGL( glEnableVertexAttribArrayARB(VertexColorLocation) );
 
909
        CHECKGL( glVertexAttribPointerARB((GLuint)VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
 
910
    }
 
911
 
 
912
    CHECKGL( glDrawArrays(GL_LINES, 0, 2) );
 
913
 
 
914
    CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
 
915
    if(TextureCoord0Location != -1)
 
916
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord0Location) );
 
917
    if(VertexColorLocation != -1)
 
918
        CHECKGL( glDisableVertexAttribArrayARB(VertexColorLocation) );
 
919
    ShaderProg->End();
 
920
 
 
921
    m_line_stats++;
 
922
}
 
923
 
 
924
void GraphicsContext::QRP_GLSL_QuadWireframe(int x0, int y0, int width, int height,
 
925
                                          Color c0,
 
926
                                          Color c1,
 
927
                                          Color c2,
 
928
                                          Color c3)
 
929
{
 
930
#if USE_ARB
 
931
    QRP_QuadWireframe(x0, y0, width, height, c0, c1, c2, c3);
 
932
    return;
 
933
#endif
 
934
 
 
935
    float VtxBuffer[] =
 
936
    {
 
937
        x0, y0,                             0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c0.R(), c0.G(), c0.B(), c0.A(),
 
938
        x0, y0 + height - 1,                0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c1.R(), c1.G(), c1.B(), c1.A(),
 
939
        x0 + width - 1, y0 + height - 1,    0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c2.R(), c2.G(), c2.B(), c2.A(),
 
940
        x0 + width - 1, y0,                 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c3.R(), c3.G(), c3.B(), c3.A(),
 
941
        x0, y0,                             0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c0.R(), c0.G(), c0.B(), c0.A(),
 
942
    };
 
943
 
 
944
    TRefGL<IOpenGLShaderProgram> ShaderProg = m_SlColor;
 
945
 
 
946
 
 
947
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
948
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
949
    ShaderProg->Begin();
 
950
 
 
951
    int TextureObjectLocation = ShaderProg->GetUniformLocationARB("TextureObject0");
 
952
    int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
 
953
    int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0");
 
954
    int VertexColorLocation = ShaderProg->GetAttributeLocation("VertexColor");
 
955
 
 
956
 
 
957
    CHECKGL( glUniform1iARB(TextureObjectLocation, 0) );
 
958
 
 
959
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
 
960
    ShaderProg->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*)&(GetModelViewProjectionMatrix().m));
 
961
 
 
962
    CHECKGL( glEnableVertexAttribArrayARB(VertexLocation) );
 
963
    CHECKGL( glVertexAttribPointerARB((GLuint)VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
 
964
 
 
965
    if(TextureCoord0Location != -1)
 
966
    {
 
967
        CHECKGL( glEnableVertexAttribArrayARB(TextureCoord0Location) );
 
968
        CHECKGL( glVertexAttribPointerARB((GLuint)TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
 
969
    }
 
970
 
 
971
    if(VertexColorLocation != -1)
 
972
    {
 
973
        CHECKGL( glEnableVertexAttribArrayARB(VertexColorLocation) );
 
974
        CHECKGL( glVertexAttribPointerARB((GLuint)VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
 
975
    }
 
976
 
 
977
    CHECKGL( glDrawArrays(GL_LINE_STRIP, 0, 5) );
 
978
 
 
979
    CHECKGL( glDisableVertexAttribArrayARB(VertexLocation) );
 
980
    if(TextureCoord0Location != -1)
 
981
        CHECKGL( glDisableVertexAttribArrayARB(TextureCoord0Location) );
 
982
    if(VertexColorLocation != -1)
 
983
        CHECKGL( glDisableVertexAttribArrayARB(VertexColorLocation) );
 
984
    ShaderProg->End();
 
985
 
 
986
    m_line_stats++;
 
987
}
 
988
 
 
989
NAMESPACE_END_OGL
 
990