silence warning
[mesa.git] / src / mesa / state_tracker / st_cb_program.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * 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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33 #include "st_context.h"
34 #include "st_program.h"
35 #include "glheader.h"
36 #include "macros.h"
37 #include "enums.h"
38 #include "prog_instruction.h"
39 #include "prog_parameter.h"
40 #include "program.h"
41 #include "programopt.h"
42 #include "tnl/tnl.h"
43 #include "pipe/tgsi/mesa/tgsi_mesa.h"
44
45
46 /* Counter to track program string changes:
47 */
48 static GLuint program_id = 0;
49
50
51 static void st_bind_program( GLcontext *ctx,
52 GLenum target,
53 struct gl_program *prog )
54 {
55 struct st_context *st = st_context(ctx);
56
57 switch (target) {
58 case GL_VERTEX_PROGRAM_ARB:
59 st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
60 break;
61 case GL_FRAGMENT_PROGRAM_ARB:
62 st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
63 break;
64 }
65 }
66
67 static struct gl_program *st_new_program( GLcontext *ctx,
68 GLenum target,
69 GLuint id )
70 {
71 // struct st_context *st = st_context(ctx);
72
73 switch (target) {
74 case GL_VERTEX_PROGRAM_ARB: {
75 struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program);
76
77 prog->id = program_id++;
78 prog->dirty = 1;
79
80 return _mesa_init_vertex_program( ctx,
81 &prog->Base,
82 target,
83 id );
84 }
85
86 case GL_FRAGMENT_PROGRAM_ARB:
87 case GL_FRAGMENT_PROGRAM_NV:
88 {
89 struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program);
90
91 prog->id = program_id++;
92 prog->dirty = 1;
93
94 return _mesa_init_fragment_program( ctx,
95 &prog->Base,
96 target,
97 id );
98 }
99
100 default:
101 return _mesa_new_program(ctx, target, id);
102 }
103 }
104
105 static void st_delete_program( GLcontext *ctx,
106 struct gl_program *prog )
107 {
108 _mesa_delete_program( ctx, prog );
109 }
110
111
112 static GLboolean st_is_program_native( GLcontext *ctx,
113 GLenum target,
114 struct gl_program *prog )
115 {
116 return GL_TRUE;
117 }
118
119 static void st_program_string_notify( GLcontext *ctx,
120 GLenum target,
121 struct gl_program *prog )
122 {
123 struct st_context *st = st_context(ctx);
124
125 if (target == GL_FRAGMENT_PROGRAM_ARB) {
126 struct st_fragment_program *p = (struct st_fragment_program *)prog;
127
128 if (prog == &ctx->FragmentProgram._Current->Base)
129 st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
130
131 p->id = program_id++;
132 p->param_state = p->Base.Base.Parameters->StateFlags;
133 }
134 else if (target == GL_VERTEX_PROGRAM_ARB) {
135 struct st_vertex_program *p = (struct st_vertex_program *)prog;
136
137 if (prog == &ctx->VertexProgram._Current->Base)
138 st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
139
140 p->id = program_id++;
141 p->param_state = p->Base.Base.Parameters->StateFlags;
142
143 /* Also tell tnl about it:
144 */
145 _tnl_program_string(ctx, target, prog);
146 }
147 }
148
149
150
151 void st_init_program_functions(struct dd_function_table *functions)
152 {
153 #if 0
154 assert(functions->ProgramStringNotify == _tnl_program_string);
155 #endif
156 functions->BindProgram = st_bind_program;
157 functions->NewProgram = st_new_program;
158 functions->DeleteProgram = st_delete_program;
159 functions->IsProgramNative = st_is_program_native;
160 functions->ProgramStringNotify = st_program_string_notify;
161 }