unsigned int shader_type,
unsigned int parsing_builtin)
{
+ struct sl_pp_purify_options options;
struct sl_pp_context *context;
- struct sl_pp_token_info *tokens;
unsigned char *prod;
GLuint size;
unsigned int version;
unsigned int maxVersion;
int result;
- struct sl_pp_purify_options options;
char errmsg[200] = "";
unsigned int errline = 0;
- struct sl_pp_token_info *intokens;
- unsigned int tokens_eaten;
- context = sl_pp_context_create();
+ memset(&options, 0, sizeof(options));
+
+ context = sl_pp_context_create(source, &options);
if (!context) {
slang_info_log_error(infolog, "out of memory");
return GL_FALSE;
}
+ if (sl_pp_version(context, &version)) {
+ slang_info_log_error(infolog, "%s", sl_pp_context_error_message(context));
+ sl_pp_context_destroy(context);
+ return GL_FALSE;
+ }
+
if (sl_pp_context_add_extension(context, "ARB_draw_buffers", "GL_ARB_draw_buffers") ||
sl_pp_context_add_extension(context, "ARB_texture_rectangle", "GL_ARB_texture_rectangle")) {
slang_info_log_error(infolog, "%s", sl_pp_context_error_message(context));
}
#endif
- memset(&options, 0, sizeof(options));
- if (sl_pp_tokenise(context, source, &options, &intokens)) {
- slang_info_log_error(infolog, "%s", sl_pp_context_error_message(context));
- sl_pp_context_destroy(context);
- return GL_FALSE;
- }
-
- if (sl_pp_version(context, intokens, &version, &tokens_eaten)) {
- slang_info_log_error(infolog, "%s", sl_pp_context_error_message(context));
- sl_pp_context_destroy(context);
- free(intokens);
- return GL_FALSE;
- }
-
- if (sl_pp_process(context, &intokens[tokens_eaten], &tokens)) {
- slang_info_log_error(infolog, "%s", sl_pp_context_error_message(context));
- sl_pp_context_destroy(context);
- free(intokens);
- return GL_FALSE;
- }
-
- free(intokens);
-
- /* For the time being we care about only a handful of tokens. */
- {
- const struct sl_pp_token_info *src = tokens;
- struct sl_pp_token_info *dst = tokens;
-
- while (src->token != SL_PP_EOF) {
- switch (src->token) {
- case SL_PP_COMMA:
- case SL_PP_SEMICOLON:
- case SL_PP_LBRACE:
- case SL_PP_RBRACE:
- case SL_PP_LPAREN:
- case SL_PP_RPAREN:
- case SL_PP_LBRACKET:
- case SL_PP_RBRACKET:
- case SL_PP_DOT:
- case SL_PP_INCREMENT:
- case SL_PP_ADDASSIGN:
- case SL_PP_PLUS:
- case SL_PP_DECREMENT:
- case SL_PP_SUBASSIGN:
- case SL_PP_MINUS:
- case SL_PP_BITNOT:
- case SL_PP_NOTEQUAL:
- case SL_PP_NOT:
- case SL_PP_MULASSIGN:
- case SL_PP_STAR:
- case SL_PP_DIVASSIGN:
- case SL_PP_SLASH:
- case SL_PP_MODASSIGN:
- case SL_PP_MODULO:
- case SL_PP_LSHIFTASSIGN:
- case SL_PP_LSHIFT:
- case SL_PP_LESSEQUAL:
- case SL_PP_LESS:
- case SL_PP_RSHIFTASSIGN:
- case SL_PP_RSHIFT:
- case SL_PP_GREATEREQUAL:
- case SL_PP_GREATER:
- case SL_PP_EQUAL:
- case SL_PP_ASSIGN:
- case SL_PP_AND:
- case SL_PP_BITANDASSIGN:
- case SL_PP_BITAND:
- case SL_PP_XOR:
- case SL_PP_BITXORASSIGN:
- case SL_PP_BITXOR:
- case SL_PP_OR:
- case SL_PP_BITORASSIGN:
- case SL_PP_BITOR:
- case SL_PP_QUESTION:
- case SL_PP_COLON:
- case SL_PP_IDENTIFIER:
- case SL_PP_UINT:
- case SL_PP_FLOAT:
- *dst++ = *src++;
- break;
-
- default:
- src++;
- }
- }
-
- /* The end of stream token. */
- *dst = *src;
- }
-
#if FEATURE_ARB_shading_language_120
maxVersion = 120;
#elif FEATURE_es2_glsl
"language version %.2f is not supported.",
version * 0.01);
sl_pp_context_destroy(context);
- free(tokens);
return GL_FALSE;
}
/* Finally check the syntax and generate its binary representation. */
result = sl_cl_compile(context,
- tokens,
shader_type,
parsing_builtin,
&prod,
sizeof(errmsg));
sl_pp_context_destroy(context);
- free(tokens);
if (result) {
/*GLint pos;*/
slang_info_log info_log;
slang_code_object obj;
slang_unit_type type;
+ GLenum progTarget;
if (shader->Type == GL_VERTEX_SHADER) {
type = SLANG_UNIT_VERTEX_SHADER;
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->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();
- }
+ /* free the shader's old instructions, etc */
+ _mesa_reference_program(ctx, &shader->Program, NULL);
+
+ /* allocate new GPU program, parameter lists, etc. */
+ if (shader->Type == GL_VERTEX_SHADER)
+ progTarget = GL_VERTEX_PROGRAM_ARB;
+ else
+ progTarget = GL_FRAGMENT_PROGRAM_ARB;
+ 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);
_slang_code_object_ctr(&obj);
(ctx->Shader.Flags & GLSL_NO_OPT) == 0) {
_mesa_optimize_program(ctx, shader->Program);
}
+ if ((ctx->Shader.Flags & GLSL_NOP_VERT) &&
+ shader->Program->Target == GL_VERTEX_PROGRAM_ARB) {
+ _mesa_nop_vertex_program(ctx,
+ (struct gl_vertex_program *) shader->Program);
+ }
+ if ((ctx->Shader.Flags & GLSL_NOP_FRAG) &&
+ shader->Program->Target == GL_FRAGMENT_PROGRAM_ARB) {
+ _mesa_nop_fragment_program(ctx,
+ (struct gl_fragment_program *) shader->Program);
+ }
}
if (ctx->Shader.Flags & GLSL_LOG) {