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"
39 #include "prog_instruction.h"
40 #include "prog_parameter.h"
42 #include "programopt.h"
44 #include "pipe/tgsi/mesa/tgsi_mesa.h"
47 static void st_bind_program( GLcontext
*ctx
,
49 struct gl_program
*prog
)
51 struct st_context
*st
= st_context(ctx
);
54 case GL_VERTEX_PROGRAM_ARB
:
55 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
57 case GL_FRAGMENT_PROGRAM_ARB
:
58 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
63 static struct gl_program
*st_new_program( GLcontext
*ctx
,
67 struct st_context
*st
= st_context(ctx
);
70 case GL_VERTEX_PROGRAM_ARB
: {
71 struct st_vertex_program
*prog
= CALLOC_STRUCT(st_vertex_program
);
73 prog
->id
= st
->program_id
++;
76 return _mesa_init_vertex_program( ctx
,
82 case GL_FRAGMENT_PROGRAM_ARB
:
83 case GL_FRAGMENT_PROGRAM_NV
:
85 struct st_fragment_program
*prog
= CALLOC_STRUCT(st_fragment_program
);
87 prog
->id
= st
->program_id
++;
90 return _mesa_init_fragment_program( ctx
,
97 return _mesa_new_program(ctx
, target
, id
);
101 static void st_delete_program( GLcontext
*ctx
,
102 struct gl_program
*prog
)
104 _mesa_delete_program( ctx
, prog
);
108 static GLboolean
st_is_program_native( GLcontext
*ctx
,
110 struct gl_program
*prog
)
115 static void st_program_string_notify( GLcontext
*ctx
,
117 struct gl_program
*prog
)
119 struct st_context
*st
= st_context(ctx
);
121 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
122 struct st_fragment_program
*p
= (struct st_fragment_program
*)prog
;
124 if (prog
== &ctx
->FragmentProgram
._Current
->Base
)
125 st
->dirty
.st
|= ST_NEW_FRAGMENT_PROGRAM
;
127 p
->id
= st
->program_id
++;
128 p
->param_state
= p
->Base
.Base
.Parameters
->StateFlags
;
130 else if (target
== GL_VERTEX_PROGRAM_ARB
) {
131 struct st_vertex_program
*p
= (struct st_vertex_program
*)prog
;
133 if (prog
== &ctx
->VertexProgram
._Current
->Base
)
134 st
->dirty
.st
|= ST_NEW_VERTEX_PROGRAM
;
136 p
->id
= st
->program_id
++;
137 p
->param_state
= p
->Base
.Base
.Parameters
->StateFlags
;
139 /* Also tell tnl about it:
141 _tnl_program_string(ctx
, target
, prog
);
147 void st_init_cb_program( struct st_context
*st
)
149 struct dd_function_table
*functions
= &st
->ctx
->Driver
;
153 st
->ctx
->FragmentProgram
._MaintainTexEnvProgram
= GL_TRUE
;
154 st
->ctx
->FragmentProgram
._UseTexEnvProgram
= GL_TRUE
;
157 assert(functions
->ProgramStringNotify
== _tnl_program_string
);
159 functions
->BindProgram
= st_bind_program
;
160 functions
->NewProgram
= st_new_program
;
161 functions
->DeleteProgram
= st_delete_program
;
162 functions
->IsProgramNative
= st_is_program_native
;
163 functions
->ProgramStringNotify
= st_program_string_notify
;
167 void st_destroy_cb_program( struct st_context
*st
)