prog_parameter.h revision af69d88d
1/* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25/** 26 * \file prog_parameter.c 27 * Program parameter lists and functions. 28 * \author Brian Paul 29 */ 30 31#ifndef PROG_PARAMETER_H 32#define PROG_PARAMETER_H 33 34#include "main/mtypes.h" 35#include "prog_statevars.h" 36 37 38#ifdef __cplusplus 39extern "C" { 40#endif 41 42 43/** 44 * Actual data for constant values of parameters. 45 */ 46typedef union gl_constant_value 47{ 48 GLfloat f; 49 GLint b; 50 GLint i; 51 GLuint u; 52} gl_constant_value; 53 54 55/** 56 * Program parameter. 57 * Used by shaders/programs for uniforms, constants, varying vars, etc. 58 */ 59struct gl_program_parameter 60{ 61 const char *Name; /**< Null-terminated string */ 62 gl_register_file Type; /**< PROGRAM_CONSTANT or STATE_VAR */ 63 GLenum DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */ 64 /** 65 * Number of components (1..4), or more. 66 * If the number of components is greater than 4, 67 * this parameter is part of a larger uniform like a GLSL matrix or array. 68 * The next program parameter's Size will be Size-4 of this parameter. 69 */ 70 GLuint Size; 71 GLboolean Initialized; /**< debug: Has the ParameterValue[] been set? */ 72 /** 73 * A sequence of STATE_* tokens and integers to identify GL state. 74 */ 75 gl_state_index StateIndexes[STATE_LENGTH]; 76}; 77 78 79/** 80 * List of gl_program_parameter instances. 81 */ 82struct gl_program_parameter_list 83{ 84 GLuint Size; /**< allocated size of Parameters, ParameterValues */ 85 GLuint NumParameters; /**< number of parameters in arrays */ 86 struct gl_program_parameter *Parameters; /**< Array [Size] */ 87 gl_constant_value (*ParameterValues)[4]; /**< Array [Size] of constant[4] */ 88 GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes 89 might invalidate ParameterValues[] */ 90}; 91 92 93extern struct gl_program_parameter_list * 94_mesa_new_parameter_list(void); 95 96extern struct gl_program_parameter_list * 97_mesa_new_parameter_list_sized(unsigned size); 98 99extern void 100_mesa_free_parameter_list(struct gl_program_parameter_list *paramList); 101 102extern struct gl_program_parameter_list * 103_mesa_clone_parameter_list(const struct gl_program_parameter_list *list); 104 105extern struct gl_program_parameter_list * 106_mesa_combine_parameter_lists(const struct gl_program_parameter_list *a, 107 const struct gl_program_parameter_list *b); 108 109static inline GLuint 110_mesa_num_parameters(const struct gl_program_parameter_list *list) 111{ 112 return list ? list->NumParameters : 0; 113} 114 115extern GLint 116_mesa_add_parameter(struct gl_program_parameter_list *paramList, 117 gl_register_file type, const char *name, 118 GLuint size, GLenum datatype, 119 const gl_constant_value *values, 120 const gl_state_index state[STATE_LENGTH]); 121 122extern GLint 123_mesa_add_named_constant(struct gl_program_parameter_list *paramList, 124 const char *name, const gl_constant_value values[4], 125 GLuint size); 126 127extern GLint 128_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList, 129 const gl_constant_value values[4], GLuint size, 130 GLenum datatype, GLuint *swizzleOut); 131 132extern GLint 133_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList, 134 const gl_constant_value values[4], GLuint size, 135 GLuint *swizzleOut); 136 137extern GLint 138_mesa_add_state_reference(struct gl_program_parameter_list *paramList, 139 const gl_state_index stateTokens[STATE_LENGTH]); 140 141extern gl_constant_value * 142_mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList, 143 GLsizei nameLen, const char *name); 144 145extern GLint 146_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList, 147 GLsizei nameLen, const char *name); 148 149extern GLboolean 150_mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list, 151 const gl_constant_value v[], GLuint vSize, 152 GLint *posOut, GLuint *swizzleOut); 153 154#ifdef __cplusplus 155} 156#endif 157 158#endif /* PROG_PARAMETER_H */ 159