rename a few structs (use _state suffix consistantly), reorder/sort fields in some...
[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
36 #include "glheader.h"
37 #include "macros.h"
38 #include "enums.h"
39 #include "prog_instruction.h"
40 #include "prog_parameter.h"
41 #include "program.h"
42 #include "programopt.h"
43 #include "tnl/tnl.h"
44
45
46 static void st_bind_program( GLcontext *ctx,
47 GLenum target,
48 struct gl_program *prog )
49 {
50 struct st_context *st = st_context(ctx);
51
52 switch (target) {
53 case GL_VERTEX_PROGRAM_ARB:
54 break;
55 case GL_FRAGMENT_PROGRAM_ARB:
56 st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
57 break;
58 }
59 }
60
61 static struct gl_program *st_new_program( GLcontext *ctx,
62 GLenum target,
63 GLuint id )
64 {
65 struct st_context *st = st_context(ctx);
66
67 switch (target) {
68 case GL_VERTEX_PROGRAM_ARB:
69 return _mesa_init_vertex_program(ctx,
70 CALLOC_STRUCT(gl_vertex_program),
71 target,
72 id);
73
74 case GL_FRAGMENT_PROGRAM_ARB: {
75 struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program);
76
77 prog->id = st->program_id++;
78
79 return _mesa_init_fragment_program( ctx,
80 &prog->Base,
81 target,
82 id );
83 }
84
85 default:
86 return _mesa_new_program(ctx, target, id);
87 }
88 }
89
90 static void st_delete_program( GLcontext *ctx,
91 struct gl_program *prog )
92 {
93 _mesa_delete_program( ctx, prog );
94 }
95
96
97 static GLboolean st_is_program_native( GLcontext *ctx,
98 GLenum target,
99 struct gl_program *prog )
100 {
101 return GL_TRUE;
102 }
103
104 static void st_program_string_notify( GLcontext *ctx,
105 GLenum target,
106 struct gl_program *prog )
107 {
108 if (target == GL_FRAGMENT_PROGRAM_ARB) {
109 struct st_context *st = st_context(ctx);
110
111 if (prog == &st->ctx->FragmentProgram._Current->Base)
112 {
113 struct st_fragment_program *p =
114 (struct st_fragment_program *) prog;
115
116 st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
117
118 p->id = st->program_id++;
119 #if 0
120 p->param_state = p->Base.Base.Parameters->StateFlags;
121 p->translated = 0;
122 #endif
123
124 /* Gack! do this in the compiler:
125 */
126 if (p->Base.FogOption) {
127 /* add extra instructions to do fog, then turn off FogOption field */
128 _mesa_append_fog_code(ctx, &p->Base);
129 p->Base.FogOption = GL_NONE;
130 }
131 }
132 }
133 else if (target == GL_VERTEX_PROGRAM_ARB) {
134
135 /* Also tell tnl about it:
136 */
137 _tnl_program_string(ctx, target, prog);
138 }
139 }
140
141
142
143 void st_init_cb_program( struct st_context *st )
144 {
145 struct dd_function_table *functions = &st->ctx->Driver;
146
147 /* Need these flags:
148 */
149 st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
150 st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE;
151
152
153 assert(functions->ProgramStringNotify == _tnl_program_string);
154 functions->BindProgram = st_bind_program;
155 functions->NewProgram = st_new_program;
156 functions->DeleteProgram = st_delete_program;
157 functions->IsProgramNative = st_is_program_native;
158 functions->ProgramStringNotify = st_program_string_notify;
159 }
160
161
162 void st_destroy_cb_program( struct st_context *st )
163 {
164 }
165