2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
27 * Vertex and fragment program support functions.
33 * \mainpage Mesa vertex and fragment program module
35 * This module or directory contains most of the code for vertex and
36 * fragment programs and shaders, including state management, parsers,
37 * and (some) software routines for executing programs
43 #include "main/compiler.h"
44 #include "main/mtypes.h"
51 extern struct gl_program _mesa_DummyProgram
;
55 _mesa_init_program(struct gl_context
*ctx
);
58 _mesa_free_program_data(struct gl_context
*ctx
);
61 _mesa_update_default_objects_program(struct gl_context
*ctx
);
64 _mesa_set_program_error(struct gl_context
*ctx
, GLint pos
, const char *string
);
66 extern struct gl_program
*
67 _mesa_init_gl_program(struct gl_program
*prog
, GLenum target
, GLuint id
);
69 extern struct gl_program
*
70 _mesa_new_program(struct gl_context
*ctx
, GLenum target
, GLuint id
);
73 _mesa_delete_program(struct gl_context
*ctx
, struct gl_program
*prog
);
75 extern struct gl_program
*
76 _mesa_lookup_program(struct gl_context
*ctx
, GLuint id
);
79 _mesa_reference_program_(struct gl_context
*ctx
,
80 struct gl_program
**ptr
,
81 struct gl_program
*prog
);
84 _mesa_reference_program(struct gl_context
*ctx
,
85 struct gl_program
**ptr
,
86 struct gl_program
*prog
)
89 _mesa_reference_program_(ctx
, ptr
, prog
);
93 _mesa_reference_vertprog(struct gl_context
*ctx
,
94 struct gl_vertex_program
**ptr
,
95 struct gl_vertex_program
*prog
)
97 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
98 (struct gl_program
*) prog
);
102 _mesa_reference_fragprog(struct gl_context
*ctx
,
103 struct gl_fragment_program
**ptr
,
104 struct gl_fragment_program
*prog
)
106 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
107 (struct gl_program
*) prog
);
111 _mesa_reference_geomprog(struct gl_context
*ctx
,
112 struct gl_geometry_program
**ptr
,
113 struct gl_geometry_program
*prog
)
115 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
116 (struct gl_program
*) prog
);
120 _mesa_reference_compprog(struct gl_context
*ctx
,
121 struct gl_compute_program
**ptr
,
122 struct gl_compute_program
*prog
)
124 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
125 (struct gl_program
*) prog
);
130 _mesa_reference_tesscprog(struct gl_context
*ctx
,
131 struct gl_tess_ctrl_program
**ptr
,
132 struct gl_tess_ctrl_program
*prog
)
134 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
135 (struct gl_program
*) prog
);
139 _mesa_reference_tesseprog(struct gl_context
*ctx
,
140 struct gl_tess_eval_program
**ptr
,
141 struct gl_tess_eval_program
*prog
)
143 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
144 (struct gl_program
*) prog
);
148 _mesa_insert_instructions(struct gl_program
*prog
, GLuint start
, GLuint count
);
151 _mesa_delete_instructions(struct gl_program
*prog
, GLuint start
, GLuint count
);
154 _mesa_find_used_registers(const struct gl_program
*prog
,
155 gl_register_file file
,
156 GLboolean used
[], GLuint usedSize
);
159 _mesa_find_free_register(const GLboolean used
[],
160 GLuint maxRegs
, GLuint firstReg
);
163 _mesa_get_min_invocations_per_fragment(struct gl_context
*ctx
,
164 const struct gl_fragment_program
*prog
,
165 bool ignore_sample_qualifier
);
168 _mesa_program_enum_to_shader_stage(GLenum v
)
171 case GL_VERTEX_PROGRAM_ARB
:
172 return MESA_SHADER_VERTEX
;
173 case GL_FRAGMENT_PROGRAM_ARB
:
174 return MESA_SHADER_FRAGMENT
;
175 case GL_GEOMETRY_PROGRAM_NV
:
176 return MESA_SHADER_GEOMETRY
;
177 case GL_TESS_CONTROL_PROGRAM_NV
:
178 return MESA_SHADER_TESS_CTRL
;
179 case GL_TESS_EVALUATION_PROGRAM_NV
:
180 return MESA_SHADER_TESS_EVAL
;
181 case GL_COMPUTE_PROGRAM_NV
:
182 return MESA_SHADER_COMPUTE
;
191 _mesa_shader_stage_to_program(unsigned stage
)
194 case MESA_SHADER_VERTEX
:
195 return GL_VERTEX_PROGRAM_ARB
;
196 case MESA_SHADER_FRAGMENT
:
197 return GL_FRAGMENT_PROGRAM_ARB
;
198 case MESA_SHADER_GEOMETRY
:
199 return GL_GEOMETRY_PROGRAM_NV
;
200 case MESA_SHADER_TESS_CTRL
:
201 return GL_TESS_CONTROL_PROGRAM_NV
;
202 case MESA_SHADER_TESS_EVAL
:
203 return GL_TESS_EVALUATION_PROGRAM_NV
;
204 case MESA_SHADER_COMPUTE
:
205 return GL_COMPUTE_PROGRAM_NV
;
208 assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
209 return GL_VERTEX_PROGRAM_ARB
;
213 /* Cast wrappers from gl_program to derived program types.
214 * (e.g. gl_vertex_program)
217 static inline struct gl_fragment_program
*
218 gl_fragment_program(struct gl_program
*prog
)
220 return (struct gl_fragment_program
*) prog
;
223 static inline const struct gl_fragment_program
*
224 gl_fragment_program_const(const struct gl_program
*prog
)
226 return (const struct gl_fragment_program
*) prog
;
230 static inline struct gl_vertex_program
*
231 gl_vertex_program(struct gl_program
*prog
)
233 return (struct gl_vertex_program
*) prog
;
236 static inline const struct gl_vertex_program
*
237 gl_vertex_program_const(const struct gl_program
*prog
)
239 return (const struct gl_vertex_program
*) prog
;
243 static inline struct gl_geometry_program
*
244 gl_geometry_program(struct gl_program
*prog
)
246 return (struct gl_geometry_program
*) prog
;
249 static inline const struct gl_geometry_program
*
250 gl_geometry_program_const(const struct gl_program
*prog
)
252 return (const struct gl_geometry_program
*) prog
;
256 static inline struct gl_compute_program
*
257 gl_compute_program(struct gl_program
*prog
)
259 return (struct gl_compute_program
*) prog
;
262 static inline const struct gl_compute_program
*
263 gl_compute_program_const(const struct gl_program
*prog
)
265 return (const struct gl_compute_program
*) prog
;
268 static inline struct gl_tess_ctrl_program
*
269 gl_tess_ctrl_program(struct gl_program
*prog
)
271 return (struct gl_tess_ctrl_program
*) prog
;
274 static inline const struct gl_tess_ctrl_program
*
275 gl_tess_ctrl_program_const(const struct gl_program
*prog
)
277 return (const struct gl_tess_ctrl_program
*) prog
;
281 static inline struct gl_tess_eval_program
*
282 gl_tess_eval_program(struct gl_program
*prog
)
284 return (struct gl_tess_eval_program
*) prog
;
287 static inline const struct gl_tess_eval_program
*
288 gl_tess_eval_program_const(const struct gl_program
*prog
)
290 return (const struct gl_tess_eval_program
*) prog
;
298 #endif /* PROGRAM_H */