X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fshader%2Fshader_api.c;h=648fbc186bbedc130fa18f933df1e99ca3e3f9c4;hb=e93848e595176ae0bad3bfe64e0ca63fd089bb72;hp=828d3f062acbfea3ffda7625a1e676007d7b220e;hpb=621c999d823eed077aee9ac0779077ba2f0c5e5a;p=mesa.git diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index 828d3f062ac..648fbc186bb 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -1,8 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 7.2 + * Version: 7.5 * * Copyright (C) 2004-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -50,11 +51,6 @@ #include "glapi/dispatch.h" -#ifndef GL_PROGRAM_BINARY_LENGTH_OES -#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 -#endif - - /** * Allocate a new gl_shader_program object, initialize it. */ @@ -406,9 +402,16 @@ _mesa_init_shader_state(GLcontext * ctx) * are generated by the GLSL compiler. */ ctx->Shader.EmitHighLevelInstructions = GL_TRUE; + ctx->Shader.EmitContReturn = GL_TRUE; ctx->Shader.EmitCondCodes = GL_FALSE; ctx->Shader.EmitComments = GL_FALSE; ctx->Shader.Flags = get_shader_flags(); + + /* Default pragma settings */ + ctx->Shader.DefaultPragmas.IgnoreOptimize = GL_FALSE; + ctx->Shader.DefaultPragmas.IgnoreDebug = GL_FALSE; + ctx->Shader.DefaultPragmas.Optimize = GL_TRUE; + ctx->Shader.DefaultPragmas.Debug = GL_FALSE; } @@ -827,6 +830,27 @@ is_integer_type(GLenum type) } +static GLboolean +is_sampler_type(GLenum type) +{ + switch (type) { + case GL_SAMPLER_1D: + case GL_SAMPLER_2D: + case GL_SAMPLER_3D: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_1D_SHADOW: + case GL_SAMPLER_2D_SHADOW: + case GL_SAMPLER_2D_RECT_ARB: + case GL_SAMPLER_2D_RECT_SHADOW_ARB: + case GL_SAMPLER_1D_ARRAY_EXT: + case GL_SAMPLER_2D_ARRAY_EXT: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + static void _mesa_get_active_attrib(GLcontext *ctx, GLuint program, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, @@ -1422,6 +1446,9 @@ _mesa_compile_shader(GLcontext *ctx, GLuint shaderObj) if (!sh) return; + /* set default pragma state for shader */ + sh->Pragmas = ctx->Shader.DefaultPragmas; + /* this call will set the sh->CompileStatus field to indicate if * compilation was successful. */ @@ -1461,7 +1488,7 @@ _mesa_use_program(GLcontext *ctx, GLuint program) return; } - FLUSH_VERTICES(ctx, _NEW_PROGRAM); + FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS); if (program) { shProg = _mesa_lookup_shader_program_err(ctx, program, "glUseProgram"); @@ -1473,6 +1500,21 @@ _mesa_use_program(GLcontext *ctx, GLuint program) "glUseProgram(program %u not linked)", program); return; } + + /* debug code */ + if (0) { + GLuint i; + _mesa_printf("Use Shader %u\n", shProg->Name); + for (i = 0; i < shProg->NumShaders; i++) { + _mesa_printf(" shader %u, type 0x%x\n", + shProg->Shaders[i]->Name, + shProg->Shaders[i]->Type); + } + if (shProg->VertexProgram) + printf(" vert prog %u\n", shProg->VertexProgram->Base.Id); + if (shProg->FragmentProgram) + printf(" frag prog %u\n", shProg->FragmentProgram->Base.Id); + } } else { shProg = NULL; @@ -1516,27 +1558,6 @@ _mesa_update_shader_textures_used(struct gl_program *prog) } -static GLboolean -is_sampler_type(GLenum type) -{ - switch (type) { - case GL_SAMPLER_1D: - case GL_SAMPLER_2D: - case GL_SAMPLER_3D: - case GL_SAMPLER_CUBE: - case GL_SAMPLER_1D_SHADOW: - case GL_SAMPLER_2D_SHADOW: - case GL_SAMPLER_2D_RECT_ARB: - case GL_SAMPLER_2D_RECT_SHADOW_ARB: - case GL_SAMPLER_1D_ARRAY_EXT: - case GL_SAMPLER_2D_ARRAY_EXT: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - /** * Check if the type given by userType is allowed to set a uniform of the * target type. Generally, equivalence is required, but setting Boolean @@ -1575,10 +1596,10 @@ compatible_types(GLenum userType, GLenum targetType) * \param program the program whose uniform to update * \param index the index of the program parameter for the uniform * \param offset additional parameter slot offset (for arrays) - * \param type the datatype of the uniform + * \param type the incoming datatype of 'values' * \param count the number of uniforms to set - * \param elems number of elements per uniform - * \param values the new values + * \param elems number of elements per uniform (1, 2, 3 or 4) + * \param values the new values, of datatype 'type' */ static void set_program_uniform(GLcontext *ctx, struct gl_program *program, @@ -1588,8 +1609,12 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program, { struct gl_program_parameter *param = &program->Parameters->Parameters[index]; + const GLboolean isUniformBool = is_boolean_type(param->DataType); + const GLboolean areIntValues = is_integer_type(type); assert(offset >= 0); + assert(elems >= 1); + assert(elems <= 4); if (!compatible_types(type, param->DataType)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(type mismatch)"); @@ -1657,16 +1682,20 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program, } } + /* loop over number of array elements */ for (k = 0; k < count; k++) { GLfloat *uniformVal; - if (offset + k > slots) { + if (offset + k >= slots) { /* Extra array data is ignored */ break; } + /* uniformVal (the destination) is always float[4] */ uniformVal = program->Parameters->ParameterValues[index + offset + k]; - if (is_integer_type(type)) { + + if (areIntValues) { + /* convert user's ints to floats */ const GLint *iValues = ((const GLint *) values) + k * elems; for (i = 0; i < elems; i++) { uniformVal[i] = (GLfloat) iValues[i]; @@ -1680,7 +1709,7 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program, } /* if the uniform is bool-valued, convert to 1.0 or 0.0 */ - if (is_boolean_type(param->DataType)) { + if (isUniformBool) { for (i = 0; i < elems; i++) { uniformVal[i] = uniformVal[i] ? 1.0f : 0.0f; } @@ -1765,7 +1794,7 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count, return; } - FLUSH_VERTICES(ctx, _NEW_PROGRAM); + FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS); uniform = &shProg->Uniforms->Uniforms[location]; @@ -1873,7 +1902,7 @@ set_program_uniform_matrix(GLcontext *ctx, struct gl_program *program, */ static void _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows, - GLenum matrixType, GLint location, GLsizei count, + GLint location, GLsizei count, GLboolean transpose, const GLfloat *values) { struct gl_shader_program *shProg = ctx->Shader.CurrentProgram; @@ -1905,7 +1934,7 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows, return; } - FLUSH_VERTICES(ctx, _NEW_PROGRAM); + FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS); uniform = &shProg->Uniforms->Uniforms[location];