a2670fda32a586c32f79a9e1dfd9c377c4e72aea
2 * Mesa 3-D graphics library
5 * Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * These are basically just wrappers/adaptors for calling the
33 * ctx->Driver.foobar() GLSL-related functions.
35 * Things are biased toward the OpenGL 2.0 functions rather than the
36 * ARB extensions (i.e. the ARB functions are layered on the 2.0 functions).
38 * The general idea here is to allow enough modularity such that a
39 * completely different GLSL implemenation can be plugged in and co-exist
40 * with Mesa's native GLSL code.
46 _mesa_AttachObjectARB(GLhandleARB program
, GLhandleARB shader
)
48 GET_CURRENT_CONTEXT(ctx
);
49 ctx
->Driver
.AttachShader(ctx
, program
, shader
);
54 _mesa_AttachShader(GLuint program
, GLuint shader
)
56 GET_CURRENT_CONTEXT(ctx
);
57 ctx
->Driver
.AttachShader(ctx
, program
, shader
);
62 _mesa_BindAttribLocationARB(GLhandleARB program
, GLuint index
,
63 const GLcharARB
*name
)
65 GET_CURRENT_CONTEXT(ctx
);
66 ctx
->Driver
.BindAttribLocation(ctx
, program
, index
, name
);
71 _mesa_CompileShaderARB(GLhandleARB shaderObj
)
73 GET_CURRENT_CONTEXT(ctx
);
74 ctx
->Driver
.CompileShader(ctx
, shaderObj
);
79 _mesa_CreateShader(GLenum type
)
81 GET_CURRENT_CONTEXT(ctx
);
82 return ctx
->Driver
.CreateShader(ctx
, type
);
86 GLhandleARB GLAPIENTRY
87 _mesa_CreateShaderObjectARB(GLenum type
)
89 GET_CURRENT_CONTEXT(ctx
);
90 return ctx
->Driver
.CreateShader(ctx
, type
);
95 _mesa_CreateProgram(void)
97 GET_CURRENT_CONTEXT(ctx
);
98 return ctx
->Driver
.CreateProgram(ctx
);
102 GLhandleARB GLAPIENTRY
103 _mesa_CreateProgramObjectARB(void)
105 GET_CURRENT_CONTEXT(ctx
);
106 return ctx
->Driver
.CreateProgram(ctx
);
111 _mesa_DeleteObjectARB(GLhandleARB obj
)
114 GET_CURRENT_CONTEXT(ctx
);
115 if (ctx
->Driver
.IsProgram(ctx
, obj
)) {
116 ctx
->Driver
.DeleteProgram2(ctx
, obj
);
118 else if (ctx
->Driver
.IsShader(ctx
, obj
)) {
119 ctx
->Driver
.DeleteShader(ctx
, obj
);
129 _mesa_DeleteProgram(GLuint name
)
131 printf("%s name=%u\n", __FUNCTION__
, name
);
133 GET_CURRENT_CONTEXT(ctx
);
134 ctx
->Driver
.DeleteProgram2(ctx
, name
);
140 _mesa_DeleteShader(GLuint name
)
143 GET_CURRENT_CONTEXT(ctx
);
144 ctx
->Driver
.DeleteShader(ctx
, name
);
150 _mesa_DetachObjectARB(GLhandleARB program
, GLhandleARB shader
)
152 GET_CURRENT_CONTEXT(ctx
);
153 ctx
->Driver
.DetachShader(ctx
, program
, shader
);
158 _mesa_DetachShader(GLuint program
, GLuint shader
)
160 GET_CURRENT_CONTEXT(ctx
);
161 ctx
->Driver
.DetachShader(ctx
, program
, shader
);
166 _mesa_GetActiveAttribARB(GLhandleARB program
, GLuint index
,
167 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
168 GLenum
* type
, GLcharARB
* name
)
170 GET_CURRENT_CONTEXT(ctx
);
171 ctx
->Driver
.GetActiveAttrib(ctx
, program
, index
, maxLength
, length
, size
,
177 _mesa_GetActiveUniformARB(GLhandleARB program
, GLuint index
,
178 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
179 GLenum
* type
, GLcharARB
* name
)
181 GET_CURRENT_CONTEXT(ctx
);
182 ctx
->Driver
.GetActiveUniform(ctx
, program
, index
, maxLength
, length
, size
,
188 _mesa_GetAttachedObjectsARB(GLhandleARB container
, GLsizei maxCount
,
189 GLsizei
* count
, GLhandleARB
* obj
)
191 GET_CURRENT_CONTEXT(ctx
);
192 ctx
->Driver
.GetAttachedShaders(ctx
, container
, maxCount
, count
, obj
);
197 _mesa_GetAttachedShaders(GLuint program
, GLsizei maxCount
,
198 GLsizei
*count
, GLuint
*obj
)
200 GET_CURRENT_CONTEXT(ctx
);
201 ctx
->Driver
.GetAttachedShaders(ctx
, program
, maxCount
, count
, obj
);
206 _mesa_GetAttribLocationARB(GLhandleARB program
, const GLcharARB
* name
)
208 GET_CURRENT_CONTEXT(ctx
);
209 return ctx
->Driver
.GetAttribLocation(ctx
, program
, name
);
214 _mesa_GetInfoLogARB(GLhandleARB object
, GLsizei maxLength
, GLsizei
* length
,
217 GET_CURRENT_CONTEXT(ctx
);
218 /* Implement in terms of GetProgramInfoLog, GetShaderInfoLog */
219 if (ctx
->Driver
.IsProgram(ctx
, object
)) {
220 ctx
->Driver
.GetProgramInfoLog(ctx
, object
, maxLength
, length
, infoLog
);
222 else if (ctx
->Driver
.IsShader(ctx
, object
)) {
223 ctx
->Driver
.GetShaderInfoLog(ctx
, object
, maxLength
, length
, infoLog
);
226 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInfoLogARB");
232 _mesa_GetObjectParameterivARB(GLhandleARB object
, GLenum pname
, GLint
*params
)
234 GET_CURRENT_CONTEXT(ctx
);
235 /* Implement in terms of GetProgramiv, GetShaderiv */
236 if (ctx
->Driver
.IsProgram(ctx
, object
)) {
237 ctx
->Driver
.GetProgramiv(ctx
, object
, pname
, params
);
239 else if (ctx
->Driver
.IsShader(ctx
, object
)) {
240 ctx
->Driver
.GetShaderiv(ctx
, object
, pname
, params
);
243 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetObjectParameterivARB");
249 _mesa_GetObjectParameterfvARB(GLhandleARB object
, GLenum pname
,
252 GLint iparams
[1]; /* XXX is one element enough? */
253 _mesa_GetObjectParameterivARB(object
, pname
, iparams
);
254 params
[0] = (GLfloat
) iparams
[0];
259 _mesa_GetProgramiv(GLuint program
, GLenum pname
, GLint
*params
)
261 GET_CURRENT_CONTEXT(ctx
);
262 ctx
->Driver
.GetProgramiv(ctx
, program
, pname
, params
);
267 _mesa_GetShaderiv(GLuint shader
, GLenum pname
, GLint
*params
)
269 GET_CURRENT_CONTEXT(ctx
);
270 ctx
->Driver
.GetShaderiv(ctx
, shader
, pname
, params
);
275 _mesa_GetProgramInfoLog(GLuint program
, GLsizei bufSize
,
276 GLsizei
*length
, GLchar
*infoLog
)
278 GET_CURRENT_CONTEXT(ctx
);
279 ctx
->Driver
.GetProgramInfoLog(ctx
, program
, bufSize
, length
, infoLog
);
284 _mesa_GetShaderInfoLog(GLuint shader
, GLsizei bufSize
,
285 GLsizei
*length
, GLchar
*infoLog
)
287 GET_CURRENT_CONTEXT(ctx
);
288 ctx
->Driver
.GetShaderInfoLog(ctx
, shader
, bufSize
, length
, infoLog
);
293 _mesa_GetShaderSourceARB(GLhandleARB shader
, GLsizei maxLength
,
294 GLsizei
*length
, GLcharARB
*sourceOut
)
296 GET_CURRENT_CONTEXT(ctx
);
297 ctx
->Driver
.GetShaderSource(ctx
, shader
, maxLength
, length
, sourceOut
);
302 _mesa_GetUniformfvARB(GLhandleARB program
, GLint location
, GLfloat
* params
)
304 GET_CURRENT_CONTEXT(ctx
);
305 ctx
->Driver
.GetUniformfv(ctx
, program
, location
, params
);
310 _mesa_GetUniformivARB(GLhandleARB program
, GLint location
, GLint
* params
)
312 GET_CURRENT_CONTEXT(ctx
);
313 ctx
->Driver
.GetUniformiv(ctx
, program
, location
, params
);
320 _mesa_GetUniformLocation(GLuint program
, const GLcharARB
*name
)
322 GET_CURRENT_CONTEXT(ctx
);
323 return ctx
->Driver
.GetUniformLocation(ctx
, program
, name
);
328 GLhandleARB GLAPIENTRY
329 _mesa_GetHandleARB(GLenum pname
)
331 GET_CURRENT_CONTEXT(ctx
);
332 return ctx
->Driver
.GetHandle(ctx
, pname
);
337 _mesa_GetUniformLocationARB(GLhandleARB programObj
, const GLcharARB
*name
)
339 GET_CURRENT_CONTEXT(ctx
);
340 return ctx
->Driver
.GetUniformLocation(ctx
, programObj
, name
);
345 _mesa_IsProgram(GLuint name
)
347 GET_CURRENT_CONTEXT(ctx
);
348 return ctx
->Driver
.IsProgram(ctx
, name
);
353 _mesa_IsShader(GLuint name
)
355 GET_CURRENT_CONTEXT(ctx
);
356 return ctx
->Driver
.IsShader(ctx
, name
);
361 _mesa_LinkProgramARB(GLhandleARB programObj
)
363 GET_CURRENT_CONTEXT(ctx
);
364 ctx
->Driver
.LinkProgram(ctx
, programObj
);
369 * Called via glShaderSource() and glShaderSourceARB() API functions.
370 * Basically, concatenate the source code strings into one long string
371 * and pass it to ctx->Driver.ShaderSource().
374 _mesa_ShaderSourceARB(GLhandleARB shaderObj
, GLsizei count
,
375 const GLcharARB
** string
, const GLint
* length
)
377 GET_CURRENT_CONTEXT(ctx
);
379 GLsizei i
, totalLength
;
382 if (!shaderObj
|| string
== NULL
) {
383 _mesa_error(ctx
, GL_INVALID_VALUE
, "glShaderSourceARB");
388 * This array holds offsets of where the appropriate string ends, thus the
389 * last element will be set to the total length of the source code.
391 offsets
= (GLint
*) _mesa_malloc(count
* sizeof(GLint
));
392 if (offsets
== NULL
) {
393 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
397 for (i
= 0; i
< count
; i
++) {
398 if (string
[i
] == NULL
) {
399 _mesa_free((GLvoid
*) offsets
);
400 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glShaderSourceARB(null string)");
403 if (length
== NULL
|| length
[i
] < 0)
404 offsets
[i
] = _mesa_strlen(string
[i
]);
406 offsets
[i
] = length
[i
];
407 /* accumulate string lengths */
409 offsets
[i
] += offsets
[i
- 1];
412 /* Total length of source string is sum off all strings plus two.
413 * One extra byte for terminating zero, another extra byte to silence
414 * valgrind warnings in the parser/grammer code.
416 totalLength
= offsets
[count
- 1] + 2;
417 source
= (GLcharARB
*) _mesa_malloc(totalLength
* sizeof(GLcharARB
));
418 if (source
== NULL
) {
419 _mesa_free((GLvoid
*) offsets
);
420 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
424 for (i
= 0; i
< count
; i
++) {
425 GLint start
= (i
> 0) ? offsets
[i
- 1] : 0;
426 _mesa_memcpy(source
+ start
, string
[i
],
427 (offsets
[i
] - start
) * sizeof(GLcharARB
));
429 source
[totalLength
- 1] = '\0';
430 source
[totalLength
- 2] = '\0';
432 ctx
->Driver
.ShaderSource(ctx
, shaderObj
, source
);
439 _mesa_Uniform1fARB(GLint location
, GLfloat v0
)
441 GET_CURRENT_CONTEXT(ctx
);
442 ctx
->Driver
.Uniform(ctx
, location
, 1, &v0
, GL_FLOAT
);
446 _mesa_Uniform2fARB(GLint location
, GLfloat v0
, GLfloat v1
)
448 GET_CURRENT_CONTEXT(ctx
);
452 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC2
);
456 _mesa_Uniform3fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
458 GET_CURRENT_CONTEXT(ctx
);
463 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC3
);
467 _mesa_Uniform4fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
,
470 GET_CURRENT_CONTEXT(ctx
);
476 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC4
);
480 _mesa_Uniform1iARB(GLint location
, GLint v0
)
482 GET_CURRENT_CONTEXT(ctx
);
483 ctx
->Driver
.Uniform(ctx
, location
, 1, &v0
, GL_INT
);
487 _mesa_Uniform2iARB(GLint location
, GLint v0
, GLint v1
)
489 GET_CURRENT_CONTEXT(ctx
);
493 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC2
);
497 _mesa_Uniform3iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
)
499 GET_CURRENT_CONTEXT(ctx
);
504 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC3
);
508 _mesa_Uniform4iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
510 GET_CURRENT_CONTEXT(ctx
);
516 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC4
);
520 _mesa_Uniform1fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
522 GET_CURRENT_CONTEXT(ctx
);
523 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT
);
527 _mesa_Uniform2fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
529 GET_CURRENT_CONTEXT(ctx
);
530 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC2
);
534 _mesa_Uniform3fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
536 GET_CURRENT_CONTEXT(ctx
);
537 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC3
);
541 _mesa_Uniform4fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
543 GET_CURRENT_CONTEXT(ctx
);
544 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC4
);
548 _mesa_Uniform1ivARB(GLint location
, GLsizei count
, const GLint
* value
)
550 GET_CURRENT_CONTEXT(ctx
);
551 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT
);
555 _mesa_Uniform2ivARB(GLint location
, GLsizei count
, const GLint
* value
)
557 GET_CURRENT_CONTEXT(ctx
);
558 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC2
);
562 _mesa_Uniform3ivARB(GLint location
, GLsizei count
, const GLint
* value
)
564 GET_CURRENT_CONTEXT(ctx
);
565 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC3
);
569 _mesa_Uniform4ivARB(GLint location
, GLsizei count
, const GLint
* value
)
571 GET_CURRENT_CONTEXT(ctx
);
572 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC4
);
577 _mesa_UniformMatrix2fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
578 const GLfloat
* value
)
580 GET_CURRENT_CONTEXT(ctx
);
581 ctx
->Driver
.UniformMatrix(ctx
, 2, 2, GL_FLOAT_MAT2
,
582 location
, count
, transpose
, value
);
586 _mesa_UniformMatrix3fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
587 const GLfloat
* value
)
589 GET_CURRENT_CONTEXT(ctx
);
590 ctx
->Driver
.UniformMatrix(ctx
, 3, 3, GL_FLOAT_MAT3
,
591 location
, count
, transpose
, value
);
595 _mesa_UniformMatrix4fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
596 const GLfloat
* value
)
598 GET_CURRENT_CONTEXT(ctx
);
599 ctx
->Driver
.UniformMatrix(ctx
, 4, 4, GL_FLOAT_MAT4
,
600 location
, count
, transpose
, value
);
605 * Non-square UniformMatrix are OpenGL 2.1
608 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
609 const GLfloat
*value
)
611 GET_CURRENT_CONTEXT(ctx
);
612 ctx
->Driver
.UniformMatrix(ctx
, 2, 3, GL_FLOAT_MAT2x3
,
613 location
, count
, transpose
, value
);
617 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
618 const GLfloat
*value
)
620 GET_CURRENT_CONTEXT(ctx
);
621 ctx
->Driver
.UniformMatrix(ctx
, 3, 2, GL_FLOAT_MAT3x2
,
622 location
, count
, transpose
, value
);
626 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
627 const GLfloat
*value
)
629 GET_CURRENT_CONTEXT(ctx
);
630 ctx
->Driver
.UniformMatrix(ctx
, 2, 4, GL_FLOAT_MAT2x4
,
631 location
, count
, transpose
, value
);
635 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
636 const GLfloat
*value
)
638 GET_CURRENT_CONTEXT(ctx
);
639 ctx
->Driver
.UniformMatrix(ctx
, 4, 2, GL_FLOAT_MAT4x2
,
640 location
, count
, transpose
, value
);
644 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
645 const GLfloat
*value
)
647 GET_CURRENT_CONTEXT(ctx
);
648 ctx
->Driver
.UniformMatrix(ctx
, 3, 4, GL_FLOAT_MAT3x4
,
649 location
, count
, transpose
, value
);
653 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
654 const GLfloat
*value
)
656 GET_CURRENT_CONTEXT(ctx
);
657 ctx
->Driver
.UniformMatrix(ctx
, 4, 3, GL_FLOAT_MAT4x3
,
658 location
, count
, transpose
, value
);
663 _mesa_UseProgramObjectARB(GLhandleARB program
)
665 GET_CURRENT_CONTEXT(ctx
);
666 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
667 ctx
->Driver
.UseProgram(ctx
, program
);
672 _mesa_ValidateProgramARB(GLhandleARB program
)
674 GET_CURRENT_CONTEXT(ctx
);
675 ctx
->Driver
.ValidateProgram(ctx
, program
);