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 "main/mtypes.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, GLenum target, GLuint id,
67                       bool is_arb_asm);
68 
69 extern struct gl_program *
70 _mesa_new_program(struct gl_context *ctx, GLenum target, 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                                        bool ignore_sample_qualifier);
113 
114 static inline GLuint
_mesa_program_enum_to_shader_stage(GLenum v)115 _mesa_program_enum_to_shader_stage(GLenum v)
116 {
117    switch (v) {
118    case GL_VERTEX_PROGRAM_ARB:
119       return MESA_SHADER_VERTEX;
120    case GL_FRAGMENT_PROGRAM_ARB:
121       return MESA_SHADER_FRAGMENT;
122    case GL_FRAGMENT_SHADER_ATI:
123       return MESA_SHADER_FRAGMENT;
124    case GL_GEOMETRY_PROGRAM_NV:
125       return MESA_SHADER_GEOMETRY;
126    case GL_TESS_CONTROL_PROGRAM_NV:
127       return MESA_SHADER_TESS_CTRL;
128    case GL_TESS_EVALUATION_PROGRAM_NV:
129       return MESA_SHADER_TESS_EVAL;
130    case GL_COMPUTE_PROGRAM_NV:
131       return MESA_SHADER_COMPUTE;
132    default:
133       assert(0);
134       return ~0;
135    }
136 }
137 
138 
139 static inline GLenum
_mesa_shader_stage_to_program(unsigned stage)140 _mesa_shader_stage_to_program(unsigned stage)
141 {
142    switch (stage) {
143    case MESA_SHADER_VERTEX:
144       return GL_VERTEX_PROGRAM_ARB;
145    case MESA_SHADER_FRAGMENT:
146       return GL_FRAGMENT_PROGRAM_ARB;
147    case MESA_SHADER_GEOMETRY:
148       return GL_GEOMETRY_PROGRAM_NV;
149    case MESA_SHADER_TESS_CTRL:
150       return GL_TESS_CONTROL_PROGRAM_NV;
151    case MESA_SHADER_TESS_EVAL:
152       return GL_TESS_EVALUATION_PROGRAM_NV;
153    case MESA_SHADER_COMPUTE:
154       return GL_COMPUTE_PROGRAM_NV;
155    }
156 
157    assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
158    return GL_VERTEX_PROGRAM_ARB;
159 }
160 
161 
162 GLbitfield
163 gl_external_samplers(const struct gl_program *prog);
164 
165 
166 #ifdef __cplusplus
167 } /* extern "C" */
168 #endif
169 
170 #endif /* PROGRAM_H */
171