e3b6fccc49fbd6160f74851ff204c235a1daa4d2
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
32 #include "main/imports.h"
33 #include "main/enums.h"
34 #include "shader/prog_parameter.h"
35 #include "shader/program.h"
36 #include "shader/programopt.h"
39 #include "brw_context.h"
42 static void brwBindProgram( GLcontext
*ctx
,
44 struct gl_program
*prog
)
46 struct brw_context
*brw
= brw_context(ctx
);
49 case GL_VERTEX_PROGRAM_ARB
:
50 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
52 case GL_FRAGMENT_PROGRAM_ARB
:
53 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
58 static struct gl_program
*brwNewProgram( GLcontext
*ctx
,
62 struct brw_context
*brw
= brw_context(ctx
);
65 case GL_VERTEX_PROGRAM_ARB
: {
66 struct brw_vertex_program
*prog
= CALLOC_STRUCT(brw_vertex_program
);
68 prog
->id
= brw
->program_id
++;
70 return _mesa_init_vertex_program( ctx
, &prog
->program
,
77 case GL_FRAGMENT_PROGRAM_ARB
: {
78 struct brw_fragment_program
*prog
= CALLOC_STRUCT(brw_fragment_program
);
80 prog
->id
= brw
->program_id
++;
82 return _mesa_init_fragment_program( ctx
, &prog
->program
,
90 return _mesa_new_program(ctx
, target
, id
);
94 static void brwDeleteProgram( GLcontext
*ctx
,
95 struct gl_program
*prog
)
97 if (prog
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
98 struct gl_fragment_program
*fprog
= (struct gl_fragment_program
*) prog
;
99 struct brw_fragment_program
*brw_fprog
= brw_fragment_program(fprog
);
100 dri_bo_unreference(brw_fprog
->const_buffer
);
103 _mesa_delete_program( ctx
, prog
);
107 static GLboolean
brwIsProgramNative( GLcontext
*ctx
,
109 struct gl_program
*prog
)
114 static void brwProgramStringNotify( GLcontext
*ctx
,
116 struct gl_program
*prog
)
118 struct brw_context
*brw
= brw_context(ctx
);
120 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
121 struct gl_fragment_program
*fprog
= (struct gl_fragment_program
*) prog
;
122 struct brw_fragment_program
*newFP
= brw_fragment_program(fprog
);
123 const struct brw_fragment_program
*curFP
=
124 brw_fragment_program_const(brw
->fragment_program
);
126 if (fprog
->FogOption
) {
127 _mesa_append_fog_code(ctx
, fprog
);
128 fprog
->FogOption
= GL_NONE
;
132 brw
->state
.dirty
.brw
|= BRW_NEW_FRAGMENT_PROGRAM
;
133 newFP
->id
= brw
->program_id
++;
134 newFP
->isGLSL
= brw_wm_is_glsl(fprog
);
136 else if (target
== GL_VERTEX_PROGRAM_ARB
) {
137 struct gl_vertex_program
*vprog
= (struct gl_vertex_program
*) prog
;
138 struct brw_vertex_program
*newVP
= brw_vertex_program(vprog
);
139 const struct brw_vertex_program
*curVP
=
140 brw_vertex_program_const(brw
->vertex_program
);
143 brw
->state
.dirty
.brw
|= BRW_NEW_VERTEX_PROGRAM
;
144 if (newVP
->program
.IsPositionInvariant
) {
145 _mesa_insert_mvp_code(ctx
, &newVP
->program
);
147 newVP
->id
= brw
->program_id
++;
149 /* Also tell tnl about it:
151 _tnl_program_string(ctx
, target
, prog
);
155 void brwInitFragProgFuncs( struct dd_function_table
*functions
)
157 assert(functions
->ProgramStringNotify
== _tnl_program_string
);
159 functions
->BindProgram
= brwBindProgram
;
160 functions
->NewProgram
= brwNewProgram
;
161 functions
->DeleteProgram
= brwDeleteProgram
;
162 functions
->IsProgramNative
= brwIsProgramNative
;
163 functions
->ProgramStringNotify
= brwProgramStringNotify
;