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
);
376 GLsizei i
, totalLength
;
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 /* Total length of source string is sum off all strings plus two.
410 * One extra byte for terminating zero, another extra byte to silence
411 * valgrind warnings in the parser/grammer code.
413 totalLength
= offsets
[count
- 1] + 2;
414 source
= (GLcharARB
*) _mesa_malloc(totalLength
* sizeof(GLcharARB
));
415 if (source
== NULL
) {
416 _mesa_free((GLvoid
*) offsets
);
417 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
421 for (i
= 0; i
< count
; i
++) {
422 GLint start
= (i
> 0) ? offsets
[i
- 1] : 0;
423 _mesa_memcpy(source
+ start
, string
[i
],
424 (offsets
[i
] - start
) * sizeof(GLcharARB
));
426 source
[totalLength
- 1] = '\0';
427 source
[totalLength
- 2] = '\0';
429 ctx
->Driver
.ShaderSource(ctx
, shaderObj
, source
);
436 _mesa_Uniform1fARB(GLint location
, GLfloat v0
)
438 GET_CURRENT_CONTEXT(ctx
);
439 ctx
->Driver
.Uniform(ctx
, location
, 1, &v0
, GL_FLOAT
);
443 _mesa_Uniform2fARB(GLint location
, GLfloat v0
, GLfloat v1
)
445 GET_CURRENT_CONTEXT(ctx
);
449 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC2
);
453 _mesa_Uniform3fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
455 GET_CURRENT_CONTEXT(ctx
);
460 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC3
);
464 _mesa_Uniform4fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
,
467 GET_CURRENT_CONTEXT(ctx
);
473 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_FLOAT_VEC4
);
477 _mesa_Uniform1iARB(GLint location
, GLint v0
)
479 GET_CURRENT_CONTEXT(ctx
);
480 ctx
->Driver
.Uniform(ctx
, location
, 1, &v0
, GL_INT
);
484 _mesa_Uniform2iARB(GLint location
, GLint v0
, GLint v1
)
486 GET_CURRENT_CONTEXT(ctx
);
490 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC2
);
494 _mesa_Uniform3iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
)
496 GET_CURRENT_CONTEXT(ctx
);
501 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC3
);
505 _mesa_Uniform4iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
507 GET_CURRENT_CONTEXT(ctx
);
513 ctx
->Driver
.Uniform(ctx
, location
, 1, v
, GL_INT_VEC4
);
517 _mesa_Uniform1fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
519 GET_CURRENT_CONTEXT(ctx
);
520 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT
);
524 _mesa_Uniform2fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
526 GET_CURRENT_CONTEXT(ctx
);
527 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC2
);
531 _mesa_Uniform3fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
533 GET_CURRENT_CONTEXT(ctx
);
534 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC3
);
538 _mesa_Uniform4fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
540 GET_CURRENT_CONTEXT(ctx
);
541 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_FLOAT_VEC4
);
545 _mesa_Uniform1ivARB(GLint location
, GLsizei count
, const GLint
* value
)
547 GET_CURRENT_CONTEXT(ctx
);
548 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT
);
552 _mesa_Uniform2ivARB(GLint location
, GLsizei count
, const GLint
* value
)
554 GET_CURRENT_CONTEXT(ctx
);
555 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC2
);
559 _mesa_Uniform3ivARB(GLint location
, GLsizei count
, const GLint
* value
)
561 GET_CURRENT_CONTEXT(ctx
);
562 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC3
);
566 _mesa_Uniform4ivARB(GLint location
, GLsizei count
, const GLint
* value
)
568 GET_CURRENT_CONTEXT(ctx
);
569 ctx
->Driver
.Uniform(ctx
, location
, count
, value
, GL_INT_VEC4
);
574 _mesa_UniformMatrix2fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
575 const GLfloat
* value
)
577 GET_CURRENT_CONTEXT(ctx
);
578 ctx
->Driver
.UniformMatrix(ctx
, 2, 2, GL_FLOAT_MAT2
,
579 location
, count
, transpose
, value
);
583 _mesa_UniformMatrix3fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
584 const GLfloat
* value
)
586 GET_CURRENT_CONTEXT(ctx
);
587 ctx
->Driver
.UniformMatrix(ctx
, 3, 3, GL_FLOAT_MAT3
,
588 location
, count
, transpose
, value
);
592 _mesa_UniformMatrix4fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
593 const GLfloat
* value
)
595 GET_CURRENT_CONTEXT(ctx
);
596 ctx
->Driver
.UniformMatrix(ctx
, 4, 4, GL_FLOAT_MAT4
,
597 location
, count
, transpose
, value
);
602 * Non-square UniformMatrix are OpenGL 2.1
605 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
606 const GLfloat
*value
)
608 GET_CURRENT_CONTEXT(ctx
);
609 ctx
->Driver
.UniformMatrix(ctx
, 2, 3, GL_FLOAT_MAT2x3
,
610 location
, count
, transpose
, value
);
614 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
615 const GLfloat
*value
)
617 GET_CURRENT_CONTEXT(ctx
);
618 ctx
->Driver
.UniformMatrix(ctx
, 3, 2, GL_FLOAT_MAT3x2
,
619 location
, count
, transpose
, value
);
623 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
624 const GLfloat
*value
)
626 GET_CURRENT_CONTEXT(ctx
);
627 ctx
->Driver
.UniformMatrix(ctx
, 2, 4, GL_FLOAT_MAT2x4
,
628 location
, count
, transpose
, value
);
632 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
633 const GLfloat
*value
)
635 GET_CURRENT_CONTEXT(ctx
);
636 ctx
->Driver
.UniformMatrix(ctx
, 4, 2, GL_FLOAT_MAT4x2
,
637 location
, count
, transpose
, value
);
641 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
642 const GLfloat
*value
)
644 GET_CURRENT_CONTEXT(ctx
);
645 ctx
->Driver
.UniformMatrix(ctx
, 3, 4, GL_FLOAT_MAT3x4
,
646 location
, count
, transpose
, value
);
650 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
651 const GLfloat
*value
)
653 GET_CURRENT_CONTEXT(ctx
);
654 ctx
->Driver
.UniformMatrix(ctx
, 4, 3, GL_FLOAT_MAT4x3
,
655 location
, count
, transpose
, value
);
660 _mesa_UseProgramObjectARB(GLhandleARB program
)
662 GET_CURRENT_CONTEXT(ctx
);
663 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
664 ctx
->Driver
.UseProgram(ctx
, program
);
669 _mesa_ValidateProgramARB(GLhandleARB program
)
671 GET_CURRENT_CONTEXT(ctx
);
672 ctx
->Driver
.ValidateProgram(ctx
, program
);