• 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 GLint
94 _mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
95                                        const struct gl_program *prog);
96 
97 static inline GLuint
_mesa_program_enum_to_shader_stage(GLenum v)98 _mesa_program_enum_to_shader_stage(GLenum v)
99 {
100    switch (v) {
101    case GL_VERTEX_PROGRAM_ARB:
102       return MESA_SHADER_VERTEX;
103    case GL_FRAGMENT_PROGRAM_ARB:
104       return MESA_SHADER_FRAGMENT;
105    case GL_FRAGMENT_SHADER_ATI:
106       return MESA_SHADER_FRAGMENT;
107    case GL_GEOMETRY_PROGRAM_NV:
108       return MESA_SHADER_GEOMETRY;
109    case GL_TESS_CONTROL_PROGRAM_NV:
110       return MESA_SHADER_TESS_CTRL;
111    case GL_TESS_EVALUATION_PROGRAM_NV:
112       return MESA_SHADER_TESS_EVAL;
113    case GL_COMPUTE_PROGRAM_NV:
114       return MESA_SHADER_COMPUTE;
115    default:
116       assert(0);
117       return ~0;
118    }
119 }
120 
121 
122 static inline GLenum
_mesa_shader_stage_to_program(unsigned stage)123 _mesa_shader_stage_to_program(unsigned stage)
124 {
125    switch (stage) {
126    case MESA_SHADER_VERTEX:
127       return GL_VERTEX_PROGRAM_ARB;
128    case MESA_SHADER_FRAGMENT:
129       return GL_FRAGMENT_PROGRAM_ARB;
130    case MESA_SHADER_GEOMETRY:
131       return GL_GEOMETRY_PROGRAM_NV;
132    case MESA_SHADER_TESS_CTRL:
133       return GL_TESS_CONTROL_PROGRAM_NV;
134    case MESA_SHADER_TESS_EVAL:
135       return GL_TESS_EVALUATION_PROGRAM_NV;
136    case MESA_SHADER_COMPUTE:
137       return GL_COMPUTE_PROGRAM_NV;
138    }
139 
140    assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
141    return GL_VERTEX_PROGRAM_ARB;
142 }
143 
144 
145 GLbitfield
146 gl_external_samplers(const struct gl_program *prog);
147 
148 void
149 _mesa_add_separate_state_parameters(struct gl_program *prog,
150                                     struct gl_program_parameter_list *state_params);
151 
152 #ifdef __cplusplus
153 } /* extern "C" */
154 #endif
155 
156 #endif /* PROGRAM_H */
157