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 "st_context.h"
34 #include "st_program.h"
38 #include "prog_instruction.h"
39 #include "prog_parameter.h"
41 #include "programopt.h"
43 #include "pipe/tgsi/mesa/tgsi_mesa.h"
46 /* Counter to track program string changes:
48 static GLuint program_id
= 0;
51 static void st_bind_program( GLcontext
*ctx
,
53 struct gl_program
*prog
)
55 struct st_context
*st
= st_context(ctx
);
58 case GL_VERTEX_PROGRAM_ARB
:
59 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
61 case GL_FRAGMENT_PROGRAM_ARB
:
62 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
67 static struct gl_program
*st_new_program( GLcontext
*ctx
,
71 // struct st_context *st = st_context(ctx);
74 case GL_VERTEX_PROGRAM_ARB
: {
75 struct st_vertex_program
*prog
= CALLOC_STRUCT(st_vertex_program
);
77 prog
->id
= program_id
++;
80 #if defined(USE_X86_ASM) || defined(SLANG_X86)
81 x86_init_func( &prog
->sse2_program
);
84 return _mesa_init_vertex_program( ctx
,
90 case GL_FRAGMENT_PROGRAM_ARB
:
91 case GL_FRAGMENT_PROGRAM_NV
:
93 struct st_fragment_program
*prog
= CALLOC_STRUCT(st_fragment_program
);
95 prog
->id
= program_id
++;
98 return _mesa_init_fragment_program( ctx
,
105 return _mesa_new_program(ctx
, target
, id
);
109 static void st_delete_program( GLcontext
*ctx
,
110 struct gl_program
*prog
)
112 switch( prog
->Target
) {
113 case GL_VERTEX_PROGRAM_ARB
:
115 #if defined(USE_X86_ASM) || defined(SLANG_X86)
116 struct st_vertex_program
*p
= (struct st_vertex_program
*) prog
;
118 x86_release_func( &p
->sse2_program
);
124 _mesa_delete_program( ctx
, prog
);
128 static GLboolean
st_is_program_native( GLcontext
*ctx
,
130 struct gl_program
*prog
)
135 static void st_program_string_notify( GLcontext
*ctx
,
137 struct gl_program
*prog
)
139 struct st_context
*st
= st_context(ctx
);
141 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
142 struct st_fragment_program
*p
= (struct st_fragment_program
*)prog
;
144 if (prog
== &ctx
->FragmentProgram
._Current
->Base
)
145 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
147 p
->id
= program_id
++;
148 p
->param_state
= p
->Base
.Base
.Parameters
->StateFlags
;
150 else if (target
== GL_VERTEX_PROGRAM_ARB
) {
151 struct st_vertex_program
*p
= (struct st_vertex_program
*)prog
;
153 if (prog
== &ctx
->VertexProgram
._Current
->Base
)
154 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
156 p
->id
= program_id
++;
157 p
->param_state
= p
->Base
.Base
.Parameters
->StateFlags
;
159 /* Also tell tnl about it:
161 _tnl_program_string(ctx
, target
, prog
);
167 void st_init_program_functions(struct dd_function_table
*functions
)
170 assert(functions
->ProgramStringNotify
== _tnl_program_string
);
172 functions
->BindProgram
= st_bind_program
;
173 functions
->NewProgram
= st_new_program
;
174 functions
->DeleteProgram
= st_delete_program
;
175 functions
->IsProgramNative
= st_is_program_native
;
176 functions
->ProgramStringNotify
= st_program_string_notify
;