2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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 arbfragparse.c
29 * ARB_fragment_program parser.
39 #include "arbprogparse.h"
40 #include "arbfragparse.h"
44 _mesa_parse_arb_fragment_program(GLcontext
* ctx
, GLenum target
,
45 const GLubyte
* str
, GLsizei len
,
46 struct fragment_program
*program
)
49 struct arb_program ap
;
50 struct prog_instruction
*newInstructions
;
53 /* set the program target before parsing */
54 ap
.Base
.Target
= GL_FRAGMENT_PROGRAM_ARB
;
56 if (!_mesa_parse_arb_program(ctx
, str
, len
, &ap
)) {
57 /* Error in the program. Just return. */
61 /* Copy the relevant contents of the arb_program struct into the
62 * fragment_program struct.
64 /* copy instruction buffer */
65 newInstructions
= (struct prog_instruction
*)
66 _mesa_malloc(ap
.Base
.NumInstructions
* sizeof(struct prog_instruction
));
67 if (!newInstructions
) {
68 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glProgramStringARB");
71 _mesa_memcpy(newInstructions
, ap
.FPInstructions
,
72 ap
.Base
.NumInstructions
* sizeof(struct prog_instruction
));
73 if (program
->Instructions
)
74 _mesa_free(program
->Instructions
);
75 program
->Instructions
= newInstructions
;
76 program
->Base
.String
= ap
.Base
.String
;
77 program
->Base
.NumInstructions
= ap
.Base
.NumInstructions
;
78 program
->Base
.NumTemporaries
= ap
.Base
.NumTemporaries
;
79 program
->Base
.NumParameters
= ap
.Base
.NumParameters
;
80 program
->Base
.NumAttributes
= ap
.Base
.NumAttributes
;
81 program
->Base
.NumAddressRegs
= ap
.Base
.NumAddressRegs
;
82 program
->NumAluInstructions
= ap
.NumAluInstructions
;
83 program
->NumTexInstructions
= ap
.NumTexInstructions
;
84 program
->NumTexIndirections
= ap
.NumTexIndirections
;
85 program
->InputsRead
= ap
.InputsRead
;
86 program
->OutputsWritten
= ap
.OutputsWritten
;
87 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
88 program
->TexturesUsed
[i
] = ap
.TexturesUsed
[i
];
90 if (program
->Parameters
) {
91 /* free previous program's parameters */
92 _mesa_free_parameter_list(program
->Parameters
);
94 program
->Parameters
= ap
.Parameters
;
95 program
->FogOption
= ap
.FogOption
;
98 _mesa_print_program(ap
.Base
.NumInstructions
, ap
.FPInstructions
);