program.h revision 3464ebd5
13464ebd5Sriastradh/*
23464ebd5Sriastradh * Mesa 3-D graphics library
33464ebd5Sriastradh * Version:  6.5.3
43464ebd5Sriastradh *
53464ebd5Sriastradh * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
63464ebd5Sriastradh *
73464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
83464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"),
93464ebd5Sriastradh * to deal in the Software without restriction, including without limitation
103464ebd5Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
113464ebd5Sriastradh * and/or sell copies of the Software, and to permit persons to whom the
123464ebd5Sriastradh * Software is furnished to do so, subject to the following conditions:
133464ebd5Sriastradh *
143464ebd5Sriastradh * The above copyright notice and this permission notice shall be included
153464ebd5Sriastradh * in all copies or substantial portions of the Software.
163464ebd5Sriastradh *
173464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
183464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
193464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
203464ebd5Sriastradh * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
213464ebd5Sriastradh * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
223464ebd5Sriastradh * CONNECTION WITH THE SOFTWARE OR THE USE OR 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
433464ebd5Sriastradh#include "main/compiler.h"
443464ebd5Sriastradh#include "main/mtypes.h"
453464ebd5Sriastradh
463464ebd5Sriastradh
473464ebd5Sriastradhextern struct gl_program _mesa_DummyProgram;
483464ebd5Sriastradh
493464ebd5Sriastradh
503464ebd5Sriastradhextern void
513464ebd5Sriastradh_mesa_init_program(struct gl_context *ctx);
523464ebd5Sriastradh
533464ebd5Sriastradhextern void
543464ebd5Sriastradh_mesa_free_program_data(struct gl_context *ctx);
553464ebd5Sriastradh
563464ebd5Sriastradhextern void
573464ebd5Sriastradh_mesa_update_default_objects_program(struct gl_context *ctx);
583464ebd5Sriastradh
593464ebd5Sriastradhextern void
603464ebd5Sriastradh_mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string);
613464ebd5Sriastradh
623464ebd5Sriastradhextern const GLubyte *
633464ebd5Sriastradh_mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
643464ebd5Sriastradh                       GLint *line, GLint *col);
653464ebd5Sriastradh
663464ebd5Sriastradh
673464ebd5Sriastradhextern struct gl_program *
683464ebd5Sriastradh_mesa_init_vertex_program(struct gl_context *ctx,
693464ebd5Sriastradh                          struct gl_vertex_program *prog,
703464ebd5Sriastradh                          GLenum target, GLuint id);
713464ebd5Sriastradh
723464ebd5Sriastradhextern struct gl_program *
733464ebd5Sriastradh_mesa_init_fragment_program(struct gl_context *ctx,
743464ebd5Sriastradh                            struct gl_fragment_program *prog,
753464ebd5Sriastradh                            GLenum target, GLuint id);
763464ebd5Sriastradh
773464ebd5Sriastradhextern struct gl_program *
783464ebd5Sriastradh_mesa_init_geometry_program(struct gl_context *ctx,
793464ebd5Sriastradh                            struct gl_geometry_program *prog,
803464ebd5Sriastradh                            GLenum target, GLuint id);
813464ebd5Sriastradh
823464ebd5Sriastradhextern struct gl_program *
833464ebd5Sriastradh_mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id);
843464ebd5Sriastradh
853464ebd5Sriastradhextern void
863464ebd5Sriastradh_mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
873464ebd5Sriastradh
883464ebd5Sriastradhextern struct gl_program *
893464ebd5Sriastradh_mesa_lookup_program(struct gl_context *ctx, GLuint id);
903464ebd5Sriastradh
913464ebd5Sriastradhextern void
923464ebd5Sriastradh_mesa_reference_program(struct gl_context *ctx,
933464ebd5Sriastradh                        struct gl_program **ptr,
943464ebd5Sriastradh                        struct gl_program *prog);
953464ebd5Sriastradh
963464ebd5Sriastradhstatic INLINE void
973464ebd5Sriastradh_mesa_reference_vertprog(struct gl_context *ctx,
983464ebd5Sriastradh                         struct gl_vertex_program **ptr,
993464ebd5Sriastradh                         struct gl_vertex_program *prog)
1003464ebd5Sriastradh{
1013464ebd5Sriastradh   _mesa_reference_program(ctx, (struct gl_program **) ptr,
1023464ebd5Sriastradh                           (struct gl_program *) prog);
1033464ebd5Sriastradh}
1043464ebd5Sriastradh
1053464ebd5Sriastradhstatic INLINE void
1063464ebd5Sriastradh_mesa_reference_fragprog(struct gl_context *ctx,
1073464ebd5Sriastradh                         struct gl_fragment_program **ptr,
1083464ebd5Sriastradh                         struct gl_fragment_program *prog)
1093464ebd5Sriastradh{
1103464ebd5Sriastradh   _mesa_reference_program(ctx, (struct gl_program **) ptr,
1113464ebd5Sriastradh                           (struct gl_program *) prog);
1123464ebd5Sriastradh}
1133464ebd5Sriastradh
1143464ebd5Sriastradhstatic INLINE void
1153464ebd5Sriastradh_mesa_reference_geomprog(struct gl_context *ctx,
1163464ebd5Sriastradh                         struct gl_geometry_program **ptr,
1173464ebd5Sriastradh                         struct gl_geometry_program *prog)
1183464ebd5Sriastradh{
1193464ebd5Sriastradh   _mesa_reference_program(ctx, (struct gl_program **) ptr,
1203464ebd5Sriastradh                           (struct gl_program *) prog);
1213464ebd5Sriastradh}
1223464ebd5Sriastradh
1233464ebd5Sriastradhextern struct gl_program *
1243464ebd5Sriastradh_mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog);
1253464ebd5Sriastradh
1263464ebd5Sriastradhstatic INLINE struct gl_vertex_program *
1273464ebd5Sriastradh_mesa_clone_vertex_program(struct gl_context *ctx,
1283464ebd5Sriastradh                           const struct gl_vertex_program *prog)
1293464ebd5Sriastradh{
1303464ebd5Sriastradh   return (struct gl_vertex_program *) _mesa_clone_program(ctx, &prog->Base);
1313464ebd5Sriastradh}
1323464ebd5Sriastradh
1333464ebd5Sriastradhstatic INLINE struct gl_geometry_program *
1343464ebd5Sriastradh_mesa_clone_geometry_program(struct gl_context *ctx,
1353464ebd5Sriastradh                             const struct gl_geometry_program *prog)
1363464ebd5Sriastradh{
1373464ebd5Sriastradh   return (struct gl_geometry_program *) _mesa_clone_program(ctx, &prog->Base);
1383464ebd5Sriastradh}
1393464ebd5Sriastradh
1403464ebd5Sriastradhstatic INLINE struct gl_fragment_program *
1413464ebd5Sriastradh_mesa_clone_fragment_program(struct gl_context *ctx,
1423464ebd5Sriastradh                             const struct gl_fragment_program *prog)
1433464ebd5Sriastradh{
1443464ebd5Sriastradh   return (struct gl_fragment_program *) _mesa_clone_program(ctx, &prog->Base);
1453464ebd5Sriastradh}
1463464ebd5Sriastradh
1473464ebd5Sriastradh
1483464ebd5Sriastradhextern  GLboolean
1493464ebd5Sriastradh_mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
1503464ebd5Sriastradh
1513464ebd5Sriastradhextern  GLboolean
1523464ebd5Sriastradh_mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count);
1533464ebd5Sriastradh
1543464ebd5Sriastradhextern struct gl_program *
1553464ebd5Sriastradh_mesa_combine_programs(struct gl_context *ctx,
1563464ebd5Sriastradh                       const struct gl_program *progA,
1573464ebd5Sriastradh                       const struct gl_program *progB);
1583464ebd5Sriastradh
1593464ebd5Sriastradhextern void
1603464ebd5Sriastradh_mesa_find_used_registers(const struct gl_program *prog,
1613464ebd5Sriastradh                          gl_register_file file,
1623464ebd5Sriastradh                          GLboolean used[], GLuint usedSize);
1633464ebd5Sriastradh
1643464ebd5Sriastradhextern GLint
1653464ebd5Sriastradh_mesa_find_free_register(const GLboolean used[],
1663464ebd5Sriastradh                         GLuint maxRegs, GLuint firstReg);
1673464ebd5Sriastradh
1683464ebd5Sriastradh
1693464ebd5Sriastradhextern GLboolean
1703464ebd5Sriastradh_mesa_valid_register_index(const struct gl_context *ctx,
1713464ebd5Sriastradh                           gl_shader_type shaderType,
1723464ebd5Sriastradh                           gl_register_file file, GLint index);
1733464ebd5Sriastradh
1743464ebd5Sriastradhextern void
1753464ebd5Sriastradh_mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog);
1763464ebd5Sriastradh
1773464ebd5Sriastradh/* keep these in the same order as TGSI_PROCESSOR_* */
1783464ebd5Sriastradh
1793464ebd5Sriastradhstatic INLINE GLuint
1803464ebd5Sriastradh_mesa_program_target_to_index(GLenum v)
1813464ebd5Sriastradh{
1823464ebd5Sriastradh   switch(v)
1833464ebd5Sriastradh   {
1843464ebd5Sriastradh   case GL_VERTEX_PROGRAM_ARB:
1853464ebd5Sriastradh      return MESA_SHADER_VERTEX;
1863464ebd5Sriastradh   case GL_FRAGMENT_PROGRAM_ARB:
1873464ebd5Sriastradh      return MESA_SHADER_FRAGMENT;
1883464ebd5Sriastradh   case GL_GEOMETRY_PROGRAM_NV:
1893464ebd5Sriastradh      return MESA_SHADER_GEOMETRY;
1903464ebd5Sriastradh   default:
1913464ebd5Sriastradh      ASSERT(0);
1923464ebd5Sriastradh      return ~0;
1933464ebd5Sriastradh   }
1943464ebd5Sriastradh}
1953464ebd5Sriastradh
1963464ebd5Sriastradhstatic INLINE GLenum
1973464ebd5Sriastradh_mesa_program_index_to_target(GLuint i)
1983464ebd5Sriastradh{
1993464ebd5Sriastradh   GLenum enums[MESA_SHADER_TYPES] = {
2003464ebd5Sriastradh         GL_VERTEX_PROGRAM_ARB,
2013464ebd5Sriastradh         GL_FRAGMENT_PROGRAM_ARB,
2023464ebd5Sriastradh         GL_GEOMETRY_PROGRAM_NV,
2033464ebd5Sriastradh   };
2043464ebd5Sriastradh   if(i >= MESA_SHADER_TYPES)
2053464ebd5Sriastradh      return 0;
2063464ebd5Sriastradh   else
2073464ebd5Sriastradh      return enums[i];
2083464ebd5Sriastradh}
2093464ebd5Sriastradh
2103464ebd5Sriastradh#endif /* PROGRAM_H */
211