253f2937edfee4282d9469a93065a93ab8b81fd1
2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 * \file arbvertparse.c
29 * ARB_vertex_program parser.
36 #include "arbprogparse.h"
37 #include "arbvertparse.h"
41 * Parse the vertex program string. If success, update the given
42 * vertex_program object with the new program. Else, leave the vertex_program
46 _mesa_parse_arb_vertex_program(GLcontext
* ctx
, GLenum target
,
47 const GLubyte
* str
, GLsizei len
,
48 struct vertex_program
*program
)
50 struct arb_program ap
;
52 struct prog_instruction
*newInstructions
;
54 /* set the program target before parsing */
55 ap
.Base
.Target
= GL_VERTEX_PROGRAM_ARB
;
57 if (!_mesa_parse_arb_program(ctx
, str
, len
, &ap
)) {
58 /* Error in the program. Just return. */
62 /* Copy the relevant contents of the arb_program struct into the
63 * vertex_program struct.
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");
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
;
87 if (program
->Base
.Parameters
) {
88 /* free previous program's parameters */
89 _mesa_free_parameter_list(program
->Base
.Parameters
);
91 program
->Base
.Parameters
= ap
.Base
.Parameters
;
94 _mesa_print_program(&program
->Base
);