static GLboolean
parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
- struct gl_program *program)
+ struct gl_shader *shader)
{
GET_CURRENT_CONTEXT(ctx);
slang_output_ctx o;
o.structs = &unit->structs;
o.vars = &unit->vars;
o.global_pool = &unit->object->varpool;
- o.program = program;
+ o.program = shader ? shader->Program : NULL;
o.vartable = _slang_new_var_table(maxRegs);
_slang_push_var_table(o.vartable);
_slang_codegen_function(&A, mainFunc);
+ shader->Main = GL_TRUE; /* this shader defines main() */
}
_slang_pop_var_table(o.vartable);
GLuint version,
slang_unit_type type, slang_info_log * infolog,
slang_code_unit * builtin, slang_code_unit * downlink,
- struct gl_program *program)
+ struct gl_shader *shader)
{
slang_parse_ctx C;
}
/* parse translation unit */
- return parse_code_unit(&C, unit, program);
+ return parse_code_unit(&C, unit, shader);
}
static GLboolean
compile_with_grammar(grammar id, const char *source, slang_code_unit * unit,
slang_unit_type type, slang_info_log * infolog,
slang_code_unit * builtin,
- struct gl_program *program)
+ struct gl_shader *shader)
{
byte *prod;
GLuint size, start, version;
/* Syntax is okay - translate it to internal representation. */
if (!compile_binary(prod, unit, version, type, infolog, builtin,
&builtin[SLANG_BUILTIN_TOTAL - 1],
- program)) {
+ shader)) {
grammar_alloc_free(prod);
return GL_FALSE;
}
static GLboolean
compile_object(grammar * id, const char *source, slang_code_object * object,
slang_unit_type type, slang_info_log * infolog,
- struct gl_program *program)
+ struct gl_shader *shader)
{
slang_code_unit *builtins = NULL;
GLuint base_version = 110;
/* compile the actual shader - pass-in built-in library for external shader */
return compile_with_grammar(*id, source, &object->unit, type, infolog,
- builtins, program);
+ builtins, shader);
}
slang_unit_type type, slang_info_log * infolog,
struct gl_shader *shader)
{
- struct gl_program *program = shader->Programs[0];
GLboolean success;
grammar id = 0;
_mesa_printf("************************************\n");
#endif
- assert(program);
+ assert(shader->Program);
_slang_code_object_dtr(object);
_slang_code_object_ctr(object);
- success = compile_object(&id, shader->Source, object, type, infolog, program);
+ success = compile_object(&id, shader->Source, object, type, infolog, shader);
if (id != 0)
grammar_destroy(id);
if (!success)
ctx->Shader.MemPool = _slang_new_mempool(1024*1024);
- /* XXX temporary hack */
- if (!shader->Programs) {
+ shader->Main = GL_FALSE;
+
+ if (!shader->Program) {
GLenum progTarget;
if (shader->Type == GL_VERTEX_SHADER)
progTarget = GL_VERTEX_PROGRAM_ARB;
else
progTarget = GL_FRAGMENT_PROGRAM_ARB;
- shader->Programs
- = (struct gl_program **) malloc(sizeof(struct gl_program*));
- shader->Programs[0] = ctx->Driver.NewProgram(ctx, progTarget, 1);
- shader->NumPrograms = 1;
-
- shader->Programs[0]->Parameters = _mesa_new_parameter_list();
- shader->Programs[0]->Varying = _mesa_new_parameter_list();
- shader->Programs[0]->Attributes = _mesa_new_parameter_list();
+ shader->Program = ctx->Driver.NewProgram(ctx, progTarget, 1);
+ shader->Program->Parameters = _mesa_new_parameter_list();
+ shader->Program->Varying = _mesa_new_parameter_list();
+ shader->Program->Attributes = _mesa_new_parameter_list();
}
slang_info_log_construct(&info_log);
/* remove any reads of varying (output) registers */
#if 0
printf("Pre-remove output reads:\n");
- _mesa_print_program(shader->Programs[0]);
+ _mesa_print_program(shader->Programs);
#endif
- _mesa_remove_output_reads(shader->Programs[0], PROGRAM_VARYING);
- _mesa_remove_output_reads(shader->Programs[0], PROGRAM_OUTPUT);
+ _mesa_remove_output_reads(shader->Program, PROGRAM_VARYING);
+ _mesa_remove_output_reads(shader->Program, PROGRAM_OUTPUT);
#if 0
printf("Post-remove output reads:\n");
- _mesa_print_program(shader->Programs[0]);
+ _mesa_print_program(shader->Programs);
#endif
}