summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2011-01-19 07:41:20 -0700
committerBrian Paul <brianp@vmware.com>2011-01-19 07:41:55 -0700
commit3ee60a3558a3546b3c3a0a9732d384afcf02994a (patch)
tree1a7ff57efb9ddeedf38d818de67277aa5b7bbf41
parent34613c66acb6143719315d409f167124c78f5cde (diff)
mesa: implement glGetShaderPrecisionFormat()
Drivers should override the default range/precision info as needed. No drivers do this yet.
-rw-r--r--src/mesa/main/context.c10
-rw-r--r--src/mesa/main/mtypes.h14
-rw-r--r--src/mesa/main/shaderapi.c49
3 files changed, 68 insertions, 5 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 958ea10a42..fe370fa369 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 a6445b1836..ac2957ac8d 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2549,6 +2549,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.
*/
struct gl_program_constants
@@ -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 2ffd8be0eb..e831175235 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;
}