r300: add hw accelerated support for different vertex data formats
[mesa.git] / src / mesa / drivers / dri / r300 / r300_shader.c
1 /*
2 * Copyright 2009 Maciej Cencora <m.cencora@gmail.com>
3 *
4 * All Rights Reserved.
5 *
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:
13 *
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.
17 *
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.
25 *
26 */
27
28 #include "main/glheader.h"
29
30 #include "shader/program.h"
31 #include "tnl/tnl.h"
32 #include "r300_context.h"
33 #include "r300_fragprog_common.h"
34
35 static struct gl_program *r300NewProgram(GLcontext * ctx, GLenum target,
36 GLuint id)
37 {
38 struct r300_vertex_program_cont *vp;
39 struct r300_fragment_program *fp;
40
41 switch (target) {
42 case GL_VERTEX_STATE_PROGRAM_NV:
43 case GL_VERTEX_PROGRAM_ARB:
44 vp = CALLOC_STRUCT(r300_vertex_program_cont);
45 return _mesa_init_vertex_program(ctx, &vp->mesa_program,
46 target, id);
47
48 case GL_FRAGMENT_PROGRAM_NV:
49 case GL_FRAGMENT_PROGRAM_ARB:
50 fp = CALLOC_STRUCT(r300_fragment_program);
51 return _mesa_init_fragment_program(ctx, &fp->Base, target, id);
52
53 default:
54 _mesa_problem(ctx, "Bad target in r300NewProgram");
55 }
56
57 return NULL;
58 }
59
60 static void r300DeleteProgram(GLcontext * ctx, struct gl_program *prog)
61 {
62 _mesa_delete_program(ctx, prog);
63 }
64
65 static void
66 r300ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
67 {
68 struct r300_vertex_program_cont *vp = (void *)prog;
69 struct r300_fragment_program *r300_fp = (struct r300_fragment_program *)prog;
70
71 switch (target) {
72 case GL_VERTEX_PROGRAM_ARB:
73 vp->progs = NULL;
74 break;
75 case GL_FRAGMENT_PROGRAM_ARB:
76 r300_fp->translated = GL_FALSE;
77 break;
78 }
79
80 /* need this for tcl fallbacks */
81 _tnl_program_string(ctx, target, prog);
82 }
83
84 static GLboolean
85 r300IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
86 {
87 if (target == GL_FRAGMENT_PROGRAM_ARB) {
88 struct r300_fragment_program *fp = (struct r300_fragment_program *)prog;
89 if (!fp->translated)
90 r300TranslateFragmentShader(ctx, &fp->Base);
91
92 return !fp->error;
93 } else
94 return GL_TRUE;
95 }
96
97 void r300InitShaderFuncs(struct dd_function_table *functions)
98 {
99 functions->NewProgram = r300NewProgram;
100 functions->DeleteProgram = r300DeleteProgram;
101 functions->ProgramStringNotify = r300ProgramStringNotify;
102 functions->IsProgramNative = r300IsProgramNative;
103 }