r300: more r300/r500 unification
[mesa.git] / src / mesa / drivers / dri / r300 / r300_shader.c
1
2 #include "main/glheader.h"
3
4 #include "shader/program.h"
5 #include "tnl/tnl.h"
6 #include "r300_context.h"
7 #include "r300_fragprog.h"
8
9 static struct gl_program *r300NewProgram(GLcontext * ctx, GLenum target,
10 GLuint id)
11 {
12 struct r300_vertex_program_cont *vp;
13 struct r300_fragment_program *fp;
14
15 switch (target) {
16 case GL_VERTEX_STATE_PROGRAM_NV:
17 case GL_VERTEX_PROGRAM_ARB:
18 vp = CALLOC_STRUCT(r300_vertex_program_cont);
19 return _mesa_init_vertex_program(ctx, &vp->mesa_program,
20 target, id);
21
22 case GL_FRAGMENT_PROGRAM_NV:
23 case GL_FRAGMENT_PROGRAM_ARB:
24 fp = CALLOC_STRUCT(r300_fragment_program);
25 return _mesa_init_fragment_program(ctx, &fp->Base, target, id);
26
27 default:
28 _mesa_problem(ctx, "Bad target in r300NewProgram");
29 }
30
31 return NULL;
32 }
33
34 static void r300DeleteProgram(GLcontext * ctx, struct gl_program *prog)
35 {
36 _mesa_delete_program(ctx, prog);
37 }
38
39 static void
40 r300ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
41 {
42 struct r300_vertex_program_cont *vp = (void *)prog;
43 struct r300_fragment_program *r300_fp = (struct r300_fragment_program *)prog;
44
45 switch (target) {
46 case GL_VERTEX_PROGRAM_ARB:
47 vp->progs = NULL;
48 break;
49 case GL_FRAGMENT_PROGRAM_ARB:
50 r300_fp->translated = GL_FALSE;
51 break;
52 }
53
54 /* need this for tcl fallbacks */
55 _tnl_program_string(ctx, target, prog);
56 }
57
58 static GLboolean
59 r300IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
60 {
61 if (target == GL_FRAGMENT_PROGRAM_ARB) {
62 r300ContextPtr rmesa = R300_CONTEXT(ctx);
63 struct r300_fragment_program *fp = (struct r300_fragment_program *)prog;
64 if (!fp->translated)
65 rmesa->vtbl.TranslateFragmentShader(ctx, &fp->Base);
66
67 return !fp->error;
68 } else
69 return GL_TRUE;
70 }
71
72 void r300InitShaderFuncs(struct dd_function_table *functions)
73 {
74 functions->NewProgram = r300NewProgram;
75 functions->DeleteProgram = r300DeleteProgram;
76 functions->ProgramStringNotify = r300ProgramStringNotify;
77 functions->IsProgramNative = r300IsProgramNative;
78 }