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
|
#pragma once
#include "drape/glconstants.hpp"
#include "base/src_point.hpp"
#include "std/string.hpp"
#include "std/thread.hpp"
class GLFunctions
{
friend class GLFunctionsCache;
public:
static void Init();
/// Attaches cache of gl-functions to specified thread. The only cache
/// is available, so invoking of this method on other thread leads to
/// disabling of current cache and enabling another
static void AttachCache(thread::id const & threadId);
static bool glHasExtension(string const & name);
static void glClearColor(float r, float g, float b, float a);
static void glClear();
static void glClearDepth();
static void glViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
static void glScissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
static void glFlush();
static void glFinish();
static void glFrontFace(glConst mode);
static void glCullFace(glConst face);
static void glPixelStore(glConst name, uint32_t value);
static int32_t glGetInteger(glConst pname);
/// target = { gl_const::GLArrayBuffer, gl_const::GLElementArrayBuffer }
/// name = { gl_const::GLBufferSize, gl_const::GLBufferUsage }
static int32_t glGetBufferParameter(glConst target, glConst name);
static string glGetString(glConst pname);
static void glEnable(glConst mode);
static void glDisable(glConst mode);
static void glClearDepthValue(double depth);
static void glDepthMask(bool needWriteToDepthBuffer);
static void glDepthFunc(glConst depthFunc);
static void glBlendEquation(glConst function);
static void glBlendFunc(glConst srcFactor, glConst dstFactor);
/// VAO support
static uint32_t glGenVertexArray();
static void glBindVertexArray(uint32_t vao);
static void glDeleteVertexArray(uint32_t vao);
/// VBO support
static uint32_t glGenBuffer();
/// target - type of buffer to bind. Look GLConst
static void glBindBuffer(uint32_t vbo, glConst target);
static void glDeleteBuffer(uint32_t vbo);
/// usage - Look GLConst
static void glBufferData(glConst target, uint32_t size, void const * data, glConst usage);
static void glBufferSubData(glConst target, uint32_t size, void const * data, uint32_t offset);
static void * glMapBuffer(glConst target, glConst access = gl_const::GLWriteOnly);
static void glUnmapBuffer(glConst target);
static void * glMapBufferRange(glConst target, uint32_t offset, uint32_t length, glConst access);
static void glFlushMappedBufferRange(glConst target, uint32_t offset, uint32_t length);
/// Shaders support
static uint32_t glCreateShader(glConst type);
static void glShaderSource(uint32_t shaderID, string const & src, string const & defines);
static bool glCompileShader(uint32_t shaderID, string & errorLog);
static void glDeleteShader(uint32_t shaderID);
static uint32_t glCreateProgram();
static void glAttachShader(uint32_t programID, uint32_t shaderID);
static void glDetachShader(uint32_t programID, uint32_t shaderID);
static bool glLinkProgram(uint32_t programID, string & errorLog);
static void glDeleteProgram(uint32_t programID);
static void glUseProgram(uint32_t programID);
static int8_t glGetAttribLocation(uint32_t programID, string const & name);
static void glBindAttribLocation(uint32_t programID, uint8_t index, string const & name);
/// enable vertex attribute binding. To get attributeLocation need to call glGetAttributeLocation
static void glEnableVertexAttribute(int32_t attributeLocation);
/// Configure vertex attribute binding.
/// attrLocation - attribute location in shader program
/// count - specify number of components with "type" for generic attribute
/// needNormalize - if "true" then OGL will map integer value on [-1 : 1] for signed of on [0 : 1] for unsigned
/// if "false" it will direct convert to float type
/// if "type" == GLFloat this parameter have no sense
/// stride - how much bytes need to seek from current attribute value to get the second value
/// offset - how much bytes need to seek from begin of currenct buffer to get first attribute value
static void glVertexAttributePointer(int32_t attrLocation,
uint32_t count,
glConst type,
bool needNormalize,
uint32_t stride,
uint32_t offset);
static void glGetActiveUniform(uint32_t programID, uint32_t uniformIndex,
int32_t * uniformSize, glConst * type, string & name);
static int8_t glGetUniformLocation(uint32_t programID, string const & name);
static void glUniformValuei(int8_t location, int32_t v);
static void glUniformValuei(int8_t location, int32_t v1, int32_t v2);
static void glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3);
static void glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3, int32_t v4);
static void glUniformValueiv(int8_t location, int32_t * v, uint32_t size);
static void glUniformValuef(int8_t location, float v);
static void glUniformValuef(int8_t location, float v1, float v2);
static void glUniformValuef(int8_t location, float v1, float v2, float v3);
static void glUniformValuef(int8_t location, float v1, float v2, float v3, float v4);
static void glUniformValuefv(int8_t location, float * v, uint32_t size);
static void glUniformMatrix4x4Value(int8_t location, float const *values);
static uint32_t glGetCurrentProgram();
static int32_t glGetProgramiv(uint32_t program, glConst paramName);
// Textures support
static void glActiveTexture(glConst texBlock);
static uint32_t glGenTexture();
static void glDeleteTexture(uint32_t id);
static void glBindTexture(uint32_t textureID);
static void glTexImage2D(int width, int height, glConst layout, glConst pixelType, void const * data);
static void glTexSubImage2D(int x, int y, int width, int height, glConst layout, glConst pixelType, void const * data);
static void glTexParameter(glConst param, glConst value);
// Draw support
static void glDrawElements(glConst primitive, uint32_t sizeOfIndex, uint32_t indexCount, uint32_t startIndex = 0);
static void glDrawArrays(glConst mode, int32_t first, uint32_t count);
// FBO support
static void glGenFramebuffer(uint32_t * fbo);
static void glDeleteFramebuffer(uint32_t * fbo);
static void glBindFramebuffer(uint32_t fbo);
static void glFramebufferTexture2D(glConst attachment, glConst texture);
static uint32_t glCheckFramebufferStatus();
};
void CheckGLError(my::SrcPoint const &src);
#ifdef DEBUG
#define GLCHECK(x) do { (x); CheckGLError(SRC()); } while (false)
#define GLCHECKCALL() do { CheckGLError(SRC()); } while (false)
#else
#define GLCHECK(x) (x)
#define GLCHECKCALL()
#endif
|