2 * Mesa 3-D graphics library
5 * Copyright (C) 2004-2007 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
);
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
);
103 _mesa_CreateProgramObjectARB(void)
105 GET_CURRENT_CONTEXT(ctx
);
106 return ctx
->Driver
.CreateProgram(ctx
);
111 _mesa_DeleteObjectARB(GLhandleARB obj
)
113 GET_CURRENT_CONTEXT(ctx
);
114 if (ctx
->Driver
.IsProgram(ctx
, obj
)) {
115 ctx
->Driver
.DeleteProgram2(ctx
, obj
);
117 else if (ctx
->Driver
.IsShader(ctx
, obj
)) {
118 ctx
->Driver
.DeleteShader(ctx
, obj
);
127 _mesa_DeleteProgram(GLuint name
)
129 GET_CURRENT_CONTEXT(ctx
);
130 ctx
->Driver
.DeleteProgram2(ctx
, name
);
135 _mesa_DeleteShader(GLuint name
)
137 GET_CURRENT_CONTEXT(ctx
);
138 ctx
->Driver
.DeleteShader(ctx
, name
);
143 _mesa_DetachObjectARB(GLhandleARB program
, GLhandleARB shader
)
145 GET_CURRENT_CONTEXT(ctx
);
146 ctx
->Driver
.DetachShader(ctx
, program
, shader
);
151 _mesa_DetachShader(GLuint program
, GLuint shader
)
153 GET_CURRENT_CONTEXT(ctx
);
154 ctx
->Driver
.DetachShader(ctx
, program
, shader
);
159 _mesa_GetActiveAttribARB(GLhandleARB program
, GLuint index
,
160 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
161 GLenum
* type
, GLcharARB
* name
)
163 GET_CURRENT_CONTEXT(ctx
);
164 ctx
->Driver
.GetActiveAttrib(ctx
, program
, index
, maxLength
, length
, size
,
170 _mesa_GetActiveUniformARB(GLhandleARB program
, GLuint index
,
171 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
172 GLenum
* type
, GLcharARB
* name
)
174 GET_CURRENT_CONTEXT(ctx
);
175 ctx
->Driver
.GetActiveUniform(ctx
, program
, index
, maxLength
, length
, size
,
181 _mesa_GetAttachedObjectsARB(GLhandleARB container
, GLsizei maxCount
,
182 GLsizei
* count
, GLhandleARB
* obj
)
184 GET_CURRENT_CONTEXT(ctx
);
185 ctx
->Driver
.GetAttachedShaders(ctx
, container
, maxCount
, count
, obj
);
190 _mesa_GetAttachedShaders(GLuint program
, GLsizei maxCount
,
191 GLsizei
*count
, GLuint
*obj
)
193 GET_CURRENT_CONTEXT(ctx
);
194 ctx
->Driver
.GetAttachedShaders(ctx
, program
, maxCount
, count
, obj
);
199 _mesa_GetAttribLocationARB(GLhandleARB program
, const GLcharARB
* name
)
201 GET_CURRENT_CONTEXT(ctx
);
202 return ctx
->Driver
.GetAttribLocation(ctx
, program
, name
);
207 _mesa_GetInfoLogARB(GLhandleARB object
, GLsizei maxLength
, GLsizei
* length
,
210 GET_CURRENT_CONTEXT(ctx
);
211 /* Implement in terms of GetProgramInfoLog, GetShaderInfoLog */
212 if (ctx
->Driver
.IsProgram(ctx
, object
)) {
213 ctx
->Driver
.GetProgramInfoLog(ctx
, object
, maxLength
, length
, infoLog
);
215 else if (ctx
->Driver
.IsShader(ctx
, object
)) {
216 ctx
->Driver
.GetShaderInfoLog(ctx
, object
, maxLength
, length
, infoLog
);
219 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInfoLogARB");
225 _mesa_GetObjectParameterivARB(GLhandleARB object
, GLenum pname
, GLint
*params
)
227 GET_CURRENT_CONTEXT(ctx
);
228 /* Implement in terms of GetProgramiv, GetShaderiv */
229 if (ctx
->Driver
.IsProgram(ctx
, object
)) {
230 ctx
->Driver
.GetProgramiv(ctx
, object
, pname
, params
);
232 else if (ctx
->Driver
.IsShader(ctx
, object
)) {
233 ctx
->Driver
.GetShaderiv(ctx
, object
, pname
, params
);
236 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetObjectParameterivARB");
242 _mesa_GetObjectParameterfvARB(GLhandleARB object
, GLenum pname
,
245 GLint iparams
[1]; /* XXX is one element enough? */
246 _mesa_GetObjectParameterivARB(object
, pname
, iparams
);
247 params
[0] = (GLfloat
) iparams
[0];
252 _mesa_GetProgramiv(GLuint program
, GLenum pname
, GLint
*params
)
254 GET_CURRENT_CONTEXT(ctx
);
255 ctx
->Driver
.GetProgramiv(ctx
, program
, pname
, params
);
260 _mesa_GetShaderiv(GLuint shader
, GLenum pname
, GLint
*params
)
262 GET_CURRENT_CONTEXT(ctx
);
263 ctx
->Driver
.GetShaderiv(ctx
, shader
, pname
, params
);
268 _mesa_GetProgramInfoLog(GLuint program
, GLsizei bufSize
,
269 GLsizei
*length
, GLchar
*infoLog
)
271 GET_CURRENT_CONTEXT(ctx
);
272 ctx
->Driver
.GetProgramInfoLog(ctx
, program
, bufSize
, length
, infoLog
);
277 _mesa_GetShaderInfoLog(GLuint shader
, GLsizei bufSize
,
278 GLsizei
*length
, GLchar
*infoLog
)
280 GET_CURRENT_CONTEXT(ctx
);
281 ctx
->Driver
.GetShaderInfoLog(ctx
, shader
, bufSize
, length
, infoLog
);
286 _mesa_GetShaderSourceARB(GLhandleARB shader
, GLsizei maxLength
,
287 GLsizei
*length
, GLcharARB
*sourceOut
)
289 GET_CURRENT_CONTEXT(ctx
);
290 ctx
->Driver
.GetShaderSource(ctx
, shader
, maxLength
, length
, sourceOut
);
295 _mesa_GetUniformfvARB(GLhandleARB program
, GLint location
, GLfloat
* params
)
297 GET_CURRENT_CONTEXT(ctx
);
298 ctx
->Driver
.GetUniformfv(ctx
, program
, location
, params
);
303 _mesa_GetUniformivARB(GLhandleARB program
, GLint location
, GLint
* params
)
305 GET_CURRENT_CONTEXT(ctx
);
306 GLfloat fparams
[16]; /* XXX is 16 enough? */
308 ctx
->Driver
.GetUniformfv(ctx
, program
, location
, fparams
);
309 for (i
= 0; i
< 16; i
++)
310 params
[i
] = (GLint
) fparams
[i
]; /* XXX correct? */
317 _mesa_GetUniformLocation(GLuint program
, const GLcharARB
*name
)
319 GET_CURRENT_CONTEXT(ctx
);
320 return ctx
->Driver
.GetUniformLocation(ctx
, program
, name
);
325 GLhandleARB GLAPIENTRY
326 _mesa_GetHandleARB(GLenum pname
)
328 GET_CURRENT_CONTEXT(ctx
);
329 return ctx
->Driver
.GetHandle(ctx
, pname
);
334 _mesa_GetUniformLocationARB(GLhandleARB programObj
, const GLcharARB
*name
)
336 GET_CURRENT_CONTEXT(ctx
);
337 return ctx
->Driver
.GetUniformLocation(ctx
, programObj
, name
);
342 _mesa_IsProgram(GLuint name
)
344 GET_CURRENT_CONTEXT(ctx
);
345 return ctx
->Driver
.IsProgram(ctx
, name
);
350 _mesa_IsShader(GLuint name
)
352 GET_CURRENT_CONTEXT(ctx
);
353 return ctx
->Driver
.IsShader(ctx
, name
);
358 _mesa_LinkProgramARB(GLhandleARB programObj
)
360 GET_CURRENT_CONTEXT(ctx
);
361 ctx
->Driver
.LinkProgram(ctx
, programObj
);
366 * Called via glShaderSource() and glShaderSourceARB() API functions.
367 * Basically, concatenate the source code strings into one long string
368 * and pass it to ctx->Driver.ShaderSource().
371 _mesa_ShaderSourceARB(GLhandleARB shaderObj
, GLsizei count
,
372 const GLcharARB
** string
, const GLint
* length
)
374 GET_CURRENT_CONTEXT(ctx
);
379 if (string
== NULL
) {
380 _mesa_error(ctx
, GL_INVALID_VALUE
, "glShaderSourceARB");
385 * This array holds offsets of where the appropriate string ends, thus the
386 * last element will be set to the total length of the source code.
388 offsets
= (GLint
*) _mesa_malloc(count
* sizeof(GLint
));
389 if (offsets
== NULL
) {
390 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
394 for (i
= 0; i
< count
; i
++) {
395 if (string
[i
] == NULL
) {
396 _mesa_free((GLvoid
*) offsets
);
397 _mesa_error(ctx
, GL_INVALID_VALUE
, "glShaderSourceARB(null string)");
400 if (length
== NULL
|| length
[i
] < 0)
401 offsets
[i
] = _mesa_strlen(string
[i
]);
403 offsets
[i
] = length
[i
];
404 /* accumulate string lengths */
406 offsets
[i
] += offsets
[i
- 1];
409 source
= (GLcharARB
*) _mesa_malloc((offsets
[count
- 1] + 1) *
411 if (source
== NULL
) {
412 _mesa_free((GLvoid
*) offsets
);
413 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
417 for (i
= 0; i
< count
; i
++) {
418 GLint start
= (i
> 0) ? offsets
[i
- 1] : 0;
419 _mesa_memcpy(source
+ start
, string
[i
],
420 (offsets
[i
] - start
) * sizeof(GLcharARB
));
422 source
[offsets
[count
- 1]] = '\0';
424 ctx
->Driver
.ShaderSource(ctx
, shaderObj
, source
);
429 _mesa_Uniform1fARB(GLint location
, GLfloat v0
)
431 GET_CURRENT_CONTEXT(ctx
);
432 ctx
->Driver
.Uniform(ctx
, location
, 1, &v0
, GL_FLOAT
);
436 _mesa_Uniform2fARB(GLint location
, GLfloat v0
, GLfloat v1
)
438 GET_CURRENT_CONTEXT(ctx
);
442 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC2
);
446 _mesa_Uniform3fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
448 GET_CURRENT_CONTEXT(ctx
);
453 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC3
);
457 _mesa_Uniform4fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
,
460 GET_CURRENT_CONTEXT(ctx
);
466 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC4
);
470 _mesa_Uniform1iARB(GLint location
, GLint v0
)
472 GET_CURRENT_CONTEXT(ctx
);
473 ctx
->Driver
.Uniform(ctx
, location
, 1, &v0
, GL_INT
);
477 _mesa_Uniform2iARB(GLint location
, GLint v0
, GLint v1
)
479 GET_CURRENT_CONTEXT(ctx
);
483 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC2
);
487 _mesa_Uniform3iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
)
489 GET_CURRENT_CONTEXT(ctx
);
494 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC3
);
498 _mesa_Uniform4iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
500 GET_CURRENT_CONTEXT(ctx
);
506 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC4
);
510 _mesa_Uniform1fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
512 GET_CURRENT_CONTEXT(ctx
);
513 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT
);
517 _mesa_Uniform2fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
519 GET_CURRENT_CONTEXT(ctx
);
520 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC2
);
524 _mesa_Uniform3fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
526 GET_CURRENT_CONTEXT(ctx
);
527 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC3
);
531 _mesa_Uniform4fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
533 GET_CURRENT_CONTEXT(ctx
);
534 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC4
);
538 _mesa_Uniform1ivARB(GLint location
, GLsizei count
, const GLint
* value
)
540 GET_CURRENT_CONTEXT(ctx
);
541 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT
);
545 _mesa_Uniform2ivARB(GLint location
, GLsizei count
, const GLint
* value
)
547 GET_CURRENT_CONTEXT(ctx
);
548 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC2
);
552 _mesa_Uniform3ivARB(GLint location
, GLsizei count
, const GLint
* value
)
554 GET_CURRENT_CONTEXT(ctx
);
555 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC3
);
559 _mesa_Uniform4ivARB(GLint location
, GLsizei count
, const GLint
* value
)
561 GET_CURRENT_CONTEXT(ctx
);
562 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC4
);
567 _mesa_UniformMatrix2fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
568 const GLfloat
* value
)
570 GET_CURRENT_CONTEXT(ctx
);
571 ctx
->Driver
.UniformMatrix(ctx
, 2, 2, GL_FLOAT_MAT2
,
572 location
, count
, transpose
, value
);
576 _mesa_UniformMatrix3fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
577 const GLfloat
* value
)
579 GET_CURRENT_CONTEXT(ctx
);
580 ctx
->Driver
.UniformMatrix(ctx
, 3, 3, GL_FLOAT_MAT3
,
581 location
, count
, transpose
, value
);
585 _mesa_UniformMatrix4fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
586 const GLfloat
* value
)
588 GET_CURRENT_CONTEXT(ctx
);
589 ctx
->Driver
.UniformMatrix(ctx
, 4, 4, GL_FLOAT_MAT4
,
590 location
, count
, transpose
, value
);
595 * Non-square UniformMatrix are OpenGL 2.1
598 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
599 const GLfloat
*value
)
601 GET_CURRENT_CONTEXT(ctx
);
602 ctx
->Driver
.UniformMatrix(ctx
, 2, 3, GL_FLOAT_MAT2x3
,
603 location
, count
, transpose
, value
);
607 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
608 const GLfloat
*value
)
610 GET_CURRENT_CONTEXT(ctx
);
611 ctx
->Driver
.UniformMatrix(ctx
, 3, 2, GL_FLOAT_MAT3x2
,
612 location
, count
, transpose
, value
);
616 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
617 const GLfloat
*value
)
619 GET_CURRENT_CONTEXT(ctx
);
620 ctx
->Driver
.UniformMatrix(ctx
, 2, 4, GL_FLOAT_MAT2x4
,
621 location
, count
, transpose
, value
);
625 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
626 const GLfloat
*value
)
628 GET_CURRENT_CONTEXT(ctx
);
629 ctx
->Driver
.UniformMatrix(ctx
, 4, 2, GL_FLOAT_MAT4x2
,
630 location
, count
, transpose
, value
);
634 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
635 const GLfloat
*value
)
637 GET_CURRENT_CONTEXT(ctx
);
638 ctx
->Driver
.UniformMatrix(ctx
, 3, 4, GL_FLOAT_MAT3x4
,
639 location
, count
, transpose
, value
);
643 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
644 const GLfloat
*value
)
646 GET_CURRENT_CONTEXT(ctx
);
647 ctx
->Driver
.UniformMatrix(ctx
, 4, 3, GL_FLOAT_MAT4x3
,
648 location
, count
, transpose
, value
);
653 _mesa_UseProgramObjectARB(GLhandleARB program
)
655 GET_CURRENT_CONTEXT(ctx
);
656 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
657 ctx
->Driver
.UseProgram(ctx
, program
);
662 _mesa_ValidateProgramARB(GLhandleARB program
)
664 GET_CURRENT_CONTEXT(ctx
);
665 ctx
->Driver
.ValidateProgram(ctx
, program
);