program.h revision 01e04c3f
13464ebd5Sriastradh/*
23464ebd5Sriastradh * Mesa 3-D graphics library
33464ebd5Sriastradh *
43464ebd5Sriastradh * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
53464ebd5Sriastradh *
63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
73464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"),
83464ebd5Sriastradh * to deal in the Software without restriction, including without limitation
93464ebd5Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
103464ebd5Sriastradh * and/or sell copies of the Software, and to permit persons to whom the
113464ebd5Sriastradh * Software is furnished to do so, subject to the following conditions:
123464ebd5Sriastradh *
133464ebd5Sriastradh * The above copyright notice and this permission notice shall be included
143464ebd5Sriastradh * in all copies or substantial portions of the Software.
153464ebd5Sriastradh *
163464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
173464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
183464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE.
233464ebd5Sriastradh */
243464ebd5Sriastradh
253464ebd5Sriastradh/**
263464ebd5Sriastradh * \file program.c
273464ebd5Sriastradh * Vertex and fragment program support functions.
283464ebd5Sriastradh * \author Brian Paul
293464ebd5Sriastradh */
303464ebd5Sriastradh
313464ebd5Sriastradh
323464ebd5Sriastradh/**
333464ebd5Sriastradh * \mainpage Mesa vertex and fragment program module
343464ebd5Sriastradh *
353464ebd5Sriastradh * This module or directory contains most of the code for vertex and
363464ebd5Sriastradh * fragment programs and shaders, including state management, parsers,
373464ebd5Sriastradh * and (some) software routines for executing programs
383464ebd5Sriastradh */
393464ebd5Sriastradh
403464ebd5Sriastradh#ifndef PROGRAM_H
413464ebd5Sriastradh#define PROGRAM_H
423464ebd5Sriastradh
4301e04c3fSmrg#include "prog_parameter.h"
443464ebd5Sriastradh
453464ebd5Sriastradh
46af69d88dSmrg#ifdef __cplusplus
47af69d88dSmrgextern "C" {
48af69d88dSmrg#endif
49af69d88dSmrg
503464ebd5Sriastradhextern struct gl_program _mesa_DummyProgram;
513464ebd5Sriastradh
523464ebd5Sriastradh
533464ebd5Sriastradhextern void
543464ebd5Sriastradh_mesa_init_program(struct gl_context *ctx);
553464ebd5Sriastradh
563464ebd5Sriastradhextern void
573464ebd5Sriastradh_mesa_free_program_data(struct gl_context *ctx);
583464ebd5Sriastradh
593464ebd5Sriastradhextern void
603464ebd5Sriastradh_mesa_update_default_objects_program(struct gl_context *ctx);
613464ebd5Sriastradh
623464ebd5Sriastradhextern void
633464ebd5Sriastradh_mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string);
643464ebd5Sriastradh
65af69d88dSmrgextern struct gl_program *
6601e04c3fSmrg_mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id,
6701e04c3fSmrg                      bool is_arb_asm);
68af69d88dSmrg
693464ebd5Sriastradhextern struct gl_program *
7001e04c3fSmrg_mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id,
7101e04c3fSmrg                  bool is_arb_asm);
723464ebd5Sriastradh
733464ebd5Sriastradhextern void
743464ebd5Sriastradh_mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
753464ebd5Sriastradh
763464ebd5Sriastradhextern struct gl_program *
773464ebd5Sriastradh_mesa_lookup_program(struct gl_context *ctx, GLuint id);
783464ebd5Sriastradh
793464ebd5Sriastradhextern void
80af69d88dSmrg_mesa_reference_program_(struct gl_context *ctx,
81af69d88dSmrg                         struct gl_program **ptr,
82af69d88dSmrg                         struct gl_program *prog);
83af69d88dSmrg
84af69d88dSmrgstatic inline void
853464ebd5Sriastradh_mesa_reference_program(struct gl_context *ctx,
863464ebd5Sriastradh                        struct gl_program **ptr,
87af69d88dSmrg                        struct gl_program *prog)
88af69d88dSmrg{
89af69d88dSmrg   if (*ptr != prog)
90af69d88dSmrg      _mesa_reference_program_(ctx, ptr, prog);
91af69d88dSmrg}
923464ebd5Sriastradh
933464ebd5Sriastradhextern  GLboolean
943464ebd5Sriastradh_mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
953464ebd5Sriastradh
963464ebd5Sriastradhextern  GLboolean
9701e04c3fSmrg_mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count,
9801e04c3fSmrg                          void *mem_ctx);
993464ebd5Sriastradh
1003464ebd5Sriastradhextern void
1013464ebd5Sriastradh_mesa_find_used_registers(const struct gl_program *prog,
1023464ebd5Sriastradh                          gl_register_file file,
1033464ebd5Sriastradh                          GLboolean used[], GLuint usedSize);
1043464ebd5Sriastradh
1053464ebd5Sriastradhextern GLint
1063464ebd5Sriastradh_mesa_find_free_register(const GLboolean used[],
1073464ebd5Sriastradh                         GLuint maxRegs, GLuint firstReg);
1083464ebd5Sriastradh
109af69d88dSmrgextern GLint
110af69d88dSmrg_mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
11101e04c3fSmrg                                       const struct gl_program *prog);
1123464ebd5Sriastradh
113af69d88dSmrgstatic inline GLuint
114af69d88dSmrg_mesa_program_enum_to_shader_stage(GLenum v)
1153464ebd5Sriastradh{
116af69d88dSmrg   switch (v) {
1173464ebd5Sriastradh   case GL_VERTEX_PROGRAM_ARB:
1183464ebd5Sriastradh      return MESA_SHADER_VERTEX;
1193464ebd5Sriastradh   case GL_FRAGMENT_PROGRAM_ARB:
1203464ebd5Sriastradh      return MESA_SHADER_FRAGMENT;
12101e04c3fSmrg   case GL_FRAGMENT_SHADER_ATI:
12201e04c3fSmrg      return MESA_SHADER_FRAGMENT;
1233464ebd5Sriastradh   case GL_GEOMETRY_PROGRAM_NV:
1243464ebd5Sriastradh      return MESA_SHADER_GEOMETRY;
12501e04c3fSmrg   case GL_TESS_CONTROL_PROGRAM_NV:
12601e04c3fSmrg      return MESA_SHADER_TESS_CTRL;
12701e04c3fSmrg   case GL_TESS_EVALUATION_PROGRAM_NV:
12801e04c3fSmrg      return MESA_SHADER_TESS_EVAL;
129af69d88dSmrg   case GL_COMPUTE_PROGRAM_NV:
130af69d88dSmrg      return MESA_SHADER_COMPUTE;
1313464ebd5Sriastradh   default:
13201e04c3fSmrg      assert(0);
1333464ebd5Sriastradh      return ~0;
1343464ebd5Sriastradh   }
1353464ebd5Sriastradh}
1363464ebd5Sriastradh
137af69d88dSmrg
138af69d88dSmrgstatic inline GLenum
139af69d88dSmrg_mesa_shader_stage_to_program(unsigned stage)
140af69d88dSmrg{
141af69d88dSmrg   switch (stage) {
142af69d88dSmrg   case MESA_SHADER_VERTEX:
143af69d88dSmrg      return GL_VERTEX_PROGRAM_ARB;
144af69d88dSmrg   case MESA_SHADER_FRAGMENT:
145af69d88dSmrg      return GL_FRAGMENT_PROGRAM_ARB;
146af69d88dSmrg   case MESA_SHADER_GEOMETRY:
147af69d88dSmrg      return GL_GEOMETRY_PROGRAM_NV;
14801e04c3fSmrg   case MESA_SHADER_TESS_CTRL:
14901e04c3fSmrg      return GL_TESS_CONTROL_PROGRAM_NV;
15001e04c3fSmrg   case MESA_SHADER_TESS_EVAL:
15101e04c3fSmrg      return GL_TESS_EVALUATION_PROGRAM_NV;
152af69d88dSmrg   case MESA_SHADER_COMPUTE:
153af69d88dSmrg      return GL_COMPUTE_PROGRAM_NV;
154af69d88dSmrg   }
155af69d88dSmrg
156af69d88dSmrg   assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
157af69d88dSmrg   return GL_VERTEX_PROGRAM_ARB;
158af69d88dSmrg}
159af69d88dSmrg
160af69d88dSmrg
16101e04c3fSmrgGLbitfield
16201e04c3fSmrggl_external_samplers(const struct gl_program *prog);
163af69d88dSmrg
164af69d88dSmrg
165af69d88dSmrg#ifdef __cplusplus
166af69d88dSmrg} /* extern "C" */
167af69d88dSmrg#endif
168af69d88dSmrg
1693464ebd5Sriastradh#endif /* PROGRAM_H */
170