• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2007  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 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 "prog_parameter.h"
44 
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 extern struct gl_program _mesa_DummyProgram;
51 
52 
53 extern void
54 _mesa_init_program(struct gl_context *ctx);
55 
56 extern void
57 _mesa_free_program_data(struct gl_context *ctx);
58 
59 extern void
60 _mesa_update_default_objects_program(struct gl_context *ctx);
61 
62 extern void
63 _mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string);
64 
65 extern struct gl_program *
66 _mesa_init_gl_program(struct gl_program *prog, gl_shader_stage stage,
67                       GLuint id, bool is_arb_asm);
68 
69 extern struct gl_program *
70 _mesa_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
71                   bool is_arb_asm);
72 
73 extern void
74 _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
75 
76 extern struct gl_program *
77 _mesa_lookup_program(struct gl_context *ctx, GLuint id);
78 
79 extern void
80 _mesa_reference_program_(struct gl_context *ctx,
81                          struct gl_program **ptr,
82                          struct gl_program *prog);
83 
84 static inline void
_mesa_reference_program(struct gl_context * ctx,struct gl_program ** ptr,struct gl_program * prog)85 _mesa_reference_program(struct gl_context *ctx,
86                         struct gl_program **ptr,
87                         struct gl_program *prog)
88 {
89    if (*ptr != prog)
90       _mesa_reference_program_(ctx, ptr, prog);
91 }
92 
93 extern  GLboolean
94 _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
95 
96 extern  GLboolean
97 _mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count,
98                           void *mem_ctx);
99 
100 extern void
101 _mesa_find_used_registers(const struct gl_program *prog,
102                           gl_register_file file,
103                           GLboolean used[], GLuint usedSize);
104 
105 extern GLint
106 _mesa_find_free_register(const GLboolean used[],
107                          GLuint maxRegs, GLuint firstReg);
108 
109 extern GLint
110 _mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
111                                        const struct gl_program *prog);
112 
113 static inline GLuint
_mesa_program_enum_to_shader_stage(GLenum v)114 _mesa_program_enum_to_shader_stage(GLenum v)
115 {
116    switch (v) {
117    case GL_VERTEX_PROGRAM_ARB:
118       return MESA_SHADER_VERTEX;
119    case GL_FRAGMENT_PROGRAM_ARB:
120       return MESA_SHADER_FRAGMENT;
121    case GL_FRAGMENT_SHADER_ATI:
122       return MESA_SHADER_FRAGMENT;
123    case GL_GEOMETRY_PROGRAM_NV:
124       return MESA_SHADER_GEOMETRY;
125    case GL_TESS_CONTROL_PROGRAM_NV:
126       return MESA_SHADER_TESS_CTRL;
127    case GL_TESS_EVALUATION_PROGRAM_NV:
128       return MESA_SHADER_TESS_EVAL;
129    case GL_COMPUTE_PROGRAM_NV:
130       return MESA_SHADER_COMPUTE;
131    default:
132       assert(0);
133       return ~0;
134    }
135 }
136 
137 
138 static inline GLenum
_mesa_shader_stage_to_program(unsigned stage)139 _mesa_shader_stage_to_program(unsigned stage)
140 {
141    switch (stage) {
142    case MESA_SHADER_VERTEX:
143       return GL_VERTEX_PROGRAM_ARB;
144    case MESA_SHADER_FRAGMENT:
145       return GL_FRAGMENT_PROGRAM_ARB;
146    case MESA_SHADER_GEOMETRY:
147       return GL_GEOMETRY_PROGRAM_NV;
148    case MESA_SHADER_TESS_CTRL:
149       return GL_TESS_CONTROL_PROGRAM_NV;
150    case MESA_SHADER_TESS_EVAL:
151       return GL_TESS_EVALUATION_PROGRAM_NV;
152    case MESA_SHADER_COMPUTE:
153       return GL_COMPUTE_PROGRAM_NV;
154    }
155 
156    assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
157    return GL_VERTEX_PROGRAM_ARB;
158 }
159 
160 
161 GLbitfield
162 gl_external_samplers(const struct gl_program *prog);
163 
164 void
165 _mesa_add_separate_state_parameters(struct gl_program *prog,
166                                     struct gl_program_parameter_list *state_params);
167 
168 #ifdef __cplusplus
169 } /* extern "C" */
170 #endif
171 
172 #endif /* PROGRAM_H */
173