• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  * Version:  6.5.3
4  *
5  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
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.
23  */
24 
25 /**
26  * \file program.c
27  * Vertex and fragment program support functions.
28  * \author Brian Paul
29  */
30 
31 
32 /**
33  * \mainpage Mesa vertex and fragment program module
34  *
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
38  */
39 
40 #ifndef PROGRAM_H
41 #define PROGRAM_H
42 
43 #include "main/compiler.h"
44 #include "main/mtypes.h"
45 
46 
47 extern struct gl_program _mesa_DummyProgram;
48 
49 
50 extern void
51 _mesa_init_program(struct gl_context *ctx);
52 
53 extern void
54 _mesa_free_program_data(struct gl_context *ctx);
55 
56 extern void
57 _mesa_update_default_objects_program(struct gl_context *ctx);
58 
59 extern void
60 _mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string);
61 
62 extern const GLubyte *
63 _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
64                        GLint *line, GLint *col);
65 
66 
67 extern struct gl_program *
68 _mesa_init_vertex_program(struct gl_context *ctx,
69                           struct gl_vertex_program *prog,
70                           GLenum target, GLuint id);
71 
72 extern struct gl_program *
73 _mesa_init_fragment_program(struct gl_context *ctx,
74                             struct gl_fragment_program *prog,
75                             GLenum target, GLuint id);
76 
77 extern struct gl_program *
78 _mesa_init_geometry_program(struct gl_context *ctx,
79                             struct gl_geometry_program *prog,
80                             GLenum target, GLuint id);
81 
82 extern struct gl_program *
83 _mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id);
84 
85 extern void
86 _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
87 
88 extern struct gl_program *
89 _mesa_lookup_program(struct gl_context *ctx, GLuint id);
90 
91 extern void
92 _mesa_reference_program_(struct gl_context *ctx,
93                          struct gl_program **ptr,
94                          struct gl_program *prog);
95 
96 static inline void
_mesa_reference_program(struct gl_context * ctx,struct gl_program ** ptr,struct gl_program * prog)97 _mesa_reference_program(struct gl_context *ctx,
98                         struct gl_program **ptr,
99                         struct gl_program *prog)
100 {
101    if (*ptr != prog)
102       _mesa_reference_program_(ctx, ptr, prog);
103 }
104 
105 static inline void
_mesa_reference_vertprog(struct gl_context * ctx,struct gl_vertex_program ** ptr,struct gl_vertex_program * prog)106 _mesa_reference_vertprog(struct gl_context *ctx,
107                          struct gl_vertex_program **ptr,
108                          struct gl_vertex_program *prog)
109 {
110    _mesa_reference_program(ctx, (struct gl_program **) ptr,
111                            (struct gl_program *) prog);
112 }
113 
114 static inline void
_mesa_reference_fragprog(struct gl_context * ctx,struct gl_fragment_program ** ptr,struct gl_fragment_program * prog)115 _mesa_reference_fragprog(struct gl_context *ctx,
116                          struct gl_fragment_program **ptr,
117                          struct gl_fragment_program *prog)
118 {
119    _mesa_reference_program(ctx, (struct gl_program **) ptr,
120                            (struct gl_program *) prog);
121 }
122 
123 static inline void
_mesa_reference_geomprog(struct gl_context * ctx,struct gl_geometry_program ** ptr,struct gl_geometry_program * prog)124 _mesa_reference_geomprog(struct gl_context *ctx,
125                          struct gl_geometry_program **ptr,
126                          struct gl_geometry_program *prog)
127 {
128    _mesa_reference_program(ctx, (struct gl_program **) ptr,
129                            (struct gl_program *) prog);
130 }
131 
132 extern struct gl_program *
133 _mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog);
134 
135 static inline struct gl_vertex_program *
_mesa_clone_vertex_program(struct gl_context * ctx,const struct gl_vertex_program * prog)136 _mesa_clone_vertex_program(struct gl_context *ctx,
137                            const struct gl_vertex_program *prog)
138 {
139    return (struct gl_vertex_program *) _mesa_clone_program(ctx, &prog->Base);
140 }
141 
142 static inline struct gl_geometry_program *
_mesa_clone_geometry_program(struct gl_context * ctx,const struct gl_geometry_program * prog)143 _mesa_clone_geometry_program(struct gl_context *ctx,
144                              const struct gl_geometry_program *prog)
145 {
146    return (struct gl_geometry_program *) _mesa_clone_program(ctx, &prog->Base);
147 }
148 
149 static inline struct gl_fragment_program *
_mesa_clone_fragment_program(struct gl_context * ctx,const struct gl_fragment_program * prog)150 _mesa_clone_fragment_program(struct gl_context *ctx,
151                              const struct gl_fragment_program *prog)
152 {
153    return (struct gl_fragment_program *) _mesa_clone_program(ctx, &prog->Base);
154 }
155 
156 
157 extern  GLboolean
158 _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
159 
160 extern  GLboolean
161 _mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count);
162 
163 extern struct gl_program *
164 _mesa_combine_programs(struct gl_context *ctx,
165                        const struct gl_program *progA,
166                        const struct gl_program *progB);
167 
168 extern void
169 _mesa_find_used_registers(const struct gl_program *prog,
170                           gl_register_file file,
171                           GLboolean used[], GLuint usedSize);
172 
173 extern GLint
174 _mesa_find_free_register(const GLboolean used[],
175                          GLuint maxRegs, GLuint firstReg);
176 
177 
178 extern GLboolean
179 _mesa_valid_register_index(const struct gl_context *ctx,
180                            gl_shader_type shaderType,
181                            gl_register_file file, GLint index);
182 
183 extern void
184 _mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog);
185 
186 
187 static inline GLuint
_mesa_program_target_to_index(GLenum v)188 _mesa_program_target_to_index(GLenum v)
189 {
190    switch (v) {
191    case GL_VERTEX_PROGRAM_ARB:
192       return MESA_SHADER_VERTEX;
193    case GL_FRAGMENT_PROGRAM_ARB:
194       return MESA_SHADER_FRAGMENT;
195    case GL_GEOMETRY_PROGRAM_NV:
196       return MESA_SHADER_GEOMETRY;
197    default:
198       ASSERT(0);
199       return ~0;
200    }
201 }
202 
203 static inline GLenum
_mesa_program_index_to_target(GLuint i)204 _mesa_program_index_to_target(GLuint i)
205 {
206    static const GLenum enums[MESA_SHADER_TYPES] = {
207       GL_VERTEX_PROGRAM_ARB,
208       GL_FRAGMENT_PROGRAM_ARB,
209       GL_GEOMETRY_PROGRAM_NV,
210    };
211    if(i >= MESA_SHADER_TYPES)
212       return 0;
213    else
214       return enums[i];
215 }
216 
217 
218 /* Cast wrappers from gl_program to gl_vertex/geometry/fragment_program */
219 
220 static inline struct gl_fragment_program *
gl_fragment_program(struct gl_program * prog)221 gl_fragment_program(struct gl_program *prog)
222 {
223    return (struct gl_fragment_program *) prog;
224 }
225 
226 static inline const struct gl_fragment_program *
gl_fragment_program_const(const struct gl_program * prog)227 gl_fragment_program_const(const struct gl_program *prog)
228 {
229    return (const struct gl_fragment_program *) prog;
230 }
231 
232 
233 static inline struct gl_vertex_program *
gl_vertex_program(struct gl_program * prog)234 gl_vertex_program(struct gl_program *prog)
235 {
236    return (struct gl_vertex_program *) prog;
237 }
238 
239 static inline const struct gl_vertex_program *
gl_vertex_program_const(const struct gl_program * prog)240 gl_vertex_program_const(const struct gl_program *prog)
241 {
242    return (const struct gl_vertex_program *) prog;
243 }
244 
245 
246 static inline struct gl_geometry_program *
gl_geometry_program(struct gl_program * prog)247 gl_geometry_program(struct gl_program *prog)
248 {
249    return (struct gl_geometry_program *) prog;
250 }
251 
252 static inline const struct gl_geometry_program *
gl_geometry_program_const(const struct gl_program * prog)253 gl_geometry_program_const(const struct gl_program *prog)
254 {
255    return (const struct gl_geometry_program *) prog;
256 }
257 
258 
259 #endif /* PROGRAM_H */
260