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