253f2937edfee4282d9469a93065a93ab8b81fd1
[mesa.git] / src / mesa / shader / arbvertparse.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #define DEBUG_VP 0
26
27 /**
28 * \file arbvertparse.c
29 * ARB_vertex_program parser.
30 * \author Karl Rasche
31 */
32
33 #include "glheader.h"
34 #include "imports.h"
35 #include "program.h"
36 #include "arbprogparse.h"
37 #include "arbvertparse.h"
38
39
40 /**
41 * Parse the vertex program string. If success, update the given
42 * vertex_program object with the new program. Else, leave the vertex_program
43 * object unchanged.
44 */
45 void
46 _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target,
47 const GLubyte * str, GLsizei len,
48 struct vertex_program *program)
49 {
50 struct arb_program ap;
51 (void) target;
52 struct prog_instruction *newInstructions;
53
54 /* set the program target before parsing */
55 ap.Base.Target = GL_VERTEX_PROGRAM_ARB;
56
57 if (!_mesa_parse_arb_program(ctx, str, len, &ap)) {
58 /* Error in the program. Just return. */
59 return;
60 }
61
62 /* Copy the relevant contents of the arb_program struct into the
63 * vertex_program struct.
64 */
65 /* copy instruction buffer */
66 newInstructions = (struct prog_instruction *)
67 _mesa_malloc(ap.Base.NumInstructions * sizeof(struct prog_instruction));
68 if (!newInstructions) {
69 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
70 return;
71 }
72 _mesa_memcpy(newInstructions, ap.VPInstructions,
73 ap.Base.NumInstructions * sizeof(struct prog_instruction));
74 if (program->Base.Instructions)
75 _mesa_free(program->Base.Instructions);
76 program->Base.Instructions = newInstructions;
77 program->Base.String = ap.Base.String;
78 program->Base.NumInstructions = ap.Base.NumInstructions;
79 program->Base.NumTemporaries = ap.Base.NumTemporaries;
80 program->Base.NumParameters = ap.Base.NumParameters;
81 program->Base.NumAttributes = ap.Base.NumAttributes;
82 program->Base.NumAddressRegs = ap.Base.NumAddressRegs;
83 program->IsPositionInvariant = ap.HintPositionInvariant;
84 program->Base.InputsRead = ap.Base.InputsRead;
85 program->Base.OutputsWritten = ap.Base.OutputsWritten;
86
87 if (program->Base.Parameters) {
88 /* free previous program's parameters */
89 _mesa_free_parameter_list(program->Base.Parameters);
90 }
91 program->Base.Parameters = ap.Base.Parameters;
92
93 #if DEBUG_VP
94 _mesa_print_program(&program->Base);
95 #endif
96 }