core | glapi | vbo | math | shader | swrast | swrast_setup | tnl | tnl_dd

shader_api.c File Reference


Detailed Description

Implementation of GLSL-related API functions.

Author:
Brian Paul

#include "main/glheader.h"
#include "main/context.h"
#include "main/hash.h"
#include "main/macros.h"
#include "shader/program.h"
#include "shader/prog_parameter.h"
#include "shader/prog_print.h"
#include "shader/prog_statevars.h"
#include "shader/prog_uniform.h"
#include "shader/shader_api.h"
#include "shader/slang/slang_compile.h"
#include "shader/slang/slang_link.h"
#include "glapi/dispatch.h"

Functions

static struct gl_shader_program_mesa_new_shader_program (GLcontext *ctx, GLuint name)
 XXX things to do: 1.
void _mesa_clear_shader_program_data (GLcontext *ctx, struct gl_shader_program *shProg)
 Clear (free) the shader program state that gets produced by linking.
void _mesa_free_shader_program_data (GLcontext *ctx, struct gl_shader_program *shProg)
 Free all the data that hangs off a shader program object, but not the object itself.
void _mesa_free_shader_program (GLcontext *ctx, struct gl_shader_program *shProg)
 Free/delete a shader program object.
void _mesa_reference_shader_program (GLcontext *ctx, struct gl_shader_program **ptr, struct gl_shader_program *shProg)
 Set ptr to point to shProg.
struct gl_shader_program_mesa_lookup_shader_program (GLcontext *ctx, GLuint name)
 Lookup a GLSL program object.
static struct gl_shader_program_mesa_lookup_shader_program_err (GLcontext *ctx, GLuint name, const char *caller)
 As above, but record an error if program is not found.
struct gl_shader_mesa_new_shader (GLcontext *ctx, GLuint name, GLenum type)
 Allocate a new gl_shader object, initialize it.
void _mesa_free_shader (GLcontext *ctx, struct gl_shader *sh)
void _mesa_reference_shader (GLcontext *ctx, struct gl_shader **ptr, struct gl_shader *sh)
 Set ptr to point to sh.
struct gl_shader_mesa_lookup_shader (GLcontext *ctx, GLuint name)
 Lookup a GLSL shader object.
static struct gl_shader_mesa_lookup_shader_err (GLcontext *ctx, GLuint name, const char *caller)
 As above, but record an error if shader is not found.
static GLbitfield get_shader_flags (void)
 Return mask of GLSL_x flags by examining the MESA_GLSL env var.
void _mesa_init_shader_state (GLcontext *ctx)
 Initialize context's shader state.
void _mesa_free_shader_state (GLcontext *ctx)
 Free the per-context shader-related state.
static void copy_string (GLchar *dst, GLsizei maxLength, GLsizei *length, const GLchar *src)
 Copy string from <src> to <dst>, up to maxLength characters, returning length of <dst> in <length>.
static GLboolean _mesa_is_program (GLcontext *ctx, GLuint name)
static GLboolean _mesa_is_shader (GLcontext *ctx, GLuint name)
static void _mesa_attach_shader (GLcontext *ctx, GLuint program, GLuint shader)
 Called via ctx->Driver.AttachShader().
static GLint _mesa_get_attrib_location (GLcontext *ctx, GLuint program, const GLchar *name)
static void _mesa_bind_attrib_location (GLcontext *ctx, GLuint program, GLuint index, const GLchar *name)
static GLuint _mesa_create_shader (GLcontext *ctx, GLenum type)
static GLuint _mesa_create_program (GLcontext *ctx)
static void _mesa_delete_program2 (GLcontext *ctx, GLuint name)
 Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's DeleteProgramARB.
static void _mesa_delete_shader (GLcontext *ctx, GLuint shader)
static void _mesa_detach_shader (GLcontext *ctx, GLuint program, GLuint shader)
static GLint sizeof_glsl_type (GLenum type)
static GLboolean is_boolean_type (GLenum type)
static GLboolean is_integer_type (GLenum type)
static GLboolean is_sampler_type (GLenum type)
static void _mesa_get_active_attrib (GLcontext *ctx, GLuint program, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *nameOut)
static struct
gl_program_parameter
get_uniform_parameter (const struct gl_shader_program *shProg, GLuint index)
static void _mesa_get_active_uniform (GLcontext *ctx, GLuint program, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *nameOut)
 Called via ctx->Driver.GetActiveUniform().
static void _mesa_get_attached_shaders (GLcontext *ctx, GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj)
 Called via ctx->Driver.GetAttachedShaders().
static GLuint _mesa_get_handle (GLcontext *ctx, GLenum pname)
static void _mesa_get_programiv (GLcontext *ctx, GLuint program, GLenum pname, GLint *params)
static void _mesa_get_shaderiv (GLcontext *ctx, GLuint name, GLenum pname, GLint *params)
static void _mesa_get_program_info_log (GLcontext *ctx, GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog)
static void _mesa_get_shader_info_log (GLcontext *ctx, GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog)
static void _mesa_get_shader_source (GLcontext *ctx, GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *sourceOut)
 Called via ctx->Driver.GetShaderSource().
static void get_matrix_dims (GLenum type, GLint *rows, GLint *cols)
static void get_uniform_rows_cols (const struct gl_program_parameter *p, GLint *rows, GLint *cols)
 Determine the number of rows and columns occupied by a uniform according to its datatype.
static void lookup_uniform_parameter (GLcontext *ctx, GLuint program, GLint location, struct gl_program **progOut, GLint *paramPosOut)
 Helper for get_uniform[fi]v() functions.
static void _mesa_get_uniformfv (GLcontext *ctx, GLuint program, GLint location, GLfloat *params)
 Called via ctx->Driver.GetUniformfv().
static void _mesa_get_uniformiv (GLcontext *ctx, GLuint program, GLint location, GLint *params)
 Called via ctx->Driver.GetUniformiv().
static void merge_location_offset (GLint *location, GLint offset)
 The value returned by GetUniformLocation actually encodes two things: 1.
static void split_location_offset (GLint *location, GLint *offset)
 Seperate the uniform location and parameter offset.
static GLint _mesa_get_uniform_location (GLcontext *ctx, GLuint program, const GLchar *name)
 Called via ctx->Driver.GetUniformLocation().
static void _mesa_shader_source (GLcontext *ctx, GLuint shader, const GLchar *source)
 Called via ctx->Driver.ShaderSource().
static void _mesa_compile_shader (GLcontext *ctx, GLuint shaderObj)
 Called via ctx->Driver.CompileShader().
static void _mesa_link_program (GLcontext *ctx, GLuint program)
 Called via ctx->Driver.LinkProgram().
void _mesa_use_program (GLcontext *ctx, GLuint program)
 Called via ctx->Driver.UseProgram().
void _mesa_update_shader_textures_used (struct gl_program *prog)
 Update the vertex/fragment program's TexturesUsed array.
static GLboolean compatible_types (GLenum userType, GLenum targetType)
 Check if the type given by userType is allowed to set a uniform of the target type.
static void set_program_uniform (GLcontext *ctx, struct gl_program *program, GLint index, GLint offset, GLenum type, GLsizei count, GLint elems, const void *values)
 Set the value of a program's uniform variable.
static void _mesa_uniform (GLcontext *ctx, GLint location, GLsizei count, const GLvoid *values, GLenum type)
 Called via ctx->Driver.Uniform().
static void set_program_uniform_matrix (GLcontext *ctx, struct gl_program *program, GLuint index, GLuint offset, GLuint count, GLuint rows, GLuint cols, GLboolean transpose, const GLfloat *values)
 Set a matrix-valued program parameter.
static void _mesa_uniform_matrix (GLcontext *ctx, GLint cols, GLint rows, GLint location, GLsizei count, GLboolean transpose, const GLfloat *values)
 Called by ctx->Driver.UniformMatrix().
static GLboolean validate_samplers (GLcontext *ctx, const struct gl_program *prog, char *errMsg)
 Validate a program's samplers.
GLboolean _mesa_validate_shader_program (GLcontext *ctx, const struct gl_shader_program *shProg, char *errMsg)
 Do validation of the given shader program.
static void _mesa_validate_program (GLcontext *ctx, GLuint program)
 Called via glValidateProgram().
void _mesa_init_glsl_driver_functions (struct dd_function_table *driver)
 Plug in Mesa's GLSL functions into the device driver function table.


Function Documentation

static void _mesa_attach_shader ( GLcontext ctx,
GLuint  program,
GLuint  shader 
) [static]

Called via ctx->Driver.AttachShader().

static void _mesa_bind_attrib_location ( GLcontext ctx,
GLuint  program,
GLuint  index,
const GLchar *  name 
) [static]

void _mesa_clear_shader_program_data ( GLcontext ctx,
struct gl_shader_program shProg 
)

Clear (free) the shader program state that gets produced by linking.

static void _mesa_compile_shader ( GLcontext ctx,
GLuint  shaderObj 
) [static]

Called via ctx->Driver.CompileShader().

static GLuint _mesa_create_program ( GLcontext ctx  )  [static]

static GLuint _mesa_create_shader ( GLcontext ctx,
GLenum  type 
) [static]

static void _mesa_delete_program2 ( GLcontext ctx,
GLuint  name 
) [static]

Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's DeleteProgramARB.

static void _mesa_delete_shader ( GLcontext ctx,
GLuint  shader 
) [static]

static void _mesa_detach_shader ( GLcontext ctx,
GLuint  program,
GLuint  shader 
) [static]

void _mesa_free_shader ( GLcontext ctx,
struct gl_shader sh 
)

void _mesa_free_shader_program ( GLcontext ctx,
struct gl_shader_program shProg 
)

Free/delete a shader program object.

void _mesa_free_shader_program_data ( GLcontext ctx,
struct gl_shader_program shProg 
)

Free all the data that hangs off a shader program object, but not the object itself.

void _mesa_free_shader_state ( GLcontext ctx  ) 

Free the per-context shader-related state.

static void _mesa_get_active_attrib ( GLcontext ctx,
GLuint  program,
GLuint  index,
GLsizei  maxLength,
GLsizei *  length,
GLint *  size,
GLenum *  type,
GLchar *  nameOut 
) [static]

static void _mesa_get_active_uniform ( GLcontext ctx,
GLuint  program,
GLuint  index,
GLsizei  maxLength,
GLsizei *  length,
GLint *  size,
GLenum *  type,
GLchar *  nameOut 
) [static]

Called via ctx->Driver.GetActiveUniform().

static void _mesa_get_attached_shaders ( GLcontext ctx,
GLuint  program,
GLsizei  maxCount,
GLsizei *  count,
GLuint *  obj 
) [static]

Called via ctx->Driver.GetAttachedShaders().

static GLint _mesa_get_attrib_location ( GLcontext ctx,
GLuint  program,
const GLchar *  name 
) [static]

static GLuint _mesa_get_handle ( GLcontext ctx,
GLenum  pname 
) [static]

static void _mesa_get_program_info_log ( GLcontext ctx,
GLuint  program,
GLsizei  bufSize,
GLsizei *  length,
GLchar *  infoLog 
) [static]

static void _mesa_get_programiv ( GLcontext ctx,
GLuint  program,
GLenum  pname,
GLint *  params 
) [static]

static void _mesa_get_shader_info_log ( GLcontext ctx,
GLuint  shader,
GLsizei  bufSize,
GLsizei *  length,
GLchar *  infoLog 
) [static]

static void _mesa_get_shader_source ( GLcontext ctx,
GLuint  shader,
GLsizei  maxLength,
GLsizei *  length,
GLchar *  sourceOut 
) [static]

Called via ctx->Driver.GetShaderSource().

static void _mesa_get_shaderiv ( GLcontext ctx,
GLuint  name,
GLenum  pname,
GLint *  params 
) [static]

static GLint _mesa_get_uniform_location ( GLcontext ctx,
GLuint  program,
const GLchar *  name 
) [static]

Called via ctx->Driver.GetUniformLocation().

The return value will encode two values, the uniform location and an offset (used for arrays, structs).

static void _mesa_get_uniformfv ( GLcontext ctx,
GLuint  program,
GLint  location,
GLfloat *  params 
) [static]

Called via ctx->Driver.GetUniformfv().

static void _mesa_get_uniformiv ( GLcontext ctx,
GLuint  program,
GLint  location,
GLint *  params 
) [static]

Called via ctx->Driver.GetUniformiv().

See also:
_mesa_get_uniformfv, only difference is a cast.

void _mesa_init_glsl_driver_functions ( struct dd_function_table driver  ) 

Plug in Mesa's GLSL functions into the device driver function table.

void _mesa_init_shader_state ( GLcontext ctx  ) 

Initialize context's shader state.

Internal functions.

static GLboolean _mesa_is_program ( GLcontext ctx,
GLuint  name 
) [static]

static GLboolean _mesa_is_shader ( GLcontext ctx,
GLuint  name 
) [static]

static void _mesa_link_program ( GLcontext ctx,
GLuint  program 
) [static]

Called via ctx->Driver.LinkProgram().

struct gl_shader* _mesa_lookup_shader ( GLcontext ctx,
GLuint  name 
) [read]

Lookup a GLSL shader object.

static struct gl_shader* _mesa_lookup_shader_err ( GLcontext ctx,
GLuint  name,
const char *  caller 
) [static, read]

As above, but record an error if shader is not found.

struct gl_shader_program* _mesa_lookup_shader_program ( GLcontext ctx,
GLuint  name 
) [read]

Lookup a GLSL program object.

static struct gl_shader_program* _mesa_lookup_shader_program_err ( GLcontext ctx,
GLuint  name,
const char *  caller 
) [static, read]

As above, but record an error if program is not found.

struct gl_shader* _mesa_new_shader ( GLcontext ctx,
GLuint  name,
GLenum  type 
) [read]

Allocate a new gl_shader object, initialize it.

static struct gl_shader_program* _mesa_new_shader_program ( GLcontext ctx,
GLuint  name 
) [static, read]

XXX things to do: 1.

Check that the right error code is generated for all _mesa_error() calls. 2. Insert FLUSH_VERTICES calls in various places Allocate a new gl_shader_program object, initialize it.

void _mesa_reference_shader ( GLcontext ctx,
struct gl_shader **  ptr,
struct gl_shader sh 
)

Set ptr to point to sh.

If ptr is pointing to another shader, decrement its refcount (and delete if refcount hits zero). Then set ptr to point to sh, incrementing its refcount.

void _mesa_reference_shader_program ( GLcontext ctx,
struct gl_shader_program **  ptr,
struct gl_shader_program shProg 
)

Set ptr to point to shProg.

If ptr is pointing to another object, decrement its refcount (and delete if refcount hits zero). Then set ptr to point to shProg, incrementing its refcount.

static void _mesa_shader_source ( GLcontext ctx,
GLuint  shader,
const GLchar *  source 
) [static]

Called via ctx->Driver.ShaderSource().

static void _mesa_uniform ( GLcontext ctx,
GLint  location,
GLsizei  count,
const GLvoid *  values,
GLenum  type 
) [static]

Called via ctx->Driver.Uniform().

static void _mesa_uniform_matrix ( GLcontext ctx,
GLint  cols,
GLint  rows,
GLint  location,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  values 
) [static]

Called by ctx->Driver.UniformMatrix().

Note: cols=2, rows=4 ==> array[2] of vec4

void _mesa_update_shader_textures_used ( struct gl_program prog  ) 

Update the vertex/fragment program's TexturesUsed array.

This needs to be called after glUniform(set sampler var) is called. A call to glUniform(samplerVar, value) causes a sampler to point to a particular texture unit. We know the sampler's texture target (1D/2D/3D/etc) from compile time but the sampler's texture unit is set by glUniform() calls.

So, scan the program->SamplerUnits[] and program->SamplerTargets[] information to update the prog->TexturesUsed[] values. Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX, TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc. We'll use that info for state validation before rendering.

void _mesa_use_program ( GLcontext ctx,
GLuint  program 
)

Called via ctx->Driver.UseProgram().

static void _mesa_validate_program ( GLcontext ctx,
GLuint  program 
) [static]

Called via glValidateProgram().

GLboolean _mesa_validate_shader_program ( GLcontext ctx,
const struct gl_shader_program shProg,
char *  errMsg 
)

Do validation of the given shader program.

Parameters:
errMsg returns error message if validation fails.
Returns:
GL_TRUE if valid, GL_FALSE if invalid (and set errMsg)

static GLboolean compatible_types ( GLenum  userType,
GLenum  targetType 
) [static]

Check if the type given by userType is allowed to set a uniform of the target type.

Generally, equivalence is required, but setting Boolean uniforms can be done with glUniformiv or glUniformfv.

static void copy_string ( GLchar *  dst,
GLsizei  maxLength,
GLsizei *  length,
const GLchar *  src 
) [static]

Copy string from <src> to <dst>, up to maxLength characters, returning length of <dst> in <length>.

Parameters:
src the strings source
maxLength max chars to copy
length returns number of chars copied
dst the string destination

static void get_matrix_dims ( GLenum  type,
GLint *  rows,
GLint *  cols 
) [static]

static GLbitfield get_shader_flags ( void   )  [static]

Return mask of GLSL_x flags by examining the MESA_GLSL env var.

static struct gl_program_parameter* get_uniform_parameter ( const struct gl_shader_program shProg,
GLuint  index 
) [static, read]

static void get_uniform_rows_cols ( const struct gl_program_parameter p,
GLint *  rows,
GLint *  cols 
) [static]

Determine the number of rows and columns occupied by a uniform according to its datatype.

For non-matrix types (such as GL_FLOAT_VEC4), the number of rows = 1 and cols = number of elements in the vector.

static GLboolean is_boolean_type ( GLenum  type  )  [static]

static GLboolean is_integer_type ( GLenum  type  )  [static]

static GLboolean is_sampler_type ( GLenum  type  )  [static]

static void lookup_uniform_parameter ( GLcontext ctx,
GLuint  program,
GLint  location,
struct gl_program **  progOut,
GLint *  paramPosOut 
) [static]

Helper for get_uniform[fi]v() functions.

Given a shader program name and uniform location, return a pointer to the shader program and return the program parameter position.

static void merge_location_offset ( GLint *  location,
GLint  offset 
) [static]

The value returned by GetUniformLocation actually encodes two things: 1.

the index into the prog->Uniforms[] array for the uniform 2. an offset in the prog->ParameterValues[] array for specifying array elements or structure fields. This function merges those two values.

static void set_program_uniform ( GLcontext ctx,
struct gl_program program,
GLint  index,
GLint  offset,
GLenum  type,
GLsizei  count,
GLint  elems,
const void *  values 
) [static]

Set the value of a program's uniform variable.

Parameters:
program the program whose uniform to update
index the index of the program parameter for the uniform
offset additional parameter slot offset (for arrays)
type the incoming datatype of 'values'
count the number of uniforms to set
elems number of elements per uniform (1, 2, 3 or 4)
values the new values, of datatype 'type'

static void set_program_uniform_matrix ( GLcontext ctx,
struct gl_program program,
GLuint  index,
GLuint  offset,
GLuint  count,
GLuint  rows,
GLuint  cols,
GLboolean  transpose,
const GLfloat *  values 
) [static]

Set a matrix-valued program parameter.

static GLint sizeof_glsl_type ( GLenum  type  )  [static]

static void split_location_offset ( GLint *  location,
GLint *  offset 
) [static]

Seperate the uniform location and parameter offset.

See above.

static GLboolean validate_samplers ( GLcontext ctx,
const struct gl_program prog,
char *  errMsg 
) [static]

Validate a program's samplers.

Specifically, check that there aren't two samplers of different types pointing to the same texture unit.

Returns:
GL_TRUE if valid, GL_FALSE if invalid


Generated on Sun Sep 27 06:48:02 2009 for Mesa Vertex and Fragment Program code by  doxygen 1.5.4