Merge remote branch 'origin/master' into radeon-rewrite
[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 r300ContextPtr rmesa = R300_CONTEXT(ctx);
13 struct r300_vertex_program_cont *vp;
14 struct r300_fragment_program *r300_fp;
15 struct r500_fragment_program *r500_fp;
16
17 switch (target) {
18 case GL_VERTEX_STATE_PROGRAM_NV:
19 case GL_VERTEX_PROGRAM_ARB:
20 vp = CALLOC_STRUCT(r300_vertex_program_cont);
21 return _mesa_init_vertex_program(ctx, &vp->mesa_program,
22 target, id);
23 case GL_FRAGMENT_PROGRAM_ARB:
24 if (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) {
25 r500_fp = CALLOC_STRUCT(r500_fragment_program);
26 r500_fp->ctx = ctx;
27 return _mesa_init_fragment_program(ctx, &r500_fp->mesa_program,
28 target, id);
29 } else {
30 r300_fp = CALLOC_STRUCT(r300_fragment_program);
31 return _mesa_init_fragment_program(ctx, &r300_fp->mesa_program,
32 target, id);
33 }
34
35 case GL_FRAGMENT_PROGRAM_NV:
36 if (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) {
37 r500_fp = CALLOC_STRUCT(r500_fragment_program);
38 return _mesa_init_fragment_program(ctx, &r500_fp->mesa_program,
39 target, id);
40 } else {
41 r300_fp = CALLOC_STRUCT(r300_fragment_program);
42 return _mesa_init_fragment_program(ctx, &r300_fp->mesa_program,
43 target, id);
44 }
45 default:
46 _mesa_problem(ctx, "Bad target in r300NewProgram");
47 }
48
49 return NULL;
50 }
51
52 static void r300DeleteProgram(GLcontext * ctx, struct gl_program *prog)
53 {
54 _mesa_delete_program(ctx, prog);
55 }
56
57 static void
58 r300ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
59 {
60 r300ContextPtr rmesa = R300_CONTEXT(ctx);
61 struct r300_vertex_program_cont *vp = (void *)prog;
62 struct r300_fragment_program *r300_fp = (struct r300_fragment_program *)prog;
63 struct r500_fragment_program *r500_fp = (struct r500_fragment_program *)prog;
64
65 switch (target) {
66 case GL_VERTEX_PROGRAM_ARB:
67 vp->progs = NULL;
68 break;
69 case GL_FRAGMENT_PROGRAM_ARB:
70 if (rmesa->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515)
71 r500_fp->translated = GL_FALSE;
72 else
73 r300_fp->translated = GL_FALSE;
74 break;
75 }
76
77 /* need this for tcl fallbacks */
78 _tnl_program_string(ctx, target, prog);
79 }
80
81 static GLboolean
82 r300IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
83 {
84 return GL_TRUE;
85 }
86
87 void r300InitShaderFuncs(struct dd_function_table *functions)
88 {
89 functions->NewProgram = r300NewProgram;
90 functions->DeleteProgram = r300DeleteProgram;
91 functions->ProgramStringNotify = r300ProgramStringNotify;
92 functions->IsProgramNative = r300IsProgramNative;
93 }