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
);
431 _mesa_Uniform1fARB(GLint location
, GLfloat v0
)
433 GET_CURRENT_CONTEXT(ctx
);
434 ctx
->Driver
.Uniform(ctx
, location
, 1, &v0
, GL_FLOAT
);
438 _mesa_Uniform2fARB(GLint location
, GLfloat v0
, GLfloat v1
)
440 GET_CURRENT_CONTEXT(ctx
);
444 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC2
);
448 _mesa_Uniform3fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
450 GET_CURRENT_CONTEXT(ctx
);
455 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC3
);
459 _mesa_Uniform4fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
,
462 GET_CURRENT_CONTEXT(ctx
);
468 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC4
);
472 _mesa_Uniform1iARB(GLint location
, GLint v0
)
474 GET_CURRENT_CONTEXT(ctx
);
475 ctx
->Driver
.Uniform(ctx
, location
, 1, &v0
, GL_INT
);
479 _mesa_Uniform2iARB(GLint location
, GLint v0
, GLint v1
)
481 GET_CURRENT_CONTEXT(ctx
);
485 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC2
);
489 _mesa_Uniform3iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
)
491 GET_CURRENT_CONTEXT(ctx
);
496 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC3
);
500 _mesa_Uniform4iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
502 GET_CURRENT_CONTEXT(ctx
);
508 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC4
);
512 _mesa_Uniform1fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
514 GET_CURRENT_CONTEXT(ctx
);
515 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT
);
519 _mesa_Uniform2fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
521 GET_CURRENT_CONTEXT(ctx
);
522 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC2
);
526 _mesa_Uniform3fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
528 GET_CURRENT_CONTEXT(ctx
);
529 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC3
);
533 _mesa_Uniform4fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
535 GET_CURRENT_CONTEXT(ctx
);
536 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC4
);
540 _mesa_Uniform1ivARB(GLint location
, GLsizei count
, const GLint
* value
)
542 GET_CURRENT_CONTEXT(ctx
);
543 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT
);
547 _mesa_Uniform2ivARB(GLint location
, GLsizei count
, const GLint
* value
)
549 GET_CURRENT_CONTEXT(ctx
);
550 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC2
);
554 _mesa_Uniform3ivARB(GLint location
, GLsizei count
, const GLint
* value
)
556 GET_CURRENT_CONTEXT(ctx
);
557 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC3
);
561 _mesa_Uniform4ivARB(GLint location
, GLsizei count
, const GLint
* value
)
563 GET_CURRENT_CONTEXT(ctx
);
564 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC4
);
569 _mesa_UniformMatrix2fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
570 const GLfloat
* value
)
572 GET_CURRENT_CONTEXT(ctx
);
573 ctx
->Driver
.UniformMatrix(ctx
, 2, 2, GL_FLOAT_MAT2
,
574 location
, count
, transpose
, value
);
578 _mesa_UniformMatrix3fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
579 const GLfloat
* value
)
581 GET_CURRENT_CONTEXT(ctx
);
582 ctx
->Driver
.UniformMatrix(ctx
, 3, 3, GL_FLOAT_MAT3
,
583 location
, count
, transpose
, value
);
587 _mesa_UniformMatrix4fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
588 const GLfloat
* value
)
590 GET_CURRENT_CONTEXT(ctx
);
591 ctx
->Driver
.UniformMatrix(ctx
, 4, 4, GL_FLOAT_MAT4
,
592 location
, count
, transpose
, value
);
597 * Non-square UniformMatrix are OpenGL 2.1
600 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
601 const GLfloat
*value
)
603 GET_CURRENT_CONTEXT(ctx
);
604 ctx
->Driver
.UniformMatrix(ctx
, 2, 3, GL_FLOAT_MAT2x3
,
605 location
, count
, transpose
, value
);
609 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
610 const GLfloat
*value
)
612 GET_CURRENT_CONTEXT(ctx
);
613 ctx
->Driver
.UniformMatrix(ctx
, 3, 2, GL_FLOAT_MAT3x2
,
614 location
, count
, transpose
, value
);
618 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
619 const GLfloat
*value
)
621 GET_CURRENT_CONTEXT(ctx
);
622 ctx
->Driver
.UniformMatrix(ctx
, 2, 4, GL_FLOAT_MAT2x4
,
623 location
, count
, transpose
, value
);
627 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
628 const GLfloat
*value
)
630 GET_CURRENT_CONTEXT(ctx
);
631 ctx
->Driver
.UniformMatrix(ctx
, 4, 2, GL_FLOAT_MAT4x2
,
632 location
, count
, transpose
, value
);
636 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
637 const GLfloat
*value
)
639 GET_CURRENT_CONTEXT(ctx
);
640 ctx
->Driver
.UniformMatrix(ctx
, 3, 4, GL_FLOAT_MAT3x4
,
641 location
, count
, transpose
, value
);
645 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
646 const GLfloat
*value
)
648 GET_CURRENT_CONTEXT(ctx
);
649 ctx
->Driver
.UniformMatrix(ctx
, 4, 3, GL_FLOAT_MAT4x3
,
650 location
, count
, transpose
, value
);
655 _mesa_UseProgramObjectARB(GLhandleARB program
)
657 GET_CURRENT_CONTEXT(ctx
);
658 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
659 ctx
->Driver
.UseProgram(ctx
, program
);
664 _mesa_ValidateProgramARB(GLhandleARB program
)
666 GET_CURRENT_CONTEXT(ctx
);
667 ctx
->Driver
.ValidateProgram(ctx
, program
);