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
47extern "C" {
48#endif
49
50extern struct gl_program _mesa_DummyProgram;
51
52
53extern void
54_mesa_init_program(struct gl_context *ctx);
55
56extern void
57_mesa_free_program_data(struct gl_context *ctx);
58
59extern void
60_mesa_update_default_objects_program(struct gl_context *ctx);
61
62extern void
63_mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string);
64
65extern struct gl_program *
66_mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id,
67                      bool is_arb_asm);
68
69extern struct gl_program *
70_mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id,
71                  bool is_arb_asm);
72
73extern void
74_mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
75
76extern struct gl_program *
77_mesa_lookup_program(struct gl_context *ctx, GLuint id);
78
79extern void
80_mesa_reference_program_(struct gl_context *ctx,
81                         struct gl_program **ptr,
82                         struct gl_program *prog);
83
84static inline void
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
93extern  GLboolean
94_mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
95
96extern  GLboolean
97_mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count,
98                          void *mem_ctx);
99
100extern void
101_mesa_find_used_registers(const struct gl_program *prog,
102                          gl_register_file file,
103                          GLboolean used[], GLuint usedSize);
104
105extern GLint
106_mesa_find_free_register(const GLboolean used[],
107                         GLuint maxRegs, GLuint firstReg);
108
109extern GLint
110_mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
111                                       const struct gl_program *prog);
112
113static inline GLuint
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
138static inline GLenum
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
161GLbitfield
162gl_external_samplers(const struct gl_program *prog);
163
164
165#ifdef __cplusplus
166} /* extern "C" */
167#endif
168
169#endif /* PROGRAM_H */
170