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 const GLubyte
*
67 _mesa_find_line_column(const GLubyte
*string
, const GLubyte
*pos
,
68 GLint
*line
, GLint
*col
);
71 extern struct gl_program
*
72 _mesa_init_vertex_program(struct gl_context
*ctx
,
73 struct gl_vertex_program
*prog
,
74 GLenum target
, GLuint id
);
76 extern struct gl_program
*
77 _mesa_init_fragment_program(struct gl_context
*ctx
,
78 struct gl_fragment_program
*prog
,
79 GLenum target
, GLuint id
);
81 extern struct gl_program
*
82 _mesa_init_geometry_program(struct gl_context
*ctx
,
83 struct gl_geometry_program
*prog
,
84 GLenum target
, GLuint id
);
86 extern struct gl_program
*
87 _mesa_init_compute_program(struct gl_context
*ctx
,
88 struct gl_compute_program
*prog
,
89 GLenum target
, GLuint id
);
91 extern struct gl_program
*
92 _mesa_new_program(struct gl_context
*ctx
, GLenum target
, GLuint id
);
95 _mesa_delete_program(struct gl_context
*ctx
, struct gl_program
*prog
);
97 extern struct gl_program
*
98 _mesa_lookup_program(struct gl_context
*ctx
, GLuint id
);
101 _mesa_reference_program_(struct gl_context
*ctx
,
102 struct gl_program
**ptr
,
103 struct gl_program
*prog
);
106 _mesa_reference_program(struct gl_context
*ctx
,
107 struct gl_program
**ptr
,
108 struct gl_program
*prog
)
111 _mesa_reference_program_(ctx
, ptr
, prog
);
115 _mesa_reference_vertprog(struct gl_context
*ctx
,
116 struct gl_vertex_program
**ptr
,
117 struct gl_vertex_program
*prog
)
119 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
120 (struct gl_program
*) prog
);
124 _mesa_reference_fragprog(struct gl_context
*ctx
,
125 struct gl_fragment_program
**ptr
,
126 struct gl_fragment_program
*prog
)
128 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
129 (struct gl_program
*) prog
);
133 _mesa_reference_geomprog(struct gl_context
*ctx
,
134 struct gl_geometry_program
**ptr
,
135 struct gl_geometry_program
*prog
)
137 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
138 (struct gl_program
*) prog
);
142 _mesa_reference_compprog(struct gl_context
*ctx
,
143 struct gl_compute_program
**ptr
,
144 struct gl_compute_program
*prog
)
146 _mesa_reference_program(ctx
, (struct gl_program
**) ptr
,
147 (struct gl_program
*) prog
);
150 extern struct gl_program
*
151 _mesa_clone_program(struct gl_context
*ctx
, const struct gl_program
*prog
);
153 static inline struct gl_vertex_program
*
154 _mesa_clone_vertex_program(struct gl_context
*ctx
,
155 const struct gl_vertex_program
*prog
)
157 return (struct gl_vertex_program
*) _mesa_clone_program(ctx
, &prog
->Base
);
160 static inline struct gl_geometry_program
*
161 _mesa_clone_geometry_program(struct gl_context
*ctx
,
162 const struct gl_geometry_program
*prog
)
164 return (struct gl_geometry_program
*) _mesa_clone_program(ctx
, &prog
->Base
);
167 static inline struct gl_fragment_program
*
168 _mesa_clone_fragment_program(struct gl_context
*ctx
,
169 const struct gl_fragment_program
*prog
)
171 return (struct gl_fragment_program
*) _mesa_clone_program(ctx
, &prog
->Base
);
176 _mesa_insert_instructions(struct gl_program
*prog
, GLuint start
, GLuint count
);
179 _mesa_delete_instructions(struct gl_program
*prog
, GLuint start
, GLuint count
);
181 extern struct gl_program
*
182 _mesa_combine_programs(struct gl_context
*ctx
,
183 const struct gl_program
*progA
,
184 const struct gl_program
*progB
);
187 _mesa_find_used_registers(const struct gl_program
*prog
,
188 gl_register_file file
,
189 GLboolean used
[], GLuint usedSize
);
192 _mesa_find_free_register(const GLboolean used
[],
193 GLuint maxRegs
, GLuint firstReg
);
197 _mesa_valid_register_index(const struct gl_context
*ctx
,
198 gl_shader_stage shaderType
,
199 gl_register_file file
, GLint index
);
202 _mesa_postprocess_program(struct gl_context
*ctx
, struct gl_program
*prog
);
205 _mesa_get_min_invocations_per_fragment(struct gl_context
*ctx
,
206 const struct gl_fragment_program
*prog
,
207 bool ignore_sample_qualifier
);
210 _mesa_program_enum_to_shader_stage(GLenum v
)
213 case GL_VERTEX_PROGRAM_ARB
:
214 return MESA_SHADER_VERTEX
;
215 case GL_FRAGMENT_PROGRAM_ARB
:
216 return MESA_SHADER_FRAGMENT
;
217 case GL_GEOMETRY_PROGRAM_NV
:
218 return MESA_SHADER_GEOMETRY
;
219 case GL_COMPUTE_PROGRAM_NV
:
220 return MESA_SHADER_COMPUTE
;
229 _mesa_shader_stage_to_program(unsigned stage
)
232 case MESA_SHADER_VERTEX
:
233 return GL_VERTEX_PROGRAM_ARB
;
234 case MESA_SHADER_FRAGMENT
:
235 return GL_FRAGMENT_PROGRAM_ARB
;
236 case MESA_SHADER_GEOMETRY
:
237 return GL_GEOMETRY_PROGRAM_NV
;
238 case MESA_SHADER_COMPUTE
:
239 return GL_COMPUTE_PROGRAM_NV
;
242 assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
243 return GL_VERTEX_PROGRAM_ARB
;
247 /* Cast wrappers from gl_program to gl_vertex/geometry/fragment_program */
249 static inline struct gl_fragment_program
*
250 gl_fragment_program(struct gl_program
*prog
)
252 return (struct gl_fragment_program
*) prog
;
255 static inline const struct gl_fragment_program
*
256 gl_fragment_program_const(const struct gl_program
*prog
)
258 return (const struct gl_fragment_program
*) prog
;
262 static inline struct gl_vertex_program
*
263 gl_vertex_program(struct gl_program
*prog
)
265 return (struct gl_vertex_program
*) prog
;
268 static inline const struct gl_vertex_program
*
269 gl_vertex_program_const(const struct gl_program
*prog
)
271 return (const struct gl_vertex_program
*) prog
;
275 static inline struct gl_geometry_program
*
276 gl_geometry_program(struct gl_program
*prog
)
278 return (struct gl_geometry_program
*) prog
;
281 static inline const struct gl_geometry_program
*
282 gl_geometry_program_const(const struct gl_program
*prog
)
284 return (const struct gl_geometry_program
*) prog
;
288 static inline struct gl_compute_program
*
289 gl_compute_program(struct gl_program
*prog
)
291 return (struct gl_compute_program
*) prog
;
294 static inline const struct gl_compute_program
*
295 gl_compute_program_const(const struct gl_program
*prog
)
297 return (const struct gl_compute_program
*) prog
;
305 #endif /* PROGRAM_H */