From: Brian Paul Date: Wed, 19 Jan 2011 14:41:20 +0000 (-0700) Subject: mesa: implement glGetShaderPrecisionFormat() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3ee60a3558a3546b3c3a0a9732d384afcf02994a;p=mesa.git mesa: implement glGetShaderPrecisionFormat() Drivers should override the default range/precision info as needed. No drivers do this yet. --- diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 958ea10a422..fe370fa369b 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -526,6 +526,16 @@ init_program_limits(GLenum type, struct gl_program_constants *prog) prog->MaxNativeTemps = 0; prog->MaxNativeAddressRegs = 0; prog->MaxNativeParameters = 0; + + /* Set GLSL datatype range/precision info assuming IEEE float values. + * Drivers should override these defaults as needed. + */ + prog->MediumFloat.RangeMin = 127; + prog->MediumFloat.RangeMax = 127; + prog->MediumFloat.Precision = 23; + prog->LowFloat = prog->HighFloat = prog->MediumFloat; + /* assume ints are stored as floats for now */ + prog->LowInt = prog->MediumInt = prog->HighInt = prog->MediumFloat; } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index a6445b18368..ac2957ac8d5 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2548,6 +2548,17 @@ struct gl_framebuffer }; +/** + * Precision info for shader datatypes. See glGetShaderPrecisionFormat(). + */ +struct gl_precision +{ + GLushort RangeMin; /**< min value exponent */ + GLushort RangeMax; /**< max value exponent */ + GLushort Precision; /**< number of mantissa bits */ +}; + + /** * Limits for vertex and fragment programs/shaders. */ @@ -2582,6 +2593,9 @@ struct gl_program_constants GLuint MaxGeometryUniformComponents; GLuint MaxGeometryOutputVertices; GLuint MaxGeometryTotalOutputComponents; + /* ES 2.0 and GL_ARB_ES2_compatibility */ + struct gl_precision LowFloat, MediumFloat, HighFloat; + struct gl_precision LowInt, MediumInt, HighInt; }; diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 2ffd8be0eb4..e831175235e 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -1628,12 +1628,51 @@ void GLAPIENTRY _mesa_GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) { + const struct gl_program_constants *limits; + const struct gl_precision *p; GET_CURRENT_CONTEXT(ctx); - (void) shadertype; - (void) precisiontype; - (void) range; - (void) precision; - _mesa_error(ctx, GL_INVALID_OPERATION, __FUNCTION__); + + switch (shadertype) { + case GL_VERTEX_SHADER: + limits = &ctx->Const.VertexProgram; + break; + case GL_FRAGMENT_SHADER: + limits = &ctx->Const.FragmentProgram; + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, + "glGetShaderPrecisionFormat(shadertype)"); + return; + } + + switch (precisiontype) { + case GL_LOW_FLOAT: + p = &limits->LowFloat; + break; + case GL_MEDIUM_FLOAT: + p = &limits->MediumFloat; + break; + case GL_HIGH_FLOAT: + p = &limits->HighFloat; + break; + case GL_LOW_INT: + p = &limits->LowInt; + break; + case GL_MEDIUM_INT: + p = &limits->MediumInt; + break; + case GL_HIGH_INT: + p = &limits->HighInt; + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, + "glGetShaderPrecisionFormat(precisiontype)"); + return; + } + + range[0] = p->RangeMin; + range[1] = p->RangeMax; + precision[0] = p->Precision; }