1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
#include "drape/glfunctions.hpp"
#include "drape/glIncludes.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#ifdef DEBUG
#include "base/thread.hpp"
#include "base/mutex.hpp"
#include "std/map.hpp"
#endif
#include "std/cstring.hpp"
#ifndef OMIM_OS_WINDOWS
#define APIENTRY
#endif
namespace
{
#ifdef DEBUG
typedef pair<threads::ThreadID, glConst> TKey;
typedef pair<TKey, uint32_t> TNode;
typedef map<TKey, uint32_t> TBoundMap;
TBoundMap g_boundBuffers;
threads::Mutex g_mutex;
#endif
inline GLboolean convert(bool v)
{
return (v == true) ? GL_TRUE : GL_FALSE;
}
void (APIENTRY *glClearColorFn)(GLfloat r, GLfloat g, GLfloat b, GLfloat a) = NULL;
void (APIENTRY *glClearFn)(GLbitfield mask) = NULL;
void (APIENTRY *glViewportFn)(GLint x, GLint y, GLsizei w, GLsizei h) = NULL;
void (APIENTRY *glFlushFn)() = NULL;
void (APIENTRY *glBindFramebufferFn)(GLenum target, GLuint id) = NULL;
/// VAO
void (APIENTRY *glGenVertexArraysFn)(GLsizei n, GLuint * ids) = NULL;
void (APIENTRY *glBindVertexArrayFn)(GLuint id) = NULL;
void (APIENTRY *glDeleteVertexArrayFn)(GLsizei n, GLuint const * ids) = NULL;
/// VBO
void (APIENTRY *glGenBuffersFn)(GLsizei n, GLuint * buffers) = NULL;
void (APIENTRY *glBindBufferFn)(GLenum target, GLuint buffer) = NULL;
void (APIENTRY *glDeleteBuffersFn)(GLsizei n, GLuint const * buffers) = NULL;
void (APIENTRY *glBufferDataFn)(GLenum target, GLsizeiptr size, GLvoid const * data, GLenum usage) = NULL;
void (APIENTRY *glBufferSubDataFn)(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid const * data) = NULL;
void * (APIENTRY *glMapBufferFn)(GLenum target, GLenum access) = NULL;
GLboolean (APIENTRY *glUnmapBufferFn)(GLenum target) = NULL;
/// Shaders
GLuint (APIENTRY *glCreateShaderFn)(GLenum type) = NULL;
void (APIENTRY *glShaderSourceFn)(GLuint shaderID, GLsizei count, GLchar const ** string, GLint const * length) = NULL;
void (APIENTRY *glCompileShaderFn)(GLuint shaderID) = NULL;
void (APIENTRY *glDeleteShaderFn)(GLuint shaderID) = NULL;
void (APIENTRY *glGetShaderivFn)(GLuint shaderID, GLenum name, GLint * p) = NULL;
void (APIENTRY *glGetShaderInfoLogFn)(GLuint shaderID, GLsizei maxLength, GLsizei * length, GLchar * infoLog) = NULL;
GLuint (APIENTRY *glCreateProgramFn)() = NULL;
void (APIENTRY *glAttachShaderFn)(GLuint programID, GLuint shaderID) = NULL;
void (APIENTRY *glDetachShaderFn)(GLuint programID, GLuint shaderID) = NULL;
void (APIENTRY *glLinkProgramFn)(GLuint programID) = NULL;
void (APIENTRY *glDeleteProgramFn)(GLuint programID) = NULL;
void (APIENTRY *glGetProgramivFn)(GLuint programID, GLenum name, GLint * p) = NULL;
void (APIENTRY *glGetProgramInfoLogFn)(GLuint programID, GLsizei maxLength, GLsizei * length, GLchar * infoLog) = NULL;
void (APIENTRY *glUseProgramFn)(GLuint programID) = NULL;
GLint (APIENTRY *glGetAttribLocationFn)(GLuint program, GLchar const * name) = NULL;
void (APIENTRY *glBindAttribLocationFn)(GLuint program, GLuint index, GLchar const * name) = NULL;
void (APIENTRY *glEnableVertexAttributeFn)(GLuint location) = NULL;
void (APIENTRY *glVertexAttributePointerFn)(GLuint index,
GLint count,
GLenum type,
GLboolean normalize,
GLsizei stride,
GLvoid const * p) = NULL;
GLint (APIENTRY *glGetUniformLocationFn)(GLuint programID, GLchar const * name) = NULL;
void (APIENTRY *glGetActiveUniformFn)(GLuint programID,
GLuint uniformIndex,
GLsizei bufSize,
GLsizei * length,
GLint * size,
GLenum * type,
GLchar * name) = NULL;
void (APIENTRY *glUniform1iFn)(GLint location, GLint value) = NULL;
void (APIENTRY *glUniform2iFn)(GLint location, GLint v1, GLint v2) = NULL;
void (APIENTRY *glUniform3iFn)(GLint location, GLint v1, GLint v2, GLint v3) = NULL;
void (APIENTRY *glUniform4iFn)(GLint location, GLint v1, GLint v2, GLint v3, GLint v4) = NULL;
void (APIENTRY *glUniform1ivFn)(GLint location, GLsizei count, GLint const * value) = NULL;
void (APIENTRY *glUniform1fFn)(GLint location, GLfloat value) = NULL;
void (APIENTRY *glUniform2fFn)(GLint location, GLfloat v1, GLfloat v2) = NULL;
void (APIENTRY *glUniform3fFn)(GLint location, GLfloat v1, GLfloat v2, GLfloat v3) = NULL;
void (APIENTRY *glUniform4fFn)(GLint location, GLfloat v1, GLfloat v2, GLfloat v3, GLfloat v4) = NULL;
void (APIENTRY *glUniform1fvFn)(GLint location, GLsizei count, GLfloat const * value) = NULL;
void (APIENTRY *glUniformMatrix4fvFn)(GLint location, GLsizei count, GLboolean transpose, GLfloat const * value) = NULL;
int const GLCompileStatus = GL_COMPILE_STATUS;
int const GLLinkStatus = GL_LINK_STATUS;
}
void GLFunctions::Init()
{
/// VAO
#if defined(OMIM_OS_MAC)
glGenVertexArraysFn = &glGenVertexArraysAPPLE;
glBindVertexArrayFn = &glBindVertexArrayAPPLE;
glDeleteVertexArrayFn = &glDeleteVertexArraysAPPLE;
glMapBufferFn = &::glMapBuffer;
glUnmapBufferFn = &::glUnmapBuffer;
#elif defined(OMIM_OS_LINUX)
glGenVertexArraysFn = &::glGenVertexArrays;
glBindVertexArrayFn = &::glBindVertexArray;
glDeleteVertexArrayFn = &::glDeleteVertexArrays;
glMapBufferFn = &::glMapBuffer; // I don't know correct name for linux!
glUnmapBufferFn = &::glUnmapBuffer; // I don't know correct name for linux!
#elif defined(OMIM_OS_MOBILE)
glGenVertexArraysFn = &glGenVertexArraysOES;
glBindVertexArrayFn = &glBindVertexArrayOES;
glDeleteVertexArrayFn = &glDeleteVertexArraysOES;
glMapBufferFn = &::glMapBufferOES;
glUnmapBufferFn = &::glUnmapBufferOES;
#endif
glBindFramebufferFn = &::glBindFramebuffer;
glClearColorFn = &::glClearColor;
glClearFn = &::glClear;
glViewportFn = &::glViewport;
glFlushFn = &::glFlush;
/// VBO
glGenBuffersFn = &::glGenBuffers;
glBindBufferFn = &::glBindBuffer;
glDeleteBuffersFn = &::glDeleteBuffers;
glBufferDataFn = &::glBufferData;
glBufferSubDataFn = &::glBufferSubData;
/// Shaders
glCreateShaderFn = &::glCreateShader;
typedef void (APIENTRY *glShaderSource_Type)(GLuint shaderID, GLsizei count, GLchar const ** string, GLint const * length);
glShaderSourceFn = reinterpret_cast<glShaderSource_Type>(&::glShaderSource);
glCompileShaderFn = &::glCompileShader;
glDeleteShaderFn = &::glDeleteShader;
glGetShaderivFn = &::glGetShaderiv;
glGetShaderInfoLogFn = &::glGetShaderInfoLog;
glCreateProgramFn = &::glCreateProgram;
glAttachShaderFn = &::glAttachShader;
glDetachShaderFn = &::glDetachShader;
glLinkProgramFn = &::glLinkProgram;
glDeleteProgramFn = &::glDeleteProgram;
glGetProgramivFn = &::glGetProgramiv;
glGetProgramInfoLogFn = &::glGetProgramInfoLog;
glUseProgramFn = &::glUseProgram;
glGetAttribLocationFn = &::glGetAttribLocation;
glBindAttribLocationFn = &::glBindAttribLocation;
glEnableVertexAttributeFn = &::glEnableVertexAttribArray;
glVertexAttributePointerFn = &::glVertexAttribPointer;
glGetUniformLocationFn = &::glGetUniformLocation;
glGetActiveUniformFn = &::glGetActiveUniform;
glUniform1iFn = &::glUniform1i;
glUniform2iFn = &::glUniform2i;
glUniform3iFn = &::glUniform3i;
glUniform4iFn = &::glUniform4i;
glUniform1ivFn = &::glUniform1iv;
glUniform1fFn = &::glUniform1f;
glUniform2fFn = &::glUniform2f;
glUniform3fFn = &::glUniform3f;
glUniform4fFn = &::glUniform4f;
glUniform1fvFn = &::glUniform1fv;
glUniformMatrix4fvFn = &glUniformMatrix4fv;
}
bool GLFunctions::glHasExtension(string const & name)
{
char const* extensions = reinterpret_cast<char const * >(glGetString(GL_EXTENSIONS));
char const * extName = name.c_str();
char const * ptr = NULL;
while ((ptr = strstr(extensions, extName)) != NULL)
{
char const * end = ptr + strlen(extName);
if (isspace(*end) || *end == '\0')
return true;
extensions = end;
}
return false;
}
void GLFunctions::glClearColor(float r, float g, float b, float a)
{
ASSERT(glClearColorFn != NULL, ());
GLCHECK(glClearColorFn(r, g, b, a));
}
void GLFunctions::glClear()
{
ASSERT(glClearFn != NULL, ());
GLCHECK(glClearFn(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
}
void GLFunctions::glClearDepth()
{
ASSERT(glClearFn != NULL, ());
GLCHECK(glClearFn(GL_DEPTH_BUFFER_BIT));
}
void GLFunctions::glViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
{
ASSERT(glViewportFn != NULL, ());
GLCHECK(glViewportFn(x, y, w, h));
}
void GLFunctions::glFlush()
{
ASSERT(glFlushFn != NULL, ());
GLCHECK(glFlushFn());
}
void GLFunctions::glPixelStore(glConst name, uint32_t value)
{
GLCHECK(::glPixelStorei(name, value));
}
int32_t GLFunctions::glGetInteger(glConst pname)
{
GLint value;
GLCHECK(::glGetIntegerv(pname, &value));
return (int32_t)value;
}
void GLFunctions::glEnable(glConst mode)
{
GLCHECK(::glEnable(mode));
}
void GLFunctions::glDisable(glConst mode)
{
GLCHECK(::glDisable(mode));
}
void GLFunctions::glClearDepthValue(double depth)
{
#ifdef OMIM_OS_IPHONE
GLCHECK(::glClearDepthf(static_cast<GLclampf>(depth)));
#else
GLCHECK(::glClearDepth(depth));
#endif
}
void GLFunctions::glDepthMask(bool needWriteToDepthBuffer)
{
GLCHECK(::glDepthMask(convert(needWriteToDepthBuffer)));
}
void GLFunctions::glDepthFunc(glConst depthFunc)
{
GLCHECK(::glDepthFunc(depthFunc));
}
void GLFunctions::glBlendEquation(glConst function)
{
GLCHECK(::glBlendEquation(function));
}
void GLFunctions::glBlendFunc(glConst srcFactor, glConst dstFactor)
{
GLCHECK(::glBlendFunc(srcFactor, dstFactor));
}
void GLFunctions::glBindFramebuffer(glConst target, uint32_t id)
{
ASSERT(glBindFramebufferFn != NULL, ());
GLCHECK(glBindFramebufferFn(target, id));
}
uint32_t GLFunctions::glGenVertexArray()
{
ASSERT(glGenVertexArraysFn != NULL, ());
GLuint result = 0;
GLCHECK(glGenVertexArraysFn(1, &result));
return result;
}
void GLFunctions::glBindVertexArray(uint32_t vao)
{
ASSERT(glBindVertexArrayFn != NULL, ());
GLCHECK(glBindVertexArrayFn(vao));
}
void GLFunctions::glDeleteVertexArray(uint32_t vao)
{
ASSERT(glDeleteVertexArrayFn != NULL, ());
GLCHECK(glDeleteVertexArrayFn(1, &vao));
}
uint32_t GLFunctions::glGenBuffer()
{
ASSERT(glGenBuffersFn != NULL, ());
GLuint result = (GLuint)-1;
GLCHECK(glGenBuffersFn(1, &result));
return result;
}
void GLFunctions::glBindBuffer(uint32_t vbo, uint32_t target)
{
ASSERT(glBindBufferFn != NULL, ());
#ifdef DEBUG
threads::MutexGuard guard(g_mutex);
g_boundBuffers[make_pair(threads::GetCurrentThreadID(), target)] = vbo;
#endif
GLCHECK(glBindBufferFn(target, vbo));
}
void GLFunctions::glDeleteBuffer(uint32_t vbo)
{
ASSERT(glDeleteBuffersFn != NULL, ());
#ifdef DEBUG
threads::MutexGuard guard(g_mutex);
for (TNode const & n : g_boundBuffers)
ASSERT(n.second != vbo, ());
#endif
GLCHECK(glDeleteBuffersFn(1, &vbo));
}
void GLFunctions::glBufferData(glConst target, uint32_t size, void const * data, glConst usage)
{
ASSERT(glBufferDataFn != NULL, ());
GLCHECK(glBufferDataFn(target, size, data, usage));
}
void GLFunctions::glBufferSubData(glConst target, uint32_t size, void const * data, uint32_t offset)
{
ASSERT(glBufferSubDataFn != NULL, ());
GLCHECK(glBufferSubDataFn(target, offset, size, data));
}
void * GLFunctions::glMapBuffer(glConst target)
{
ASSERT(glMapBufferFn != NULL, ());
void * result = glMapBufferFn(target, gl_const::GLWriteOnly);
GLCHECKCALL();
return result;
}
void GLFunctions::glUnmapBuffer(glConst target)
{
ASSERT(glUnmapBufferFn != NULL, ());
VERIFY(glUnmapBufferFn(target) == GL_TRUE, ());
GLCHECKCALL();
}
uint32_t GLFunctions::glCreateShader(glConst type)
{
ASSERT(glCreateShaderFn != NULL, ());
GLuint result = glCreateShaderFn(type);
GLCHECKCALL();
return result;
}
void GLFunctions::glShaderSource(uint32_t shaderID, string const & src)
{
ASSERT(glShaderSourceFn != NULL, ());
GLchar const * source = src.c_str();
GLint length = src.size();
GLCHECK(glShaderSourceFn(shaderID, 1, &source, &length));
}
bool GLFunctions::glCompileShader(uint32_t shaderID, string &errorLog)
{
ASSERT(glCompileShaderFn != NULL, ());
ASSERT(glGetShaderivFn != NULL, ());
ASSERT(glGetShaderInfoLogFn != NULL, ());
GLCHECK(glCompileShaderFn(shaderID));
GLint result = GL_FALSE;
GLCHECK(glGetShaderivFn(shaderID, GLCompileStatus, &result));
if (result == GL_TRUE)
return true;
GLchar buf[1024];
GLint length = 0;
GLCHECK(glGetShaderInfoLogFn(shaderID, 1024, &length, buf));
errorLog = string(buf, length);
return false;
}
void GLFunctions::glDeleteShader(uint32_t shaderID)
{
ASSERT(glDeleteShaderFn != NULL, ());
GLCHECK(glDeleteBuffersFn(1, &shaderID));
}
uint32_t GLFunctions::glCreateProgram()
{
ASSERT(glCreateProgramFn != NULL, ());
GLuint result = glCreateProgramFn();
GLCHECKCALL();
return result;
}
void GLFunctions::glAttachShader(uint32_t programID, uint32_t shaderID)
{
ASSERT(glAttachShaderFn != NULL, ());
GLCHECK(glAttachShaderFn(programID, shaderID));
}
void GLFunctions::glDetachShader(uint32_t programID, uint32_t shaderID)
{
ASSERT(glDetachShaderFn != NULL, ());
GLCHECK(glDetachShaderFn(programID, shaderID));
}
bool GLFunctions::glLinkProgram(uint32_t programID, string & errorLog)
{
ASSERT(glLinkProgramFn != NULL, ());
ASSERT(glGetProgramivFn != NULL, ());
ASSERT(glGetProgramInfoLogFn != NULL, ());
GLCHECK(glLinkProgramFn(programID));
GLint result = GL_FALSE;
GLCHECK(glGetProgramivFn(programID, GLLinkStatus, &result));
if (result == GL_TRUE)
return true;
GLchar buf[1024];
GLint length = 0;
GLCHECK(glGetProgramInfoLogFn(programID, 1024, &length, buf));
errorLog = string(buf, length);
return false;
}
void GLFunctions::glDeleteProgram(uint32_t programID)
{
ASSERT(glDeleteProgramFn != NULL, ());
GLCHECK(glDeleteProgramFn(programID));
}
void GLFunctions::glUseProgram(uint32_t programID)
{
ASSERT(glUseProgramFn != NULL, ());
GLCHECK(glUseProgramFn(programID));
}
int8_t GLFunctions::glGetAttribLocation(uint32_t programID, string const & name)
{
ASSERT(glGetAttribLocationFn != NULL, ());
int result = glGetAttribLocationFn(programID, name.c_str());
GLCHECKCALL();
ASSERT(result != -1, ());
return result;
}
void GLFunctions::glBindAttribLocation(uint32_t programID, uint8_t index, string const & name)
{
ASSERT(glBindAttribLocationFn != NULL, ());
GLCHECK(glBindAttribLocationFn(programID, index, name.c_str()));
}
void GLFunctions::glEnableVertexAttribute(int attributeLocation)
{
ASSERT(glEnableVertexAttributeFn != NULL, ());
GLCHECK(glEnableVertexAttributeFn(attributeLocation));
}
void GLFunctions::glVertexAttributePointer(int attrLocation,
uint32_t count,
glConst type,
bool needNormalize,
uint32_t stride,
uint32_t offset)
{
ASSERT(glVertexAttributePointerFn != NULL, ());
GLCHECK(glVertexAttributePointerFn(attrLocation,
count,
type,
convert(needNormalize),
stride,
reinterpret_cast<void *>(offset)));
}
void GLFunctions::glGetActiveUniform(uint32_t programID, uint32_t uniformIndex,
int32_t * uniformSize, glConst * type, string & name)
{
ASSERT(glGetActiveUniformFn != NULL, ());
char buff[256];
GLCHECK(glGetActiveUniformFn(programID, uniformIndex, 256, NULL, uniformSize, type, buff));
name = buff;
}
int8_t GLFunctions::glGetUniformLocation(uint32_t programID, string const & name)
{
ASSERT(glGetUniformLocationFn != NULL, ());
int result = glGetUniformLocationFn(programID, name.c_str());
GLCHECKCALL();
ASSERT(result != -1, ());
return result;
}
void GLFunctions::glUniformValuei(int8_t location, int32_t v)
{
ASSERT(glUniform1iFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform1iFn(location, v));
}
void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2)
{
ASSERT(glUniform2iFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform2iFn(location, v1, v2));
}
void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3)
{
ASSERT(glUniform3iFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform3iFn(location, v1, v2, v3));
}
void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3, int32_t v4)
{
ASSERT(glUniform4iFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform4iFn(location, v1, v2, v3, v4));
}
void GLFunctions::glUniformValueiv(int8_t location, int32_t * v, uint32_t size)
{
ASSERT(glUniform1ivFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform1ivFn(location, size, v));
}
void GLFunctions::glUniformValuef(int8_t location, float v)
{
ASSERT(glUniform1fFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform1fFn(location, v));
}
void GLFunctions::glUniformValuef(int8_t location, float v1, float v2)
{
ASSERT(glUniform2fFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform2fFn(location, v1, v2));
}
void GLFunctions::glUniformValuef(int8_t location, float v1, float v2, float v3)
{
ASSERT(glUniform3fFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform3fFn(location, v1, v2, v3));
}
void GLFunctions::glUniformValuef(int8_t location, float v1, float v2, float v3, float v4)
{
ASSERT(glUniform4fFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform4fFn(location, v1, v2, v3, v4));
}
void GLFunctions::glUniformValuefv(int8_t location, float * v, uint32_t size)
{
ASSERT(glUniform1fvFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniform1fvFn(location, size, v));
}
void GLFunctions::glUniformMatrix4x4Value(int8_t location, float const * values)
{
ASSERT(glUniformMatrix4fvFn != NULL, ());
ASSERT(location != -1, ());
GLCHECK(glUniformMatrix4fvFn(location, 1, GL_FALSE, values));
}
uint32_t GLFunctions::glGetCurrentProgram()
{
GLint programIndex = 0;
GLCHECK(glGetIntegerv(GL_CURRENT_PROGRAM, &programIndex));
return programIndex;
}
int32_t GLFunctions::glGetProgramiv(uint32_t program, glConst paramName)
{
ASSERT(glGetProgramivFn != NULL, ());
GLint paramValue = 0;
GLCHECK(glGetProgramivFn(program, paramName, ¶mValue));
return paramValue;
}
void GLFunctions::glActiveTexture(glConst texBlock)
{
GLCHECK(::glActiveTexture(texBlock));
}
uint32_t GLFunctions::glGenTexture()
{
GLuint result = 0;
GLCHECK(::glGenTextures(1, &result));
return result;
}
void GLFunctions::glDeleteTexture(uint32_t id)
{
GLCHECK(::glDeleteTextures(1, &id));
}
void GLFunctions::glBindTexture(uint32_t textureID)
{
GLCHECK(::glBindTexture(GL_TEXTURE_2D, textureID));
}
void GLFunctions::glTexImage2D(int width, int height, glConst layout, glConst pixelType, void const * data)
{
GLCHECK(::glTexImage2D(GL_TEXTURE_2D, 0, layout, width, height, 0, layout, pixelType, data));
}
void GLFunctions::glTexSubImage2D(int x, int y, int width, int height, glConst layout, glConst pixelType, void const * data)
{
GLCHECK(::glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, layout, pixelType, data));
}
void GLFunctions::glTexParameter(glConst param, glConst value)
{
GLCHECK(::glTexParameteri(GL_TEXTURE_2D, param, value));
}
void GLFunctions::glDrawElements(uint16_t indexCount)
{
GLCHECK(::glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, 0));
}
void CheckGLError()
{
GLenum result = glGetError();
while (result != GL_NO_ERROR)
{
LOG(LERROR, ("GLError:", result));
result = glGetError();
}
}
|