1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "main/glheader.h"
34 #include "main/macros.h"
35 #include "main/enums.h"
36 #include "main/shaderapi.h"
37 #include "program/prog_instruction.h"
38 #include "program/program.h"
40 #include "cso_cache/cso_context.h"
41 #include "draw/draw_context.h"
43 #include "st_context.h"
44 #include "st_program.h"
45 #include "st_mesa_to_tgsi.h"
46 #include "st_cb_program.h"
49 static GLuint SerialNo
= 1;
53 * Called via ctx->Driver.BindProgram() to bind an ARB vertex or
56 static void st_bind_program( GLcontext
*ctx
,
58 struct gl_program
*prog
)
60 struct st_context
*st
= st_context(ctx
);
63 case GL_VERTEX_PROGRAM_ARB
:
64 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
66 case GL_FRAGMENT_PROGRAM_ARB
:
67 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
74 * Called via ctx->Driver.UseProgram() to bind a linked GLSL program
75 * (vertex shader + fragment shader).
77 static void st_use_program( GLcontext
*ctx
, struct gl_shader_program
*shProg
)
79 struct st_context
*st
= st_context(ctx
);
81 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
82 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
88 * Called via ctx->Driver.NewProgram() to allocate a new vertex or
91 static struct gl_program
*st_new_program( GLcontext
*ctx
,
96 case GL_VERTEX_PROGRAM_ARB
: {
97 struct st_vertex_program
*prog
= ST_CALLOC_STRUCT(st_vertex_program
);
99 prog
->serialNo
= SerialNo
++;
101 return _mesa_init_vertex_program( ctx
,
107 case GL_FRAGMENT_PROGRAM_ARB
:
108 case GL_FRAGMENT_PROGRAM_NV
: {
109 struct st_fragment_program
*prog
= ST_CALLOC_STRUCT(st_fragment_program
);
111 prog
->serialNo
= SerialNo
++;
113 return _mesa_init_fragment_program( ctx
,
127 st_delete_program(GLcontext
*ctx
, struct gl_program
*prog
)
129 struct st_context
*st
= st_context(ctx
);
131 switch( prog
->Target
) {
132 case GL_VERTEX_PROGRAM_ARB
:
134 struct st_vertex_program
*stvp
= (struct st_vertex_program
*) prog
;
135 st_vp_release_varients( st
, stvp
);
138 case GL_FRAGMENT_PROGRAM_ARB
:
140 struct st_fragment_program
*stfp
= (struct st_fragment_program
*) prog
;
142 if (stfp
->driver_shader
) {
143 cso_delete_fragment_shader(st
->cso_context
, stfp
->driver_shader
);
144 stfp
->driver_shader
= NULL
;
147 if (stfp
->tgsi
.tokens
) {
148 st_free_tokens(stfp
->tgsi
.tokens
);
149 stfp
->tgsi
.tokens
= NULL
;
152 if (stfp
->bitmap_program
) {
153 struct gl_program
*prg
= &stfp
->bitmap_program
->Base
.Base
;
154 _mesa_reference_program(ctx
, &prg
, NULL
);
155 stfp
->bitmap_program
= NULL
;
160 assert(0); /* problem */
163 /* delete base class */
164 _mesa_delete_program( ctx
, prog
);
168 static GLboolean
st_is_program_native( GLcontext
*ctx
,
170 struct gl_program
*prog
)
176 static GLboolean
st_program_string_notify( GLcontext
*ctx
,
178 struct gl_program
*prog
)
180 struct st_context
*st
= st_context(ctx
);
182 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
183 struct st_fragment_program
*stfp
= (struct st_fragment_program
*) prog
;
187 if (stfp
->driver_shader
) {
188 cso_delete_fragment_shader(st
->cso_context
, stfp
->driver_shader
);
189 stfp
->driver_shader
= NULL
;
192 if (stfp
->tgsi
.tokens
) {
193 st_free_tokens(stfp
->tgsi
.tokens
);
194 stfp
->tgsi
.tokens
= NULL
;
198 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
200 else if (target
== GL_VERTEX_PROGRAM_ARB
) {
201 struct st_vertex_program
*stvp
= (struct st_vertex_program
*) prog
;
205 st_vp_release_varients( st
, stvp
);
208 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
211 /* XXX check if program is legal, within limits */
217 void st_init_program_functions(struct dd_function_table
*functions
)
219 functions
->BindProgram
= st_bind_program
;
220 functions
->UseProgram
= st_use_program
;
221 functions
->NewProgram
= st_new_program
;
222 functions
->DeleteProgram
= st_delete_program
;
223 functions
->IsProgramNative
= st_is_program_native
;
224 functions
->ProgramStringNotify
= st_program_string_notify
;