diff options
author | Ian Romanick <[email protected]> | 2012-07-26 18:04:50 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2012-08-23 10:15:30 -0700 |
commit | b3dd524a1082efd12d4a796122c300a61ba016d9 (patch) | |
tree | 35587a2c38740fe91d831a7b9de62525dd04e90c /src/mesa | |
parent | 4269cace7944b465860213acbaf82ffddb91efcb (diff) |
mesa/es: Validate glTexParameter pnames in Mesa code rather than the ES wrapper
This also adds a missing extension (and API) check around
GL_TEXTURE_CROP_RECT_OES.
v2: Add proper core-profile, GLES1, and GLES3 filtering. GL_TEXTURE_MAX_LEVEL
is (incorrectly) accepted in ES contexts. A future patch will add
GL_APPLE_texture_max_level, and meta really needs this.
Signed-off-by: Ian Romanick <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/APIspec.xml | 23 | ||||
-rw-r--r-- | src/mesa/main/es1_conversion.c | 44 | ||||
-rw-r--r-- | src/mesa/main/texparam.c | 62 |
3 files changed, 54 insertions, 75 deletions
diff --git a/src/mesa/main/APIspec.xml b/src/mesa/main/APIspec.xml index c2347e52284..af98440e037 100644 --- a/src/mesa/main/APIspec.xml +++ b/src/mesa/main/APIspec.xml @@ -226,29 +226,6 @@ <param name="param" type="GLtype"/> </vector> </proto> - - <desc name="pname"> - <value name="GL_TEXTURE_WRAP_S"/> - <value name="GL_TEXTURE_WRAP_T"/> - <value name="GL_TEXTURE_WRAP_R_OES" category="OES_texture_3D"/> - <value name="GL_TEXTURE_MIN_FILTER"/> - <value name="GL_TEXTURE_MAG_FILTER"/> - <value name="GL_TEXTURE_MAX_ANISOTROPY_EXT" category="EXT_texture_filter_anisotropic"/> - </desc> - - <desc name="pname" category="GLES1.1"> - <value name="GL_GENERATE_MIPMAP"/> - - <desc name="param"> - <value name="GL_TRUE"/> - <value name="GL_FALSE"/> - </desc> - </desc> - - <desc name="pname" category="OES_draw_texture"> - <value name="GL_TEXTURE_CROP_RECT_OES"/> - <desc name="params" vector_size="4"/> - </desc> </template> <template name="TexImage2D"> diff --git a/src/mesa/main/es1_conversion.c b/src/mesa/main/es1_conversion.c index 247a038dc8d..75cdfc88711 100644 --- a/src/mesa/main/es1_conversion.c +++ b/src/mesa/main/es1_conversion.c @@ -1237,41 +1237,11 @@ _check_TexGenxvOES(GLenum coord, GLenum pname, const GLfixed *params) void GL_APIENTRY _es_TexParameterx(GLenum target, GLenum pname, GLfixed param) { - GLfloat converted_param; - bool convert_param_value = true; - - switch(pname) { - case GL_TEXTURE_WRAP_S: - case GL_TEXTURE_WRAP_T: - convert_param_value = false; - break; - case GL_TEXTURE_MIN_FILTER: - case GL_TEXTURE_MAG_FILTER: - convert_param_value = false; - break; - case GL_GENERATE_MIPMAP: - if (param != GL_TRUE && param != GL_FALSE) { - _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, - "glTexParameterx(pname=0x%x)", pname); - return; - } - convert_param_value = false; - break; - case GL_TEXTURE_MAX_ANISOTROPY_EXT: - break; - default: - _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, - "glTexParameterx(pname=0x%x)", pname); - return; - } - - if (convert_param_value) { - converted_param = (GLfloat) (param / 65536.0f); + if (pname == GL_TEXTURE_MAX_ANISOTROPY_EXT) { + _mesa_TexParameterf(target, pname, (GLfloat) (param / 65536.0f)); } else { - converted_param = (GLfloat) param; + _mesa_TexParameterf(target, pname, (GLfloat) param); } - - _mesa_TexParameterf(target, pname, converted_param); } void GL_APIENTRY @@ -1300,15 +1270,7 @@ _es_TexParameterxv(GLenum target, GLenum pname, const GLfixed *params) break; case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: - convert_params_value = false; - n_params = 1; - break; case GL_GENERATE_MIPMAP: - if (params[0] != GL_TRUE && params[0] != GL_FALSE) { - _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, - "glTexParameterxv(pname=0x%x)", pname); - return; - } convert_params_value = false; n_params = 1; break; diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index bb16228ee2c..05d31c1cfc8 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -325,6 +325,9 @@ set_tex_parameteri(struct gl_context *ctx, return GL_FALSE; case GL_TEXTURE_BASE_LEVEL: + if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) + goto invalid_pname; + if (texObj->BaseLevel == params[0]) return GL_FALSE; if (params[0] < 0 || @@ -350,6 +353,9 @@ set_tex_parameteri(struct gl_context *ctx, return GL_TRUE; case GL_GENERATE_MIPMAP_SGIS: + if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES) + goto invalid_pname; + if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES) goto invalid_param; if (texObj->GenerateMipmap != params[0]) { @@ -360,7 +366,8 @@ set_tex_parameteri(struct gl_context *ctx, return GL_FALSE; case GL_TEXTURE_COMPARE_MODE_ARB: - if (ctx->Extensions.ARB_shadow) { + if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow) + || _mesa_is_gles3(ctx)) { if (texObj->Sampler.CompareMode == params[0]) return GL_FALSE; if (params[0] == GL_NONE || @@ -374,7 +381,8 @@ set_tex_parameteri(struct gl_context *ctx, goto invalid_pname; case GL_TEXTURE_COMPARE_FUNC_ARB: - if (ctx->Extensions.ARB_shadow) { + if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow) + || _mesa_is_gles3(ctx)) { if (texObj->Sampler.CompareFunc == params[0]) return GL_FALSE; switch (params[0]) { @@ -402,7 +410,10 @@ set_tex_parameteri(struct gl_context *ctx, goto invalid_pname; case GL_DEPTH_TEXTURE_MODE_ARB: - if (ctx->Extensions.ARB_depth_texture) { + /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never + * existed in OpenGL ES. + */ + if (ctx->API == API_OPENGL && ctx->Extensions.ARB_depth_texture) { if (texObj->DepthMode == params[0]) return GL_FALSE; if (params[0] == GL_LUMINANCE || @@ -419,6 +430,9 @@ set_tex_parameteri(struct gl_context *ctx, #if FEATURE_OES_draw_texture case GL_TEXTURE_CROP_RECT_OES: + if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture) + goto invalid_pname; + texObj->CropRect[0] = params[0]; texObj->CropRect[1] = params[1]; texObj->CropRect[2] = params[2]; @@ -430,7 +444,8 @@ set_tex_parameteri(struct gl_context *ctx, case GL_TEXTURE_SWIZZLE_G_EXT: case GL_TEXTURE_SWIZZLE_B_EXT: case GL_TEXTURE_SWIZZLE_A_EXT: - if (ctx->Extensions.EXT_texture_swizzle) { + if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle) + || _mesa_is_gles3(ctx)) { const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT; const GLint swz = comp_to_swizzle(params[0]); if (swz < 0) { @@ -448,7 +463,8 @@ set_tex_parameteri(struct gl_context *ctx, goto invalid_pname; case GL_TEXTURE_SWIZZLE_RGBA_EXT: - if (ctx->Extensions.EXT_texture_swizzle) { + if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle) + || _mesa_is_gles3(ctx)) { GLuint comp; flush(ctx); for (comp = 0; comp < 4; comp++) { @@ -468,7 +484,8 @@ set_tex_parameteri(struct gl_context *ctx, goto invalid_pname; case GL_TEXTURE_SRGB_DECODE_EXT: - if (ctx->Extensions.EXT_texture_sRGB_decode) { + if (_mesa_is_desktop_gl(ctx) + && ctx->Extensions.EXT_texture_sRGB_decode) { GLenum decode = params[0]; if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) { if (texObj->Sampler.sRGBDecode != decode) { @@ -481,7 +498,8 @@ set_tex_parameteri(struct gl_context *ctx, goto invalid_pname; case GL_TEXTURE_CUBE_MAP_SEAMLESS: - if (ctx->Extensions.AMD_seamless_cubemap_per_texture) { + if (_mesa_is_desktop_gl(ctx) + && ctx->Extensions.AMD_seamless_cubemap_per_texture) { GLenum param = params[0]; if (param != GL_TRUE && param != GL_FALSE) { goto invalid_param; @@ -521,6 +539,9 @@ set_tex_parameterf(struct gl_context *ctx, { switch (pname) { case GL_TEXTURE_MIN_LOD: + if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) + goto invalid_pname; + if (texObj->Sampler.MinLod == params[0]) return GL_FALSE; flush(ctx); @@ -528,6 +549,9 @@ set_tex_parameterf(struct gl_context *ctx, return GL_TRUE; case GL_TEXTURE_MAX_LOD: + if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) + goto invalid_pname; + if (texObj->Sampler.MaxLod == params[0]) return GL_FALSE; flush(ctx); @@ -535,6 +559,9 @@ set_tex_parameterf(struct gl_context *ctx, return GL_TRUE; case GL_TEXTURE_PRIORITY: + if (ctx->API != API_OPENGL) + goto invalid_pname; + flush(ctx); texObj->Priority = CLAMP(params[0], 0.0F, 1.0F); return GL_TRUE; @@ -556,13 +583,18 @@ set_tex_parameterf(struct gl_context *ctx, else { static GLuint count = 0; if (count++ < 10) - _mesa_error(ctx, GL_INVALID_ENUM, - "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)"); + goto invalid_pname; } return GL_FALSE; case GL_TEXTURE_LOD_BIAS: - /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */ + /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. + * It was removed in core-profile, and it has never existed in OpenGL + * ES. + */ + if (ctx->API != API_OPENGL) + goto invalid_pname; + if (texObj->Sampler.LodBias != params[0]) { flush(ctx); texObj->Sampler.LodBias = params[0]; @@ -571,6 +603,9 @@ set_tex_parameterf(struct gl_context *ctx, break; case GL_TEXTURE_BORDER_COLOR: + if (!_mesa_is_desktop_gl(ctx)) + goto invalid_pname; + flush(ctx); /* ARB_texture_float disables clamping */ if (ctx->Extensions.ARB_texture_float) { @@ -587,9 +622,14 @@ set_tex_parameterf(struct gl_context *ctx, return GL_TRUE; default: - _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname); + goto invalid_pname; } return GL_FALSE; + +invalid_pname: + _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)", + _mesa_lookup_enum_by_nr(pname)); + return GL_FALSE; } |