@@ -38,6 +38,8 @@ GLint u_View; // view transform in the world
3838GLint u_Projection; // projection
3939GLint u_WorldViewProj;
4040
41+ void * s_uniformFuncs[CONSTANT_TYPE_COUNT] = {};
42+
4143TextureID g_whiteTexture;
4244
4345static const GLenum glPrimitiveType[] = {
@@ -171,6 +173,22 @@ int GR_InitGL()
171173 const char * glslVersionStr = (const char *)glGetString (GL_SHADING_LANGUAGE_VERSION);
172174 Msg (" *GLSL version: %s\n " , glslVersionStr);
173175
176+ s_uniformFuncs[CONSTANT_FLOAT] = (void *)glUniform1fv;
177+ s_uniformFuncs[CONSTANT_VECTOR2D] = (void *)glUniform2fv;
178+ s_uniformFuncs[CONSTANT_VECTOR3D] = (void *)glUniform3fv;
179+ s_uniformFuncs[CONSTANT_VECTOR4D] = (void *)glUniform4fv;
180+ s_uniformFuncs[CONSTANT_INT] = (void *)glUniform1iv;
181+ s_uniformFuncs[CONSTANT_IVECTOR2D] = (void *)glUniform2iv;
182+ s_uniformFuncs[CONSTANT_IVECTOR3D] = (void *)glUniform3iv;
183+ s_uniformFuncs[CONSTANT_IVECTOR4D] = (void *)glUniform4iv;
184+ s_uniformFuncs[CONSTANT_BOOL] = (void *)glUniform1iv;
185+ s_uniformFuncs[CONSTANT_BVECTOR2D] = (void *)glUniform2iv;
186+ s_uniformFuncs[CONSTANT_BVECTOR3D] = (void *)glUniform3iv;
187+ s_uniformFuncs[CONSTANT_BVECTOR4D] = (void *)glUniform4iv;
188+ s_uniformFuncs[CONSTANT_MATRIX2x2] = (void *)glUniformMatrix2fv;
189+ s_uniformFuncs[CONSTANT_MATRIX3x3] = (void *)glUniformMatrix3fv;
190+ s_uniformFuncs[CONSTANT_MATRIX4x4] = (void *)glUniformMatrix4fv;
191+
174192 return 1 ;
175193}
176194
@@ -258,14 +276,18 @@ ShaderID GR_CompileShader(const char* source)
258276 " #define VERTEX\n "
259277 " #define varying out\n "
260278 " #define attribute in\n "
261- " #define texture2D texture\n " ;
279+ " #define texture2D texture\n "
280+ " #define saturate(x) clamp(x,0.0,1.0)\r\n "
281+ " #define lerp mix\r\n " ;
262282
263283 const char * GLSL_HEADER_FRAG =
264284 " #version 300 es\n "
265285 " precision lowp int;\n "
266286 " precision highp float;\n "
267287 " #define varying in\n "
268288 " #define texture2D texture\n "
289+ " #define saturate(x) clamp(x,0.0,1.0)\r\n "
290+ " #define lerp mix\r\n " ;
269291 " out vec4 fragColor;\n " ;
270292#else
271293 const char * GLSL_HEADER_VERT =
@@ -275,14 +297,18 @@ ShaderID GR_CompileShader(const char* source)
275297 " #define VERTEX\n "
276298 " #define varying out\n "
277299 " #define attribute in\n "
278- " #define texture2D texture\n " ;
300+ " #define texture2D texture\n "
301+ " #define saturate(x) clamp(x,0.0,1.0)\r\n "
302+ " #define lerp mix\r\n " ;
279303
280304 const char * GLSL_HEADER_FRAG =
281305 " #version 330\n "
282306 " precision lowp int;\n "
283307 " precision highp float;\n "
284308 " #define varying in\n "
285309 " #define texture2D texture\n "
310+ " #define saturate(x) clamp(x,0.0,1.0)\r\n "
311+ " #define lerp mix\r\n "
286312 " out vec4 fragColor;\n " ;
287313#endif
288314
@@ -336,6 +362,47 @@ void GR_SetShader(const ShaderID& shader)
336362 GR_GetWVPUniforms (shader);
337363}
338364
365+ typedef GLvoid (APIENTRY* UNIFORM_FUNC)(GLint location, GLsizei count, const void * value);
366+ typedef GLvoid (APIENTRY* UNIFORM_MAT_FUNC)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
367+
368+ int GR_GetShaderConstantIndex (ShaderID shaderId, char * name)
369+ {
370+ return glGetUniformLocation (shaderId, name);
371+ }
372+
373+ void GR_SetShaderConstatntvi (int index, GR_ConstantType constantType, int count, float * value)
374+ {
375+ if (constantType >= CONSTANT_MATRIX2x2)
376+ ((UNIFORM_MAT_FUNC)s_uniformFuncs[constantType])(index, count, GL_TRUE, value);
377+ else
378+ ((UNIFORM_FUNC)s_uniformFuncs[constantType])(index, count, value);
379+ }
380+
381+ void GR_SetShaderConstatntFloat (int index, float value)
382+ {
383+ GR_SetShaderConstatntvi (index, CONSTANT_FLOAT, 1 , &value);
384+ }
385+
386+ void GR_SetShaderConstatntVector3D (int index, const Vector3D& value)
387+ {
388+ GR_SetShaderConstatntvi (index, CONSTANT_VECTOR3D, 1 , (float *)&value);
389+ }
390+
391+ void GR_SetShaderConstatntVector4D (int index, const Vector4D& value)
392+ {
393+ GR_SetShaderConstatntvi (index, CONSTANT_VECTOR4D, 1 , (float *)&value);
394+ }
395+
396+ void GR_SetShaderConstatntMatrix3x3 (int index, const Matrix3x3& value)
397+ {
398+ GR_SetShaderConstatntvi (index, CONSTANT_MATRIX3x3, 1 , (float *)&value);
399+ }
400+
401+ void GR_SetShaderConstatntMatrix4x4 (int index, const Matrix4x4& value)
402+ {
403+ GR_SetShaderConstatntvi (index, CONSTANT_MATRIX4x4, 1 , (float *)&value);
404+ }
405+
339406// ----------------------------------------------------------------
340407
341408void GR_SetMatrix (GR_MatrixMode mode, const Matrix4x4& matrix)
0 commit comments