diff options
author | marha <marha@users.sourceforge.net> | 2012-07-31 10:17:14 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-07-31 10:17:14 +0200 |
commit | 83da3ad0287bc51cd16ee6911fe73dc98ebe000b (patch) | |
tree | 48d48590a0b0a3770006aeda8ec2b2a45054d1f1 /mesalib/src/mesa/main | |
parent | 00e30605ffc7ac3cf1a091ff2c1f46cfefb780d7 (diff) | |
parent | bd27b3d008b0abf9ae2edcb127302728808533e4 (diff) | |
download | vcxsrv-83da3ad0287bc51cd16ee6911fe73dc98ebe000b.tar.gz vcxsrv-83da3ad0287bc51cd16ee6911fe73dc98ebe000b.tar.bz2 vcxsrv-83da3ad0287bc51cd16ee6911fe73dc98ebe000b.zip |
Merge remote-tracking branch 'origin/released'
Diffstat (limited to 'mesalib/src/mesa/main')
47 files changed, 2375 insertions, 1799 deletions
diff --git a/mesalib/src/mesa/main/api_exec.c b/mesalib/src/mesa/main/api_exec.c index 19e7f9807..81be46d5f 100644 --- a/mesalib/src/mesa/main/api_exec.c +++ b/mesalib/src/mesa/main/api_exec.c @@ -120,7 +120,7 @@ * \param exec dispatch table. */ struct _glapi_table * -_mesa_create_exec_table(void) +_mesa_create_exec_table(struct gl_context *ctx) { struct _glapi_table *exec; @@ -133,7 +133,10 @@ _mesa_create_exec_table(void) #endif /* load the dispatch slots we understand */ - SET_AlphaFunc(exec, _mesa_AlphaFunc); + if (ctx->API != API_OPENGL_CORE) { + SET_AlphaFunc(exec, _mesa_AlphaFunc); + } + SET_BlendFunc(exec, _mesa_BlendFunc); SET_Clear(exec, _mesa_Clear); SET_ClearColor(exec, _mesa_ClearColor); @@ -149,42 +152,62 @@ _mesa_create_exec_table(void) SET_Finish(exec, _mesa_Finish); SET_Flush(exec, _mesa_Flush); SET_FrontFace(exec, _mesa_FrontFace); - SET_Frustum(exec, _mesa_Frustum); + if (ctx->API != API_OPENGL_CORE) { + SET_Frustum(exec, _mesa_Frustum); + } SET_GetError(exec, _mesa_GetError); SET_GetFloatv(exec, _mesa_GetFloatv); SET_GetString(exec, _mesa_GetString); - SET_LineStipple(exec, _mesa_LineStipple); + if (ctx->API != API_OPENGL_CORE) { + SET_LineStipple(exec, _mesa_LineStipple); + } SET_LineWidth(exec, _mesa_LineWidth); - SET_LoadIdentity(exec, _mesa_LoadIdentity); - SET_LoadMatrixf(exec, _mesa_LoadMatrixf); + if (ctx->API != API_OPENGL_CORE) { + SET_LoadIdentity(exec, _mesa_LoadIdentity); + SET_LoadMatrixf(exec, _mesa_LoadMatrixf); + } SET_LogicOp(exec, _mesa_LogicOp); - SET_MatrixMode(exec, _mesa_MatrixMode); - SET_MultMatrixf(exec, _mesa_MultMatrixf); - SET_Ortho(exec, _mesa_Ortho); + if (ctx->API != API_OPENGL_CORE) { + SET_MatrixMode(exec, _mesa_MatrixMode); + SET_MultMatrixf(exec, _mesa_MultMatrixf); + SET_Ortho(exec, _mesa_Ortho); + } SET_PixelStorei(exec, _mesa_PixelStorei); - SET_PopMatrix(exec, _mesa_PopMatrix); - SET_PushMatrix(exec, _mesa_PushMatrix); - SET_Rotatef(exec, _mesa_Rotatef); - SET_Scalef(exec, _mesa_Scalef); + if (ctx->API != API_OPENGL_CORE) { + SET_PopMatrix(exec, _mesa_PopMatrix); + SET_PushMatrix(exec, _mesa_PushMatrix); + SET_Rotatef(exec, _mesa_Rotatef); + SET_Scalef(exec, _mesa_Scalef); + } SET_Scissor(exec, _mesa_Scissor); - SET_ShadeModel(exec, _mesa_ShadeModel); + if (ctx->API != API_OPENGL_CORE) { + SET_ShadeModel(exec, _mesa_ShadeModel); + } SET_StencilFunc(exec, _mesa_StencilFunc); SET_StencilMask(exec, _mesa_StencilMask); SET_StencilOp(exec, _mesa_StencilOp); - SET_TexEnvfv(exec, _mesa_TexEnvfv); - SET_TexEnvi(exec, _mesa_TexEnvi); + if (ctx->API != API_OPENGL_CORE) { + SET_TexEnvfv(exec, _mesa_TexEnvfv); + SET_TexEnvi(exec, _mesa_TexEnvi); + } SET_TexImage2D(exec, _mesa_TexImage2D); SET_TexParameteri(exec, _mesa_TexParameteri); - SET_Translatef(exec, _mesa_Translatef); + if (ctx->API != API_OPENGL_CORE) { + SET_Translatef(exec, _mesa_Translatef); + } SET_Viewport(exec, _mesa_Viewport); - _mesa_init_accum_dispatch(exec); - _mesa_init_dlist_dispatch(exec); + if (ctx->API != API_OPENGL_CORE) { + _mesa_init_accum_dispatch(exec); + _mesa_init_dlist_dispatch(exec); + } SET_ClearDepth(exec, _mesa_ClearDepth); - SET_ClearIndex(exec, _mesa_ClearIndex); - SET_ClipPlane(exec, _mesa_ClipPlane); - SET_ColorMaterial(exec, _mesa_ColorMaterial); + if (ctx->API != API_OPENGL_CORE) { + SET_ClearIndex(exec, _mesa_ClearIndex); + SET_ClipPlane(exec, _mesa_ClipPlane); + SET_ColorMaterial(exec, _mesa_ColorMaterial); + } SET_DepthFunc(exec, _mesa_DepthFunc); SET_DepthMask(exec, _mesa_DepthMask); SET_DepthRange(exec, _mesa_DepthRange); @@ -192,43 +215,53 @@ _mesa_create_exec_table(void) _mesa_init_drawpix_dispatch(exec); _mesa_init_feedback_dispatch(exec); - SET_FogCoordPointerEXT(exec, _mesa_FogCoordPointerEXT); - SET_Fogf(exec, _mesa_Fogf); - SET_Fogfv(exec, _mesa_Fogfv); - SET_Fogi(exec, _mesa_Fogi); - SET_Fogiv(exec, _mesa_Fogiv); - SET_GetClipPlane(exec, _mesa_GetClipPlane); + if (ctx->API != API_OPENGL_CORE) { + SET_FogCoordPointerEXT(exec, _mesa_FogCoordPointerEXT); + SET_Fogf(exec, _mesa_Fogf); + SET_Fogfv(exec, _mesa_Fogfv); + SET_Fogi(exec, _mesa_Fogi); + SET_Fogiv(exec, _mesa_Fogiv); + SET_GetClipPlane(exec, _mesa_GetClipPlane); + } SET_GetBooleanv(exec, _mesa_GetBooleanv); SET_GetDoublev(exec, _mesa_GetDoublev); SET_GetIntegerv(exec, _mesa_GetIntegerv); - SET_GetLightfv(exec, _mesa_GetLightfv); - SET_GetLightiv(exec, _mesa_GetLightiv); - SET_GetMaterialfv(exec, _mesa_GetMaterialfv); - SET_GetMaterialiv(exec, _mesa_GetMaterialiv); - SET_GetPolygonStipple(exec, _mesa_GetPolygonStipple); - SET_GetTexEnvfv(exec, _mesa_GetTexEnvfv); - SET_GetTexEnviv(exec, _mesa_GetTexEnviv); + if (ctx->API != API_OPENGL_CORE) { + SET_GetLightfv(exec, _mesa_GetLightfv); + SET_GetLightiv(exec, _mesa_GetLightiv); + SET_GetMaterialfv(exec, _mesa_GetMaterialfv); + SET_GetMaterialiv(exec, _mesa_GetMaterialiv); + SET_GetPolygonStipple(exec, _mesa_GetPolygonStipple); + SET_GetTexEnvfv(exec, _mesa_GetTexEnvfv); + SET_GetTexEnviv(exec, _mesa_GetTexEnviv); + } SET_GetTexLevelParameterfv(exec, _mesa_GetTexLevelParameterfv); SET_GetTexLevelParameteriv(exec, _mesa_GetTexLevelParameteriv); SET_GetTexParameterfv(exec, _mesa_GetTexParameterfv); SET_GetTexParameteriv(exec, _mesa_GetTexParameteriv); SET_GetTexImage(exec, _mesa_GetTexImage); SET_Hint(exec, _mesa_Hint); - SET_IndexMask(exec, _mesa_IndexMask); + if (ctx->API != API_OPENGL_CORE) { + SET_IndexMask(exec, _mesa_IndexMask); + } SET_IsEnabled(exec, _mesa_IsEnabled); - SET_LightModelf(exec, _mesa_LightModelf); - SET_LightModelfv(exec, _mesa_LightModelfv); - SET_LightModeli(exec, _mesa_LightModeli); - SET_LightModeliv(exec, _mesa_LightModeliv); - SET_Lightf(exec, _mesa_Lightf); - SET_Lightfv(exec, _mesa_Lightfv); - SET_Lighti(exec, _mesa_Lighti); - SET_Lightiv(exec, _mesa_Lightiv); - SET_LoadMatrixd(exec, _mesa_LoadMatrixd); + if (ctx->API != API_OPENGL_CORE) { + SET_LightModelf(exec, _mesa_LightModelf); + SET_LightModelfv(exec, _mesa_LightModelfv); + SET_LightModeli(exec, _mesa_LightModeli); + SET_LightModeliv(exec, _mesa_LightModeliv); + SET_Lightf(exec, _mesa_Lightf); + SET_Lightfv(exec, _mesa_Lightfv); + SET_Lighti(exec, _mesa_Lighti); + SET_Lightiv(exec, _mesa_Lightiv); + SET_LoadMatrixd(exec, _mesa_LoadMatrixd); + } _mesa_init_eval_dispatch(exec); - SET_MultMatrixd(exec, _mesa_MultMatrixd); + if (ctx->API != API_OPENGL_CORE) { + SET_MultMatrixd(exec, _mesa_MultMatrixd); + } _mesa_init_pixel_dispatch(exec); @@ -236,17 +269,21 @@ _mesa_create_exec_table(void) SET_PointSize(exec, _mesa_PointSize); SET_PolygonMode(exec, _mesa_PolygonMode); SET_PolygonOffset(exec, _mesa_PolygonOffset); - SET_PolygonStipple(exec, _mesa_PolygonStipple); + if (ctx->API != API_OPENGL_CORE) { + SET_PolygonStipple(exec, _mesa_PolygonStipple); + } _mesa_init_attrib_dispatch(exec); _mesa_init_rastpos_dispatch(exec); SET_ReadPixels(exec, _mesa_ReadPixels); - SET_Rotated(exec, _mesa_Rotated); - SET_Scaled(exec, _mesa_Scaled); - SET_SecondaryColorPointerEXT(exec, _mesa_SecondaryColorPointerEXT); - SET_TexEnvf(exec, _mesa_TexEnvf); - SET_TexEnviv(exec, _mesa_TexEnviv); + if (ctx->API != API_OPENGL_CORE) { + SET_Rotated(exec, _mesa_Rotated); + SET_Scaled(exec, _mesa_Scaled); + SET_SecondaryColorPointerEXT(exec, _mesa_SecondaryColorPointerEXT); + SET_TexEnvf(exec, _mesa_TexEnvf); + SET_TexEnviv(exec, _mesa_TexEnviv); + } _mesa_init_texgen_dispatch(exec); @@ -254,32 +291,42 @@ _mesa_create_exec_table(void) SET_TexParameterf(exec, _mesa_TexParameterf); SET_TexParameterfv(exec, _mesa_TexParameterfv); SET_TexParameteriv(exec, _mesa_TexParameteriv); - SET_Translated(exec, _mesa_Translated); + if (ctx->API != API_OPENGL_CORE) { + SET_Translated(exec, _mesa_Translated); + } /* 1.1 */ SET_BindTexture(exec, _mesa_BindTexture); SET_DeleteTextures(exec, _mesa_DeleteTextures); SET_GenTextures(exec, _mesa_GenTextures); #if _HAVE_FULL_GL - SET_AreTexturesResident(exec, _mesa_AreTexturesResident); - SET_ColorPointer(exec, _mesa_ColorPointer); + if (ctx->API != API_OPENGL_CORE) { + SET_AreTexturesResident(exec, _mesa_AreTexturesResident); + SET_ColorPointer(exec, _mesa_ColorPointer); + } SET_CopyTexImage1D(exec, _mesa_CopyTexImage1D); SET_CopyTexImage2D(exec, _mesa_CopyTexImage2D); SET_CopyTexSubImage1D(exec, _mesa_CopyTexSubImage1D); SET_CopyTexSubImage2D(exec, _mesa_CopyTexSubImage2D); - SET_DisableClientState(exec, _mesa_DisableClientState); - SET_EdgeFlagPointer(exec, _mesa_EdgeFlagPointer); - SET_EnableClientState(exec, _mesa_EnableClientState); - SET_GetPointerv(exec, _mesa_GetPointerv); - SET_IndexPointer(exec, _mesa_IndexPointer); - SET_InterleavedArrays(exec, _mesa_InterleavedArrays); + if (ctx->API != API_OPENGL_CORE) { + SET_DisableClientState(exec, _mesa_DisableClientState); + SET_EdgeFlagPointer(exec, _mesa_EdgeFlagPointer); + SET_EnableClientState(exec, _mesa_EnableClientState); + SET_GetPointerv(exec, _mesa_GetPointerv); + SET_IndexPointer(exec, _mesa_IndexPointer); + SET_InterleavedArrays(exec, _mesa_InterleavedArrays); + } SET_IsTexture(exec, _mesa_IsTexture); - SET_NormalPointer(exec, _mesa_NormalPointer); - SET_PrioritizeTextures(exec, _mesa_PrioritizeTextures); - SET_TexCoordPointer(exec, _mesa_TexCoordPointer); + if (ctx->API != API_OPENGL_CORE) { + SET_NormalPointer(exec, _mesa_NormalPointer); + SET_PrioritizeTextures(exec, _mesa_PrioritizeTextures); + SET_TexCoordPointer(exec, _mesa_TexCoordPointer); + } SET_TexSubImage1D(exec, _mesa_TexSubImage1D); SET_TexSubImage2D(exec, _mesa_TexSubImage2D); - SET_VertexPointer(exec, _mesa_VertexPointer); + if (ctx->API != API_OPENGL_CORE) { + SET_VertexPointer(exec, _mesa_VertexPointer); + } #endif /* 1.2 */ @@ -327,31 +374,37 @@ _mesa_create_exec_table(void) /* 11. GL_EXT_histogram */ #if 0 - SET_GetHistogramEXT(exec, _mesa_GetHistogram); - SET_GetHistogramParameterfvEXT(exec, _mesa_GetHistogramParameterfv); - SET_GetHistogramParameterivEXT(exec, _mesa_GetHistogramParameteriv); - SET_GetMinmaxEXT(exec, _mesa_GetMinmax); - SET_GetMinmaxParameterfvEXT(exec, _mesa_GetMinmaxParameterfv); - SET_GetMinmaxParameterivEXT(exec, _mesa_GetMinmaxParameteriv); + if (ctx->API != API_OPENGL_CORE) { + SET_GetHistogramEXT(exec, _mesa_GetHistogram); + SET_GetHistogramParameterfvEXT(exec, _mesa_GetHistogramParameterfv); + SET_GetHistogramParameterivEXT(exec, _mesa_GetHistogramParameteriv); + SET_GetMinmaxEXT(exec, _mesa_GetMinmax); + SET_GetMinmaxParameterfvEXT(exec, _mesa_GetMinmaxParameterfv); + SET_GetMinmaxParameterivEXT(exec, _mesa_GetMinmaxParameteriv); + } #endif /* 14. SGI_color_table */ #if 0 - SET_ColorTableSGI(exec, _mesa_ColorTable); - SET_ColorSubTableSGI(exec, _mesa_ColorSubTable); - SET_GetColorTableSGI(exec, _mesa_GetColorTable); - SET_GetColorTableParameterfvSGI(exec, _mesa_GetColorTableParameterfv); - SET_GetColorTableParameterivSGI(exec, _mesa_GetColorTableParameteriv); + if (ctx->API != API_OPENGL_CORE) { + SET_ColorTableSGI(exec, _mesa_ColorTable); + SET_ColorSubTableSGI(exec, _mesa_ColorSubTable); + SET_GetColorTableSGI(exec, _mesa_GetColorTable); + SET_GetColorTableParameterfvSGI(exec, _mesa_GetColorTableParameterfv); + SET_GetColorTableParameterivSGI(exec, _mesa_GetColorTableParameteriv); + } #endif /* 30. GL_EXT_vertex_array */ #if _HAVE_FULL_GL - SET_ColorPointerEXT(exec, _mesa_ColorPointerEXT); - SET_EdgeFlagPointerEXT(exec, _mesa_EdgeFlagPointerEXT); - SET_IndexPointerEXT(exec, _mesa_IndexPointerEXT); - SET_NormalPointerEXT(exec, _mesa_NormalPointerEXT); - SET_TexCoordPointerEXT(exec, _mesa_TexCoordPointerEXT); - SET_VertexPointerEXT(exec, _mesa_VertexPointerEXT); + if (ctx->API != API_OPENGL_CORE) { + SET_ColorPointerEXT(exec, _mesa_ColorPointerEXT); + SET_EdgeFlagPointerEXT(exec, _mesa_EdgeFlagPointerEXT); + SET_IndexPointerEXT(exec, _mesa_IndexPointerEXT); + SET_NormalPointerEXT(exec, _mesa_NormalPointerEXT); + SET_TexCoordPointerEXT(exec, _mesa_TexCoordPointerEXT); + SET_VertexPointerEXT(exec, _mesa_VertexPointerEXT); + } #endif /* 37. GL_EXT_blend_minmax */ @@ -483,10 +536,12 @@ _mesa_create_exec_table(void) /* ARB 3. GL_ARB_transpose_matrix */ #if _HAVE_FULL_GL - SET_LoadTransposeMatrixdARB(exec, _mesa_LoadTransposeMatrixdARB); - SET_LoadTransposeMatrixfARB(exec, _mesa_LoadTransposeMatrixfARB); - SET_MultTransposeMatrixdARB(exec, _mesa_MultTransposeMatrixdARB); - SET_MultTransposeMatrixfARB(exec, _mesa_MultTransposeMatrixfARB); + if (ctx->API != API_OPENGL_CORE) { + SET_LoadTransposeMatrixdARB(exec, _mesa_LoadTransposeMatrixdARB); + SET_LoadTransposeMatrixfARB(exec, _mesa_LoadTransposeMatrixfARB); + SET_MultTransposeMatrixdARB(exec, _mesa_MultTransposeMatrixdARB); + SET_MultTransposeMatrixfARB(exec, _mesa_MultTransposeMatrixfARB); + } #endif /* ARB 5. GL_ARB_multisample */ diff --git a/mesalib/src/mesa/main/api_exec.h b/mesalib/src/mesa/main/api_exec.h index 29c953f31..100e97273 100644 --- a/mesalib/src/mesa/main/api_exec.h +++ b/mesalib/src/mesa/main/api_exec.h @@ -28,12 +28,13 @@ struct _glapi_table; +struct gl_context; extern struct _glapi_table * _mesa_alloc_dispatch_table(int size); extern struct _glapi_table * -_mesa_create_exec_table(void); +_mesa_create_exec_table(struct gl_context *ctx); extern struct _glapi_table * _mesa_create_exec_table_es1(void); diff --git a/mesalib/src/mesa/main/api_validate.c b/mesalib/src/mesa/main/api_validate.c index ece0a2b4a..eaf614bdc 100644 --- a/mesalib/src/mesa/main/api_validate.c +++ b/mesalib/src/mesa/main/api_validate.c @@ -128,6 +128,7 @@ check_valid_to_render(struct gl_context *ctx, const char *function) #if FEATURE_GL case API_OPENGL: + case API_OPENGL_CORE: { const struct gl_shader_program *vsProg = ctx->Shader.CurrentVertexProgram; diff --git a/mesalib/src/mesa/main/arbprogram.c b/mesalib/src/mesa/main/arbprogram.c index b83369d9e..ae91fd5a3 100644 --- a/mesalib/src/mesa/main/arbprogram.c +++ b/mesalib/src/mesa/main/arbprogram.c @@ -138,12 +138,12 @@ _mesa_BindProgram(GLenum target, GLuint id) /* bind newProg */ if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */ _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, - (struct gl_vertex_program *) newProg); + gl_vertex_program(newProg)); } else if (target == GL_FRAGMENT_PROGRAM_NV || target == GL_FRAGMENT_PROGRAM_ARB) { _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, - (struct gl_fragment_program *) newProg); + gl_fragment_program(newProg)); } /* Never null pointers */ diff --git a/mesalib/src/mesa/main/arrayobj.h b/mesalib/src/mesa/main/arrayobj.h index e5270fa2c..4f89064bb 100644 --- a/mesalib/src/mesa/main/arrayobj.h +++ b/mesalib/src/mesa/main/arrayobj.h @@ -30,6 +30,7 @@ #include "glheader.h" #include "mtypes.h" +#include "glformats.h" struct gl_context; diff --git a/mesalib/src/mesa/main/context.c b/mesalib/src/mesa/main/context.c index d5ccce076..7616eb78b 100644 --- a/mesalib/src/mesa/main/context.c +++ b/mesalib/src/mesa/main/context.c @@ -404,8 +404,6 @@ one_time_init( struct gl_context *ctx ) _mesa_get_cpu_features(); - _mesa_init_sqrt_table(); - /* context dependence is never a one-time thing... */ _mesa_init_get_hash(ctx); @@ -433,7 +431,7 @@ one_time_init( struct gl_context *ctx ) * when an app is linked to libGLES*, there are not enough dynamic * entries. */ - if (ctx->API == API_OPENGL) + if (_mesa_is_desktop_gl(ctx)) _mesa_init_remap_table(); } @@ -628,7 +626,7 @@ _mesa_init_constants(struct gl_context *ctx) #endif /* Shading language version */ - if (ctx->API == API_OPENGL) { + if (_mesa_is_desktop_gl(ctx)) { ctx->Const.GLSLVersion = 120; _mesa_override_glsl_version(ctx); } @@ -844,7 +842,10 @@ update_default_objects(struct gl_context *ctx) static int generic_nop(void) { - _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)"); + GET_CURRENT_CONTEXT(ctx); + _mesa_error(ctx, GL_INVALID_OPERATION, + "unsupported function called " + "(unsupported extension or deprecated function?)"); return 0; } @@ -961,7 +962,8 @@ _mesa_initialize_context(struct gl_context *ctx, switch (ctx->API) { #if FEATURE_GL case API_OPENGL: - ctx->Exec = _mesa_create_exec_table(); + case API_OPENGL_CORE: + ctx->Exec = _mesa_create_exec_table(ctx); break; #endif #if FEATURE_ES1 @@ -1006,6 +1008,7 @@ _mesa_initialize_context(struct gl_context *ctx, switch (ctx->API) { case API_OPENGL: + case API_OPENGL_CORE: #if FEATURE_dlist ctx->Save = _mesa_create_save_table(); if (!ctx->Save) { @@ -1455,8 +1458,8 @@ _mesa_make_current( struct gl_context *newCtx, _glapi_set_dispatch(newCtx->CurrentDispatch); if (drawBuffer && readBuffer) { - ASSERT(drawBuffer->Name == 0); - ASSERT(readBuffer->Name == 0); + ASSERT(_mesa_is_winsys_fbo(drawBuffer)); + ASSERT(_mesa_is_winsys_fbo(readBuffer)); _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer); _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer); @@ -1464,7 +1467,7 @@ _mesa_make_current( struct gl_context *newCtx, * Only set the context's Draw/ReadBuffer fields if they're NULL * or not bound to a user-created FBO. */ - if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) { + if (!newCtx->DrawBuffer || _mesa_is_winsys_fbo(newCtx->DrawBuffer)) { _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer); /* Update the FBO's list of drawbuffers/renderbuffers. * For winsys FBOs this comes from the GL state (which may have @@ -1472,7 +1475,7 @@ _mesa_make_current( struct gl_context *newCtx, */ _mesa_update_draw_buffers(newCtx); } - if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) { + if (!newCtx->ReadBuffer || _mesa_is_winsys_fbo(newCtx->ReadBuffer)) { _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer); } diff --git a/mesalib/src/mesa/main/context.h b/mesalib/src/mesa/main/context.h index a66dd5076..6b7dafa78 100644 --- a/mesalib/src/mesa/main/context.h +++ b/mesalib/src/mesa/main/context.h @@ -290,6 +290,26 @@ do { \ /*@}*/ +/** + * Checks if the context is for Desktop GL (Compatibility or Core) + */ +static inline GLboolean +_mesa_is_desktop_gl(const struct gl_context *ctx) +{ + return ctx->API == API_OPENGL || ctx->API == API_OPENGL_CORE; +} + + +/** + * Checks if the context is for any GLES version + */ +static inline GLboolean +_mesa_is_gles(const struct gl_context *ctx) +{ + return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2; +} + + #ifdef __cplusplus } #endif diff --git a/mesalib/src/mesa/main/dlist.c b/mesalib/src/mesa/main/dlist.c index 40961b15c..510fd1e18 100644 --- a/mesalib/src/mesa/main/dlist.c +++ b/mesalib/src/mesa/main/dlist.c @@ -51,6 +51,7 @@ #endif #include "framebuffer.h" #include "glapi/glapi.h" +#include "glformats.h" #include "hash.h" #include "image.h" #include "light.h" diff --git a/mesalib/src/mesa/main/drawpix.c b/mesalib/src/mesa/main/drawpix.c index fdcbcccde..bd9837fdd 100644 --- a/mesalib/src/mesa/main/drawpix.c +++ b/mesalib/src/mesa/main/drawpix.c @@ -35,6 +35,8 @@ #include "pbo.h" #include "state.h" #include "dispatch.h" +#include "glformats.h" +#include "fbobject.h" #if FEATURE_drawpix @@ -89,7 +91,7 @@ _mesa_DrawPixels( GLsizei width, GLsizei height, * input), NVIDIA's implementation also just returns this error despite * exposing GL_EXT_texture_integer, just return an error regardless. */ - if (_mesa_is_integer_format(format)) { + if (_mesa_is_enum_format_integer(format)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels(integer format)"); goto end; } @@ -239,7 +241,8 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height, goto end; } - if (ctx->ReadBuffer->Name != 0 && ctx->ReadBuffer->Visual.samples > 0) { + if (_mesa_is_user_fbo(ctx->ReadBuffer) && + ctx->ReadBuffer->Visual.samples > 0) { _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyPixels(multisample FBO)"); goto end; diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c index 0675ce75d..a7b481ca7 100644 --- a/mesalib/src/mesa/main/extensions.c +++ b/mesalib/src/mesa/main/extensions.c @@ -41,7 +41,9 @@ enum { DISABLE = 0, - GL = 1 << API_OPENGL, + GLL = 1 << API_OPENGL, /* GL Legacy / Compatibility */ + GLC = 1 << API_OPENGL_CORE, /* GL Core */ + GL = (1 << API_OPENGL) | (1 << API_OPENGL_CORE), ES1 = 1 << API_OPENGLES, ES2 = 1 << API_OPENGLES2, }; diff --git a/mesalib/src/mesa/main/fbobject.c b/mesalib/src/mesa/main/fbobject.c index 4370c7218..eb03b0918 100644 --- a/mesalib/src/mesa/main/fbobject.c +++ b/mesalib/src/mesa/main/fbobject.c @@ -38,8 +38,8 @@ #include "fbobject.h" #include "formats.h" #include "framebuffer.h" +#include "glformats.h" #include "hash.h" -#include "image.h" #include "macros.h" #include "mfeatures.h" #include "mtypes.h" @@ -164,10 +164,10 @@ get_framebuffer_target(struct gl_context *ctx, GLenum target) { switch (target) { case GL_DRAW_FRAMEBUFFER: - return ctx->Extensions.EXT_framebuffer_blit && ctx->API == API_OPENGL + return ctx->Extensions.EXT_framebuffer_blit && _mesa_is_desktop_gl(ctx) ? ctx->DrawBuffer : NULL; case GL_READ_FRAMEBUFFER: - return ctx->Extensions.EXT_framebuffer_blit && ctx->API == API_OPENGL + return ctx->Extensions.EXT_framebuffer_blit && _mesa_is_desktop_gl(ctx) ? ctx->ReadBuffer : NULL; case GL_FRAMEBUFFER_EXT: return ctx->DrawBuffer; @@ -221,7 +221,7 @@ _mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb, } return &fb->Attachment[BUFFER_COLOR0 + i]; case GL_DEPTH_STENCIL_ATTACHMENT: - if (ctx->API != API_OPENGL) + if (!_mesa_is_desktop_gl(ctx)) return NULL; /* fall-through */ case GL_DEPTH_ATTACHMENT_EXT: @@ -817,7 +817,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx, } #if FEATURE_GL - if (ctx->API == API_OPENGL && !ctx->Extensions.ARB_ES2_compatibility) { + if (_mesa_is_desktop_gl(ctx) && !ctx->Extensions.ARB_ES2_compatibility) { /* Check that all DrawBuffers are present */ for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) { if (fb->ColorDrawBuffer[j] != GL_NONE) { @@ -2289,7 +2289,7 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, ASSERT_OUTSIDE_BEGIN_END(ctx); /* The error differs in GL and GLES. */ - err = ctx->API == API_OPENGL ? GL_INVALID_OPERATION : GL_INVALID_ENUM; + err = _mesa_is_desktop_gl(ctx) ? GL_INVALID_OPERATION : GL_INVALID_ENUM; buffer = get_framebuffer_target(ctx, target); if (!buffer) { @@ -2309,7 +2309,7 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, * OES_framebuffer_object spec refers to the EXT_framebuffer_object * spec. */ - if (ctx->API != API_OPENGL || !ctx->Extensions.ARB_framebuffer_object) { + if (!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_framebuffer_object) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetFramebufferAttachmentParameteriv(bound FBO = 0)"); return; @@ -2357,7 +2357,7 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, } else { assert(att->Type == GL_NONE); - if (ctx->API == API_OPENGL) { + if (_mesa_is_desktop_gl(ctx)) { *params = 0; } else { _mesa_error(ctx, GL_INVALID_ENUM, @@ -2633,6 +2633,116 @@ compatible_color_datatypes(gl_format srcFormat, gl_format dstFormat) /** + * Return the equivalent non-generic internal format. + * This is useful for comparing whether two internal formats are semantically + * equivalent. + */ +static GLenum +get_nongeneric_internalformat(GLenum format) +{ + switch (format) { + /* GL 1.1 formats. */ + case 4: + case GL_RGBA: + return GL_RGBA8; + + case 3: + case GL_RGB: + return GL_RGB8; + + case 2: + case GL_LUMINANCE_ALPHA: + return GL_LUMINANCE8_ALPHA8; + + case 1: + case GL_LUMINANCE: + return GL_LUMINANCE8; + + case GL_ALPHA: + return GL_ALPHA8; + + case GL_INTENSITY: + return GL_INTENSITY8; + + /* GL_ARB_texture_rg */ + case GL_RED: + return GL_R8; + + case GL_RG: + return GL_RG8; + + /* GL_EXT_texture_sRGB */ + case GL_SRGB: + return GL_SRGB8; + + case GL_SRGB_ALPHA: + return GL_SRGB8_ALPHA8; + + case GL_SLUMINANCE: + return GL_SLUMINANCE8; + + case GL_SLUMINANCE_ALPHA: + return GL_SLUMINANCE8_ALPHA8; + + /* GL_EXT_texture_snorm */ + case GL_RGBA_SNORM: + return GL_RGBA8_SNORM; + + case GL_RGB_SNORM: + return GL_RGB8_SNORM; + + case GL_RG_SNORM: + return GL_RG8_SNORM; + + case GL_RED_SNORM: + return GL_R8_SNORM; + + case GL_LUMINANCE_ALPHA_SNORM: + return GL_LUMINANCE8_ALPHA8_SNORM; + + case GL_LUMINANCE_SNORM: + return GL_LUMINANCE8_SNORM; + + case GL_ALPHA_SNORM: + return GL_ALPHA8_SNORM; + + case GL_INTENSITY_SNORM: + return GL_INTENSITY8_SNORM; + + default: + return format; + } +} + + +static GLboolean +compatible_resolve_formats(const struct gl_renderbuffer *colorReadRb, + const struct gl_renderbuffer *colorDrawRb) +{ + /* The simple case where we know the backing formats are the same. + */ + if (colorReadRb->Format == colorDrawRb->Format) { + return GL_TRUE; + } + + /* The Mesa formats are different, so we must check whether the internal + * formats are compatible. + * + * Under some circumstances, the user may request e.g. two GL_RGBA8 + * textures and get two entirely different Mesa formats like RGBA8888 and + * ARGB8888. Drivers behaving like that should be able to cope with + * non-matching formats by themselves, because it's not the user's fault. + */ + if (get_nongeneric_internalformat(colorReadRb->InternalFormat) == + get_nongeneric_internalformat(colorDrawRb->InternalFormat)) { + return GL_TRUE; + } + + return GL_FALSE; +} + + +/** * Blit rectangular region, optionally from one framebuffer to another. * * Note, if the src buffer is multisampled and the dest is not, this is @@ -2798,7 +2908,7 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, /* color formats must match */ if (colorReadRb && colorDrawRb && - colorReadRb->Format != colorDrawRb->Format) { + !compatible_resolve_formats(colorReadRb, colorDrawRb)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT(bad src/dst multisample pixel formats)"); return; diff --git a/mesalib/src/mesa/main/ffvertex_prog.c b/mesalib/src/mesa/main/ffvertex_prog.c index 557768311..e5ab20145 100644 --- a/mesalib/src/mesa/main/ffvertex_prog.c +++ b/mesalib/src/mesa/main/ffvertex_prog.c @@ -1572,7 +1572,7 @@ static void build_array_pointsize( struct tnl_program *p ) static void build_tnl_program( struct tnl_program *p ) { - /* Emit the program, starting with modelviewproject: + /* Emit the program, starting with the modelview, projection transforms: */ build_hpos(p); @@ -1658,7 +1658,6 @@ create_new_program( const struct state_key *key, /** * Return a vertex program which implements the current fixed-function * transform/lighting/texgen operations. - * XXX move this into core mesa (main/) */ struct gl_vertex_program * _mesa_get_fixed_func_vertex_program(struct gl_context *ctx) @@ -1672,16 +1671,15 @@ _mesa_get_fixed_func_vertex_program(struct gl_context *ctx) /* Look for an already-prepared program for this state: */ - prog = (struct gl_vertex_program *) - _mesa_search_program_cache(ctx->VertexProgram.Cache, &key, sizeof(key)); + prog = gl_vertex_program( + _mesa_search_program_cache(ctx->VertexProgram.Cache, &key, sizeof(key))); if (!prog) { /* OK, we'll have to build a new one */ if (0) printf("Build new TNL program\n"); - prog = (struct gl_vertex_program *) - ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); + prog = gl_vertex_program(ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0)); if (!prog) return NULL; diff --git a/mesalib/src/mesa/main/format_pack.c b/mesalib/src/mesa/main/format_pack.c index 7f0bda127..be6c026e8 100644 --- a/mesalib/src/mesa/main/format_pack.c +++ b/mesalib/src/mesa/main/format_pack.c @@ -1005,6 +1005,32 @@ pack_float_ARGB2101010(const GLfloat src[4], void *dst) } +/* MESA_FORMAT_ABGR2101010_UINT */ + +static void +pack_ubyte_ABGR2101010_UINT(const GLubyte src[4], void *dst) +{ + GLuint *d = ((GLuint *) dst); + GLushort r = UBYTE_TO_USHORT(src[RCOMP]); + GLushort g = UBYTE_TO_USHORT(src[GCOMP]); + GLushort b = UBYTE_TO_USHORT(src[BCOMP]); + GLushort a = UBYTE_TO_USHORT(src[ACOMP]); + *d = PACK_COLOR_2101010_US(a, b, g, r); +} + +static void +pack_float_ABGR2101010_UINT(const GLfloat src[4], void *dst) +{ + GLuint *d = ((GLuint *) dst); + GLushort r, g, b, a; + UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]); + UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]); + UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]); + UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]); + *d = PACK_COLOR_2101010_US(a, b, g, r); +} + + /* MESA_FORMAT_SRGB8 */ static void @@ -1696,6 +1722,7 @@ _mesa_get_pack_ubyte_rgba_function(gl_format format) table[MESA_FORMAT_RG1616] = pack_ubyte_RG1616; table[MESA_FORMAT_RG1616_REV] = pack_ubyte_RG1616_REV; table[MESA_FORMAT_ARGB2101010] = pack_ubyte_ARGB2101010; + table[MESA_FORMAT_ABGR2101010_UINT] = pack_ubyte_ABGR2101010_UINT; /* should never convert RGBA to these formats */ table[MESA_FORMAT_Z24_S8] = NULL; @@ -1841,6 +1868,7 @@ _mesa_get_pack_float_rgba_function(gl_format format) table[MESA_FORMAT_RG1616] = pack_float_RG1616; table[MESA_FORMAT_RG1616_REV] = pack_float_RG1616_REV; table[MESA_FORMAT_ARGB2101010] = pack_float_ARGB2101010; + table[MESA_FORMAT_ABGR2101010_UINT] = pack_float_ABGR2101010_UINT; /* should never convert RGBA to these formats */ table[MESA_FORMAT_Z24_S8] = NULL; diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c index c42bac19c..529c416a8 100644 --- a/mesalib/src/mesa/main/format_unpack.c +++ b/mesalib/src/mesa/main/format_unpack.c @@ -610,6 +610,20 @@ unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n) static void +unpack_ABGR2101010_UINT(const void *src, GLfloat dst[][4], GLuint n) +{ + const GLuint *s = ((const GLuint *) src); + GLuint i; + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLfloat)((s[i] >> 0) & 0x3ff); + dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff); + dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff); + dst[i][ACOMP] = (GLfloat)((s[i] >> 30) & 0x03); + } +} + + +static void unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n) { /* only return Z, not stencil data */ @@ -1499,6 +1513,7 @@ get_unpack_rgba_function(gl_format format) table[MESA_FORMAT_RG1616] = unpack_RG1616; table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV; table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010; + table[MESA_FORMAT_ABGR2101010_UINT] = unpack_ABGR2101010_UINT; table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8; table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24; table[MESA_FORMAT_Z16] = unpack_Z16; @@ -2139,6 +2154,32 @@ unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n) } static void +unpack_int_rgba_ARGB8888(const GLbyte *src, GLuint dst[][4], GLuint n) +{ + unsigned int i; + + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLubyte) src[i * 4 + 2]; + dst[i][GCOMP] = (GLubyte) src[i * 4 + 1]; + dst[i][BCOMP] = (GLubyte) src[i * 4 + 0]; + dst[i][ACOMP] = (GLubyte) src[i * 4 + 3]; + } +} + +static void +unpack_int_rgba_XRGB8888(const GLbyte *src, GLuint dst[][4], GLuint n) +{ + unsigned int i; + + for (i = 0; i < n; i++) { + dst[i][RCOMP] = (GLubyte) src[i * 4 + 2]; + dst[i][GCOMP] = (GLubyte) src[i * 4 + 1]; + dst[i][BCOMP] = (GLubyte) src[i * 4 + 0]; + dst[i][ACOMP] = (GLubyte) 0xff; + } +} + +static void unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n) { unsigned int i; @@ -2563,6 +2604,20 @@ unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n) } } +static void +unpack_int_rgba_ABGR2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n) +{ + unsigned int i; + + for (i = 0; i < n; i++) { + GLuint tmp = src[i]; + dst[i][0] = (tmp >> 0) & 0x3ff; + dst[i][1] = (tmp >> 10) & 0x3ff; + dst[i][2] = (tmp >> 20) & 0x3ff; + dst[i][3] = (tmp >> 30) & 0x3; + } +} + void _mesa_unpack_uint_rgba_row(gl_format format, GLuint n, const void *src, GLuint dst[][4]) @@ -2590,6 +2645,14 @@ _mesa_unpack_uint_rgba_row(gl_format format, GLuint n, unpack_int_rgba_RGBA_INT8(src, dst, n); break; + case MESA_FORMAT_ARGB8888: + unpack_int_rgba_ARGB8888(src, dst, n); + break; + + case MESA_FORMAT_XRGB8888: + unpack_int_rgba_XRGB8888(src, dst, n); + break; + case MESA_FORMAT_RGB_UINT32: case MESA_FORMAT_RGB_INT32: unpack_int_rgba_RGB_UINT32(src, dst, n); @@ -2725,6 +2788,11 @@ _mesa_unpack_uint_rgba_row(gl_format format, GLuint n, case MESA_FORMAT_ARGB2101010_UINT: unpack_int_rgba_ARGB2101010_UINT(src, dst, n); break; + + case MESA_FORMAT_ABGR2101010_UINT: + unpack_int_rgba_ABGR2101010_UINT(src, dst, n); + break; + default: _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__, _mesa_get_format_name(format)); diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c index c65c9c2e1..1fa641c92 100644 --- a/mesalib/src/mesa/main/formats.c +++ b/mesalib/src/mesa/main/formats.c @@ -28,6 +28,7 @@ #include "formats.h" #include "mfeatures.h" #include "macros.h" +#include "glformats.h" /** @@ -1519,6 +1520,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 0, 0, 0, 0, 0, 1, 1, 4 }, + { + MESA_FORMAT_ABGR2101010_UINT, + "MESA_FORMAT_ABGR2101010_UINT", + GL_RGBA, + GL_UNSIGNED_INT, + 10, 10, 10, 2, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, }; @@ -1712,6 +1722,17 @@ _mesa_is_format_integer_color(gl_format format) /** + * Is the given format an unsigned integer format? + */ +GLboolean +_mesa_is_format_unsigned(gl_format format) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + return _mesa_is_type_unsigned(info->DataType); +} + + +/** * Return color encoding for given format. * \return GL_LINEAR or GL_SRGB */ @@ -2491,6 +2512,7 @@ _mesa_format_to_type_and_comps(gl_format format, return; case MESA_FORMAT_ARGB2101010_UINT: + case MESA_FORMAT_ABGR2101010_UINT: *datatype = GL_UNSIGNED_INT_2_10_10_10_REV; *comps = 4; return; @@ -2916,6 +2938,11 @@ _mesa_format_matches_format_and_type(gl_format gl_format, type == GL_UNSIGNED_INT_2_10_10_10_REV && !swapBytes); + case MESA_FORMAT_ABGR2101010_UINT: + return (format == GL_RGBA_INTEGER_EXT && + type == GL_UNSIGNED_INT_2_10_10_10_REV && + !swapBytes); + case MESA_FORMAT_RGB9_E5_FLOAT: return format == GL_RGB && type == GL_UNSIGNED_INT_5_9_9_9_REV && !swapBytes; @@ -2933,3 +2960,4 @@ _mesa_format_matches_format_and_type(gl_format gl_format, return GL_FALSE; } + diff --git a/mesalib/src/mesa/main/formats.h b/mesalib/src/mesa/main/formats.h index 3a694a813..1843eb6fc 100644 --- a/mesalib/src/mesa/main/formats.h +++ b/mesalib/src/mesa/main/formats.h @@ -276,6 +276,7 @@ typedef enum MESA_FORMAT_Z32_FLOAT_X24S8, MESA_FORMAT_ARGB2101010_UINT, + MESA_FORMAT_ABGR2101010_UINT, MESA_FORMAT_COUNT } gl_format; @@ -311,6 +312,9 @@ _mesa_is_format_packed_depth_stencil(gl_format format); extern GLboolean _mesa_is_format_integer_color(gl_format format); +extern GLboolean +_mesa_is_format_unsigned(gl_format format); + extern GLenum _mesa_get_format_color_encoding(gl_format format); @@ -346,7 +350,6 @@ _mesa_format_matches_format_and_type(gl_format gl_format, GLenum format, GLenum type, GLboolean swapBytes); - #ifdef __cplusplus } #endif diff --git a/mesalib/src/mesa/main/framebuffer.c b/mesalib/src/mesa/main/framebuffer.c index ea14148de..13887f8f5 100644 --- a/mesalib/src/mesa/main/framebuffer.c +++ b/mesalib/src/mesa/main/framebuffer.c @@ -347,7 +347,7 @@ _mesa_resizebuffers( struct gl_context *ctx ) GLuint newWidth, newHeight; struct gl_framebuffer *buffer = ctx->WinSysDrawBuffer; - assert(buffer->Name == 0); + assert(_mesa_is_winsys_fbo(buffer)); /* ask device driver for size of output buffer */ ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight ); @@ -364,7 +364,7 @@ _mesa_resizebuffers( struct gl_context *ctx ) GLuint newWidth, newHeight; struct gl_framebuffer *buffer = ctx->WinSysReadBuffer; - assert(buffer->Name == 0); + assert(_mesa_is_winsys_fbo(buffer)); /* ask device driver for size of read buffer */ ctx->Driver.GetBufferSize( buffer, &newWidth, &newHeight ); @@ -444,7 +444,7 @@ _mesa_update_draw_buffer_bounds(struct gl_context *ctx) if (!buffer) return; - if (buffer->Name) { + if (_mesa_is_user_fbo(buffer)) { /* user-created framebuffer size depends on the renderbuffers */ update_framebuffer_size(ctx, buffer); } @@ -517,6 +517,13 @@ _mesa_update_framebuffer_visual(struct gl_context *ctx, const GLenum baseFormat = _mesa_get_format_base_format(rb->Format); const gl_format fmt = rb->Format; + /* Grab samples and sampleBuffers from any attachment point (assuming + * the framebuffer is complete, we'll get the same answer from all + * attachments). + */ + fb->Visual.samples = rb->NumSamples; + fb->Visual.sampleBuffers = rb->NumSamples > 0 ? 1 : 0; + if (_mesa_is_legal_color_format(ctx, baseFormat)) { fb->Visual.redBits = _mesa_get_format_bits(fmt, GL_RED_BITS); fb->Visual.greenBits = _mesa_get_format_bits(fmt, GL_GREEN_BITS); @@ -524,8 +531,6 @@ _mesa_update_framebuffer_visual(struct gl_context *ctx, fb->Visual.alphaBits = _mesa_get_format_bits(fmt, GL_ALPHA_BITS); fb->Visual.rgbBits = fb->Visual.redBits + fb->Visual.greenBits + fb->Visual.blueBits; - fb->Visual.samples = rb->NumSamples; - fb->Visual.sampleBuffers = rb->NumSamples > 0 ? 1 : 0; if (_mesa_get_format_color_encoding(fmt) == GL_SRGB) fb->Visual.sRGBCapable = ctx->Extensions.EXT_framebuffer_sRGB; break; diff --git a/mesalib/src/mesa/main/get.c b/mesalib/src/mesa/main/get.c index 15de321e4..b9c98fb22 100644 --- a/mesalib/src/mesa/main/get.c +++ b/mesalib/src/mesa/main/get.c @@ -391,6 +391,7 @@ extra_NV_read_buffer_api_gl[] = { #define API_OPENGL_BIT (1 << API_OPENGL) #define API_OPENGLES_BIT (1 << API_OPENGLES) #define API_OPENGLES2_BIT (1 << API_OPENGLES2) +#define API_OPENGL_CORE_BIT (1 << API_OPENGL_CORE) /* This is the big table describing all the enums we accept in * glGet*v(). The table is partitioned into six parts: enums @@ -405,7 +406,9 @@ extra_NV_read_buffer_api_gl[] = { static const struct value_desc values[] = { /* Enums shared between OpenGL, GLES1 and GLES2 */ { 0, 0, TYPE_API_MASK, - API_OPENGL_BIT | API_OPENGLES_BIT | API_OPENGLES2_BIT, NO_EXTRA}, + API_OPENGL_BIT | API_OPENGLES_BIT | API_OPENGLES2_BIT | + API_OPENGL_CORE_BIT, + NO_EXTRA}, { GL_ALPHA_BITS, BUFFER_INT(Visual.alphaBits), extra_new_buffers }, { GL_BLEND, CONTEXT_BIT0(Color.BlendEnabled), NO_EXTRA }, { GL_BLEND_SRC, CONTEXT_ENUM(Color.Blend[0].SrcRGB), NO_EXTRA }, @@ -534,7 +537,7 @@ static const struct value_desc values[] = { #if FEATURE_GL || FEATURE_ES1 /* Enums in OpenGL and GLES1 */ - { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGLES_BIT, NO_EXTRA }, + { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGLES_BIT | API_OPENGL_CORE_BIT, NO_EXTRA }, { GL_MAX_LIGHTS, CONTEXT_INT(Const.MaxLights), NO_EXTRA }, { GL_LIGHT0, CONTEXT_BOOL(Light.Light[0].Enabled), NO_EXTRA }, { GL_LIGHT1, CONTEXT_BOOL(Light.Light[1].Enabled), NO_EXTRA }, @@ -796,7 +799,7 @@ static const struct value_desc values[] = { #if FEATURE_GL /* Remaining enums are only in OpenGL */ - { 0, 0, TYPE_API_MASK, API_OPENGL_BIT, NO_EXTRA }, + { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGL_CORE_BIT, NO_EXTRA }, { GL_ACCUM_RED_BITS, BUFFER_INT(Visual.accumRedBits), NO_EXTRA }, { GL_ACCUM_GREEN_BITS, BUFFER_INT(Visual.accumGreenBits), NO_EXTRA }, { GL_ACCUM_BLUE_BITS, BUFFER_INT(Visual.accumBlueBits), NO_EXTRA }, @@ -1887,7 +1890,7 @@ check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d } break; case EXTRA_API_GL: - if (ctx->API == API_OPENGL) { + if (_mesa_is_desktop_gl(ctx)) { total++; enabled++; } diff --git a/mesalib/src/mesa/main/getstring.c b/mesalib/src/mesa/main/getstring.c index 2f445aaf9..c6f400af5 100644 --- a/mesalib/src/mesa/main/getstring.c +++ b/mesalib/src/mesa/main/getstring.c @@ -41,6 +41,7 @@ shading_language_version(struct gl_context *ctx) { switch (ctx->API) { case API_OPENGL: + case API_OPENGL_CORE: if (!ctx->Extensions.ARB_shader_objects) { _mesa_error(ctx, GL_INVALID_ENUM, "glGetString"); return (const GLubyte *) 0; diff --git a/mesalib/src/mesa/main/glformats.c b/mesalib/src/mesa/main/glformats.c new file mode 100644 index 000000000..4fe0ae078 --- /dev/null +++ b/mesalib/src/mesa/main/glformats.c @@ -0,0 +1,1329 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (c) 2008-2009 VMware, Inc. + * Copyright (c) 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include "context.h" +#include "glformats.h" + + +/** + * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise. + */ +GLboolean +_mesa_type_is_packed(GLenum type) +{ + switch (type) { + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case MESA_UNSIGNED_BYTE_4_4: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + case GL_UNSIGNED_SHORT_8_8_MESA: + case GL_UNSIGNED_SHORT_8_8_REV_MESA: + case GL_UNSIGNED_INT_24_8_EXT: + case GL_UNSIGNED_INT_5_9_9_9_REV: + case GL_UNSIGNED_INT_10F_11F_11F_REV: + case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + return GL_TRUE; + } + + return GL_FALSE; +} + + +/** + * Get the size of a GL data type. + * + * \param type GL data type. + * + * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1 + * if an invalid type enum. + */ +GLint +_mesa_sizeof_type(GLenum type) +{ + switch (type) { + case GL_BITMAP: + return 0; + case GL_UNSIGNED_BYTE: + return sizeof(GLubyte); + case GL_BYTE: + return sizeof(GLbyte); + case GL_UNSIGNED_SHORT: + return sizeof(GLushort); + case GL_SHORT: + return sizeof(GLshort); + case GL_UNSIGNED_INT: + return sizeof(GLuint); + case GL_INT: + return sizeof(GLint); + case GL_FLOAT: + return sizeof(GLfloat); + case GL_DOUBLE: + return sizeof(GLdouble); + case GL_HALF_FLOAT_ARB: + return sizeof(GLhalfARB); + case GL_FIXED: + return sizeof(GLfixed); + default: + return -1; + } +} + + +/** + * Same as _mesa_sizeof_type() but also accepting the packed pixel + * format data types. + */ +GLint +_mesa_sizeof_packed_type(GLenum type) +{ + switch (type) { + case GL_BITMAP: + return 0; + case GL_UNSIGNED_BYTE: + return sizeof(GLubyte); + case GL_BYTE: + return sizeof(GLbyte); + case GL_UNSIGNED_SHORT: + return sizeof(GLushort); + case GL_SHORT: + return sizeof(GLshort); + case GL_UNSIGNED_INT: + return sizeof(GLuint); + case GL_INT: + return sizeof(GLint); + case GL_HALF_FLOAT_ARB: + return sizeof(GLhalfARB); + case GL_FLOAT: + return sizeof(GLfloat); + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case MESA_UNSIGNED_BYTE_4_4: + return sizeof(GLubyte); + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_SHORT_8_8_MESA: + case GL_UNSIGNED_SHORT_8_8_REV_MESA: + return sizeof(GLushort); + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + case GL_UNSIGNED_INT_24_8_EXT: + case GL_UNSIGNED_INT_5_9_9_9_REV: + case GL_UNSIGNED_INT_10F_11F_11F_REV: + return sizeof(GLuint); + case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + return 8; + default: + return -1; + } +} + + +/** + * Get the number of components in a pixel format. + * + * \param format pixel format. + * + * \return the number of components in the given format, or -1 if a bad format. + */ +GLint +_mesa_components_in_format(GLenum format) +{ + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + case GL_RED: + case GL_RED_INTEGER_EXT: + case GL_GREEN: + case GL_GREEN_INTEGER_EXT: + case GL_BLUE: + case GL_BLUE_INTEGER_EXT: + case GL_ALPHA: + case GL_ALPHA_INTEGER_EXT: + case GL_LUMINANCE: + case GL_LUMINANCE_INTEGER_EXT: + case GL_INTENSITY: + return 1; + + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + case GL_RG: + case GL_YCBCR_MESA: + case GL_DEPTH_STENCIL_EXT: + case GL_DUDV_ATI: + case GL_DU8DV8_ATI: + case GL_RG_INTEGER: + return 2; + + case GL_RGB: + case GL_BGR: + case GL_RGB_INTEGER_EXT: + case GL_BGR_INTEGER_EXT: + return 3; + + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + case GL_RGBA_INTEGER_EXT: + case GL_BGRA_INTEGER_EXT: + return 4; + + default: + return -1; + } +} + + +/** + * Get the bytes per pixel of pixel format type pair. + * + * \param format pixel format. + * \param type pixel type. + * + * \return bytes per pixel, or -1 if a bad format or type was given. + */ +GLint +_mesa_bytes_per_pixel(GLenum format, GLenum type) +{ + GLint comps = _mesa_components_in_format(format); + if (comps < 0) + return -1; + + switch (type) { + case GL_BITMAP: + return 0; /* special case */ + case GL_BYTE: + case GL_UNSIGNED_BYTE: + return comps * sizeof(GLubyte); + case GL_SHORT: + case GL_UNSIGNED_SHORT: + return comps * sizeof(GLshort); + case GL_INT: + case GL_UNSIGNED_INT: + return comps * sizeof(GLint); + case GL_FLOAT: + return comps * sizeof(GLfloat); + case GL_HALF_FLOAT_ARB: + return comps * sizeof(GLhalfARB); + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + if (format == GL_RGB || format == GL_BGR || + format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT) + return sizeof(GLubyte); + else + return -1; /* error */ + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + if (format == GL_RGB || format == GL_BGR || + format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT) + return sizeof(GLushort); + else + return -1; /* error */ + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT || + format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) + return sizeof(GLushort); + else + return -1; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT || + format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) + return sizeof(GLuint); + else + return -1; + case GL_UNSIGNED_SHORT_8_8_MESA: + case GL_UNSIGNED_SHORT_8_8_REV_MESA: + if (format == GL_YCBCR_MESA) + return sizeof(GLushort); + else + return -1; + case GL_UNSIGNED_INT_24_8_EXT: + if (format == GL_DEPTH_STENCIL_EXT) + return sizeof(GLuint); + else + return -1; + case GL_UNSIGNED_INT_5_9_9_9_REV: + if (format == GL_RGB) + return sizeof(GLuint); + else + return -1; + case GL_UNSIGNED_INT_10F_11F_11F_REV: + if (format == GL_RGB) + return sizeof(GLuint); + else + return -1; + case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + if (format == GL_DEPTH_STENCIL) + return 8; + else + return -1; + default: + return -1; + } +} + + +/** + * Test if the given format is an integer (non-normalized) format. + */ +GLboolean +_mesa_is_enum_format_integer(GLenum format) +{ + switch (format) { + /* generic integer formats */ + case GL_RED_INTEGER_EXT: + case GL_GREEN_INTEGER_EXT: + case GL_BLUE_INTEGER_EXT: + case GL_ALPHA_INTEGER_EXT: + case GL_RGB_INTEGER_EXT: + case GL_RGBA_INTEGER_EXT: + case GL_BGR_INTEGER_EXT: + case GL_BGRA_INTEGER_EXT: + case GL_LUMINANCE_INTEGER_EXT: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + case GL_RG_INTEGER: + /* specific integer formats */ + case GL_RGBA32UI_EXT: + case GL_RGB32UI_EXT: + case GL_RG32UI: + case GL_R32UI: + case GL_ALPHA32UI_EXT: + case GL_INTENSITY32UI_EXT: + case GL_LUMINANCE32UI_EXT: + case GL_LUMINANCE_ALPHA32UI_EXT: + case GL_RGBA16UI_EXT: + case GL_RGB16UI_EXT: + case GL_RG16UI: + case GL_R16UI: + case GL_ALPHA16UI_EXT: + case GL_INTENSITY16UI_EXT: + case GL_LUMINANCE16UI_EXT: + case GL_LUMINANCE_ALPHA16UI_EXT: + case GL_RGBA8UI_EXT: + case GL_RGB8UI_EXT: + case GL_RG8UI: + case GL_R8UI: + case GL_ALPHA8UI_EXT: + case GL_INTENSITY8UI_EXT: + case GL_LUMINANCE8UI_EXT: + case GL_LUMINANCE_ALPHA8UI_EXT: + case GL_RGBA32I_EXT: + case GL_RGB32I_EXT: + case GL_RG32I: + case GL_R32I: + case GL_ALPHA32I_EXT: + case GL_INTENSITY32I_EXT: + case GL_LUMINANCE32I_EXT: + case GL_LUMINANCE_ALPHA32I_EXT: + case GL_RGBA16I_EXT: + case GL_RGB16I_EXT: + case GL_RG16I: + case GL_R16I: + case GL_ALPHA16I_EXT: + case GL_INTENSITY16I_EXT: + case GL_LUMINANCE16I_EXT: + case GL_LUMINANCE_ALPHA16I_EXT: + case GL_RGBA8I_EXT: + case GL_RGB8I_EXT: + case GL_RG8I: + case GL_R8I: + case GL_ALPHA8I_EXT: + case GL_INTENSITY8I_EXT: + case GL_LUMINANCE8I_EXT: + case GL_LUMINANCE_ALPHA8I_EXT: + case GL_RGB10_A2UI: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if the given type is an integer (non-normalized) format. + */ +GLboolean +_mesa_is_type_integer(GLenum type) +{ + switch (type) { + case GL_INT: + case GL_UNSIGNED_INT: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_BYTE: + case GL_UNSIGNED_BYTE: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if the given format or type is an integer (non-normalized) format. + */ +extern GLboolean +_mesa_is_enum_format_or_type_integer(GLenum format, GLenum type) +{ + return _mesa_is_enum_format_integer(format) || _mesa_is_type_integer(type); +} + + +GLboolean +_mesa_is_type_unsigned(GLenum type) +{ + switch (type) { + case GL_UNSIGNED_INT: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + + case GL_UNSIGNED_SHORT: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_SHORT_8_8_MESA: + case GL_UNSIGNED_SHORT_8_8_REV_MESA: + + case GL_UNSIGNED_BYTE: + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + return GL_TRUE; + + default: + return GL_FALSE; + } +} + + +/** + * Test if the given image format is a color/RGBA format (i.e., not color + * index, depth, stencil, etc). + * \param format the image format value (may by an internal texture format) + * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise. + */ +GLboolean +_mesa_is_color_format(GLenum format) +{ + switch (format) { + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + case GL_R8: + case GL_R16: + case GL_RG: + case GL_RG8: + case GL_RG16: + case 3: + case GL_RGB: + case GL_BGR: + case GL_R3_G3_B2: + case GL_RGB4: + case GL_RGB5: + case GL_RGB565: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + case 4: + case GL_ABGR_EXT: + case GL_RGBA: + case GL_BGRA: + case GL_RGBA2: + case GL_RGBA4: + case GL_RGB5_A1: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + /* float texture formats */ + case GL_ALPHA16F_ARB: + case GL_ALPHA32F_ARB: + case GL_LUMINANCE16F_ARB: + case GL_LUMINANCE32F_ARB: + case GL_LUMINANCE_ALPHA16F_ARB: + case GL_LUMINANCE_ALPHA32F_ARB: + case GL_INTENSITY16F_ARB: + case GL_INTENSITY32F_ARB: + case GL_R16F: + case GL_R32F: + case GL_RG16F: + case GL_RG32F: + case GL_RGB16F_ARB: + case GL_RGB32F_ARB: + case GL_RGBA16F_ARB: + case GL_RGBA32F_ARB: + /* compressed formats */ + case GL_COMPRESSED_ALPHA: + case GL_COMPRESSED_LUMINANCE: + case GL_COMPRESSED_LUMINANCE_ALPHA: + case GL_COMPRESSED_INTENSITY: + case GL_COMPRESSED_RED: + case GL_COMPRESSED_RG: + case GL_COMPRESSED_RGB: + case GL_COMPRESSED_RGBA: + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_RGB_FXT1_3DFX: + case GL_COMPRESSED_RGBA_FXT1_3DFX: +#if FEATURE_EXT_texture_sRGB + case GL_SRGB_EXT: + case GL_SRGB8_EXT: + case GL_SRGB_ALPHA_EXT: + case GL_SRGB8_ALPHA8_EXT: + case GL_SLUMINANCE_ALPHA_EXT: + case GL_SLUMINANCE8_ALPHA8_EXT: + case GL_SLUMINANCE_EXT: + case GL_SLUMINANCE8_EXT: + case GL_COMPRESSED_SRGB_EXT: + case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SLUMINANCE_EXT: + case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: +#endif /* FEATURE_EXT_texture_sRGB */ + case GL_COMPRESSED_RED_RGTC1: + case GL_COMPRESSED_SIGNED_RED_RGTC1: + case GL_COMPRESSED_RG_RGTC2: + case GL_COMPRESSED_SIGNED_RG_RGTC2: + case GL_COMPRESSED_LUMINANCE_LATC1_EXT: + case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: + case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: + case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: + case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: + case GL_ETC1_RGB8_OES: + /* generic integer formats */ + case GL_RED_INTEGER_EXT: + case GL_GREEN_INTEGER_EXT: + case GL_BLUE_INTEGER_EXT: + case GL_ALPHA_INTEGER_EXT: + case GL_RGB_INTEGER_EXT: + case GL_RGBA_INTEGER_EXT: + case GL_BGR_INTEGER_EXT: + case GL_BGRA_INTEGER_EXT: + case GL_RG_INTEGER: + case GL_LUMINANCE_INTEGER_EXT: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + /* sized integer formats */ + case GL_RGBA32UI_EXT: + case GL_RGB32UI_EXT: + case GL_RG32UI: + case GL_R32UI: + case GL_ALPHA32UI_EXT: + case GL_INTENSITY32UI_EXT: + case GL_LUMINANCE32UI_EXT: + case GL_LUMINANCE_ALPHA32UI_EXT: + case GL_RGBA16UI_EXT: + case GL_RGB16UI_EXT: + case GL_RG16UI: + case GL_R16UI: + case GL_ALPHA16UI_EXT: + case GL_INTENSITY16UI_EXT: + case GL_LUMINANCE16UI_EXT: + case GL_LUMINANCE_ALPHA16UI_EXT: + case GL_RGBA8UI_EXT: + case GL_RGB8UI_EXT: + case GL_RG8UI: + case GL_R8UI: + case GL_ALPHA8UI_EXT: + case GL_INTENSITY8UI_EXT: + case GL_LUMINANCE8UI_EXT: + case GL_LUMINANCE_ALPHA8UI_EXT: + case GL_RGBA32I_EXT: + case GL_RGB32I_EXT: + case GL_RG32I: + case GL_R32I: + case GL_ALPHA32I_EXT: + case GL_INTENSITY32I_EXT: + case GL_LUMINANCE32I_EXT: + case GL_LUMINANCE_ALPHA32I_EXT: + case GL_RGBA16I_EXT: + case GL_RGB16I_EXT: + case GL_RG16I: + case GL_R16I: + case GL_ALPHA16I_EXT: + case GL_INTENSITY16I_EXT: + case GL_LUMINANCE16I_EXT: + case GL_LUMINANCE_ALPHA16I_EXT: + case GL_RGBA8I_EXT: + case GL_RGB8I_EXT: + case GL_RG8I: + case GL_R8I: + case GL_ALPHA8I_EXT: + case GL_INTENSITY8I_EXT: + case GL_LUMINANCE8I_EXT: + case GL_LUMINANCE_ALPHA8I_EXT: + /* signed, normalized texture formats */ + case GL_RED_SNORM: + case GL_R8_SNORM: + case GL_R16_SNORM: + case GL_RG_SNORM: + case GL_RG8_SNORM: + case GL_RG16_SNORM: + case GL_RGB_SNORM: + case GL_RGB8_SNORM: + case GL_RGB16_SNORM: + case GL_RGBA_SNORM: + case GL_RGBA8_SNORM: + case GL_RGBA16_SNORM: + case GL_ALPHA_SNORM: + case GL_ALPHA8_SNORM: + case GL_ALPHA16_SNORM: + case GL_LUMINANCE_SNORM: + case GL_LUMINANCE8_SNORM: + case GL_LUMINANCE16_SNORM: + case GL_LUMINANCE_ALPHA_SNORM: + case GL_LUMINANCE8_ALPHA8_SNORM: + case GL_LUMINANCE16_ALPHA16_SNORM: + case GL_INTENSITY_SNORM: + case GL_INTENSITY8_SNORM: + case GL_INTENSITY16_SNORM: + case GL_RGB9_E5: + case GL_R11F_G11F_B10F: + case GL_RGB10_A2UI: + return GL_TRUE; + case GL_YCBCR_MESA: /* not considered to be RGB */ + /* fall-through */ + default: + return GL_FALSE; + } +} + + +/** + * Test if the given image format is a depth component format. + */ +GLboolean +_mesa_is_depth_format(GLenum format) +{ + switch (format) { + case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT24: + case GL_DEPTH_COMPONENT32: + case GL_DEPTH_COMPONENT32F: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if the given image format is a stencil format. + */ +GLboolean +_mesa_is_stencil_format(GLenum format) +{ + switch (format) { + case GL_STENCIL_INDEX: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if the given image format is a YCbCr format. + */ +GLboolean +_mesa_is_ycbcr_format(GLenum format) +{ + switch (format) { + case GL_YCBCR_MESA: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if the given image format is a depth+stencil format. + */ +GLboolean +_mesa_is_depthstencil_format(GLenum format) +{ + switch (format) { + case GL_DEPTH24_STENCIL8_EXT: + case GL_DEPTH_STENCIL_EXT: + case GL_DEPTH32F_STENCIL8: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if the given image format is a depth or stencil format. + */ +GLboolean +_mesa_is_depth_or_stencil_format(GLenum format) +{ + switch (format) { + case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT24: + case GL_DEPTH_COMPONENT32: + case GL_STENCIL_INDEX: + case GL_STENCIL_INDEX1_EXT: + case GL_STENCIL_INDEX4_EXT: + case GL_STENCIL_INDEX8_EXT: + case GL_STENCIL_INDEX16_EXT: + case GL_DEPTH_STENCIL_EXT: + case GL_DEPTH24_STENCIL8_EXT: + case GL_DEPTH_COMPONENT32F: + case GL_DEPTH32F_STENCIL8: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if the given image format is a dudv format. + */ +GLboolean +_mesa_is_dudv_format(GLenum format) +{ + switch (format) { + case GL_DUDV_ATI: + case GL_DU8DV8_ATI: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if an image format is a supported compressed format. + * \param format the internal format token provided by the user. + * \return GL_TRUE if compressed, GL_FALSE if uncompressed + */ +GLboolean +_mesa_is_compressed_format(struct gl_context *ctx, GLenum format) +{ + switch (format) { + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + return ctx->Extensions.EXT_texture_compression_s3tc; + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + return ctx->Extensions.S3_s3tc; + case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + return ctx->Extensions.EXT_texture_sRGB + && ctx->Extensions.EXT_texture_compression_s3tc; + case GL_COMPRESSED_RGB_FXT1_3DFX: + case GL_COMPRESSED_RGBA_FXT1_3DFX: + return ctx->Extensions.TDFX_texture_compression_FXT1; + case GL_COMPRESSED_RED_RGTC1: + case GL_COMPRESSED_SIGNED_RED_RGTC1: + case GL_COMPRESSED_RG_RGTC2: + case GL_COMPRESSED_SIGNED_RG_RGTC2: + return ctx->Extensions.ARB_texture_compression_rgtc; + case GL_COMPRESSED_LUMINANCE_LATC1_EXT: + case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: + case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: + case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: + return ctx->Extensions.EXT_texture_compression_latc; + case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: + return ctx->Extensions.ATI_texture_compression_3dc; + case GL_ETC1_RGB8_OES: + return ctx->Extensions.OES_compressed_ETC1_RGB8_texture; +#if FEATURE_ES + case GL_PALETTE4_RGB8_OES: + case GL_PALETTE4_RGBA8_OES: + case GL_PALETTE4_R5_G6_B5_OES: + case GL_PALETTE4_RGBA4_OES: + case GL_PALETTE4_RGB5_A1_OES: + case GL_PALETTE8_RGB8_OES: + case GL_PALETTE8_RGBA8_OES: + case GL_PALETTE8_R5_G6_B5_OES: + case GL_PALETTE8_RGBA4_OES: + case GL_PALETTE8_RGB5_A1_OES: + return ctx->API == API_OPENGLES; +#endif + default: + return GL_FALSE; + } +} + + +/** + * Convert various base formats to the cooresponding integer format. + */ +GLenum +_mesa_base_format_to_integer_format(GLenum format) +{ + switch(format) { + case GL_RED: + return GL_RED_INTEGER; + case GL_GREEN: + return GL_GREEN_INTEGER; + case GL_BLUE: + return GL_BLUE_INTEGER; + case GL_RG: + return GL_RG_INTEGER; + case GL_RGB: + return GL_RGB_INTEGER; + case GL_RGBA: + return GL_RGBA_INTEGER; + case GL_BGR: + return GL_BGR_INTEGER; + case GL_BGRA: + return GL_BGRA_INTEGER; + case GL_ALPHA: + return GL_ALPHA_INTEGER; + case GL_LUMINANCE: + return GL_LUMINANCE_INTEGER_EXT; + case GL_LUMINANCE_ALPHA: + return GL_LUMINANCE_ALPHA_INTEGER_EXT; + } + + return format; +} + + +/** + * Does the given base texture/renderbuffer format have the channel + * named by 'pname'? + */ +GLboolean +_mesa_base_format_has_channel(GLenum base_format, GLenum pname) +{ + switch (pname) { + case GL_TEXTURE_RED_SIZE: + case GL_TEXTURE_RED_TYPE: + case GL_RENDERBUFFER_RED_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: + if (base_format == GL_RED || + base_format == GL_RG || + base_format == GL_RGB || + base_format == GL_RGBA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_GREEN_SIZE: + case GL_TEXTURE_GREEN_TYPE: + case GL_RENDERBUFFER_GREEN_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: + if (base_format == GL_RG || + base_format == GL_RGB || + base_format == GL_RGBA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_BLUE_SIZE: + case GL_TEXTURE_BLUE_TYPE: + case GL_RENDERBUFFER_BLUE_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: + if (base_format == GL_RGB || + base_format == GL_RGBA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_ALPHA_SIZE: + case GL_TEXTURE_ALPHA_TYPE: + case GL_RENDERBUFFER_ALPHA_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: + if (base_format == GL_RGBA || + base_format == GL_ALPHA || + base_format == GL_LUMINANCE_ALPHA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_LUMINANCE_SIZE: + case GL_TEXTURE_LUMINANCE_TYPE: + if (base_format == GL_LUMINANCE || + base_format == GL_LUMINANCE_ALPHA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_INTENSITY_SIZE: + case GL_TEXTURE_INTENSITY_TYPE: + if (base_format == GL_INTENSITY) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_DEPTH_SIZE: + case GL_TEXTURE_DEPTH_TYPE: + case GL_RENDERBUFFER_DEPTH_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: + if (base_format == GL_DEPTH_STENCIL || + base_format == GL_DEPTH_COMPONENT) { + return GL_TRUE; + } + return GL_FALSE; + case GL_RENDERBUFFER_STENCIL_SIZE_EXT: + case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: + if (base_format == GL_DEPTH_STENCIL || + base_format == GL_STENCIL_INDEX) { + return GL_TRUE; + } + return GL_FALSE; + default: + _mesa_warning(NULL, "%s: Unexpected channel token 0x%x\n", + __FUNCTION__, pname); + return GL_FALSE; + } + + return GL_FALSE; +} + + +/** + * Do error checking of format/type combinations for glReadPixels, + * glDrawPixels and glTex[Sub]Image. Note that depending on the format + * and type values, we may either generate GL_INVALID_OPERATION or + * GL_INVALID_ENUM. + * + * \param format pixel format. + * \param type pixel type. + * + * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR + */ +GLenum +_mesa_error_check_format_and_type(const struct gl_context *ctx, + GLenum format, GLenum type) +{ + /* special type-based checks (see glReadPixels, glDrawPixels error lists) */ + switch (type) { + case GL_BITMAP: + if (format != GL_COLOR_INDEX && format != GL_STENCIL_INDEX) { + return GL_INVALID_ENUM; + } + break; + + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + if (format == GL_RGB) { + break; /* OK */ + } + if (format == GL_RGB_INTEGER_EXT && + ctx->Extensions.ARB_texture_rgb10_a2ui) { + break; /* OK */ + } + return GL_INVALID_OPERATION; + + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + if (format == GL_RGBA || + format == GL_BGRA || + format == GL_ABGR_EXT) { + break; /* OK */ + } + if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) && + ctx->Extensions.ARB_texture_rgb10_a2ui) { + break; /* OK */ + } + return GL_INVALID_OPERATION; + + case GL_UNSIGNED_INT_24_8: + if (!ctx->Extensions.EXT_packed_depth_stencil) { + return GL_INVALID_ENUM; + } + if (format != GL_DEPTH_STENCIL) { + return GL_INVALID_OPERATION; + } + return GL_NO_ERROR; + + case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + if (!ctx->Extensions.ARB_depth_buffer_float) { + return GL_INVALID_ENUM; + } + if (format != GL_DEPTH_STENCIL) { + return GL_INVALID_OPERATION; + } + return GL_NO_ERROR; + + case GL_UNSIGNED_INT_10F_11F_11F_REV: + if (!ctx->Extensions.EXT_packed_float) { + return GL_INVALID_ENUM; + } + if (format != GL_RGB) { + return GL_INVALID_OPERATION; + } + return GL_NO_ERROR; + + default: + ; /* fall-through */ + } + + /* now, for each format, check the type for compatibility */ + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + switch (type) { + case GL_BITMAP: + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + return GL_NO_ERROR; + case GL_HALF_FLOAT: + return ctx->Extensions.ARB_half_float_pixel + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: +#if 0 /* not legal! see table 3.6 of the 1.5 spec */ + case GL_INTENSITY: +#endif + case GL_LUMINANCE: + case GL_LUMINANCE_ALPHA: + case GL_DEPTH_COMPONENT: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + return GL_NO_ERROR; + case GL_HALF_FLOAT: + return ctx->Extensions.ARB_half_float_pixel + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_RG: + if (!ctx->Extensions.ARB_texture_rg) + return GL_INVALID_ENUM; + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + return GL_NO_ERROR; + case GL_HALF_FLOAT: + return ctx->Extensions.ARB_half_float_pixel + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_RGB: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + return GL_NO_ERROR; + case GL_HALF_FLOAT: + return ctx->Extensions.ARB_half_float_pixel + ? GL_NO_ERROR : GL_INVALID_ENUM; + case GL_UNSIGNED_INT_5_9_9_9_REV: + return ctx->Extensions.EXT_texture_shared_exponent + ? GL_NO_ERROR : GL_INVALID_ENUM; + case GL_UNSIGNED_INT_10F_11F_11F_REV: + return ctx->Extensions.EXT_packed_float + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_BGR: + switch (type) { + /* NOTE: no packed types are supported with BGR. That's + * intentional, according to the GL spec. + */ + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + return GL_NO_ERROR; + case GL_HALF_FLOAT: + return ctx->Extensions.ARB_half_float_pixel + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + return GL_NO_ERROR; + case GL_HALF_FLOAT: + return ctx->Extensions.ARB_half_float_pixel + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_YCBCR_MESA: + if (!ctx->Extensions.MESA_ycbcr_texture) + return GL_INVALID_ENUM; + if (type == GL_UNSIGNED_SHORT_8_8_MESA || + type == GL_UNSIGNED_SHORT_8_8_REV_MESA) + return GL_NO_ERROR; + else + return GL_INVALID_OPERATION; + + case GL_DEPTH_STENCIL_EXT: + if (ctx->Extensions.EXT_packed_depth_stencil && + type == GL_UNSIGNED_INT_24_8) + return GL_NO_ERROR; + else if (ctx->Extensions.ARB_depth_buffer_float && + type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV) + return GL_NO_ERROR; + else + return GL_INVALID_ENUM; + + case GL_DUDV_ATI: + case GL_DU8DV8_ATI: + if (!ctx->Extensions.ATI_envmap_bumpmap) + return GL_INVALID_ENUM; + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + return GL_NO_ERROR; + default: + return GL_INVALID_ENUM; + } + + /* integer-valued formats */ + case GL_RED_INTEGER_EXT: + case GL_GREEN_INTEGER_EXT: + case GL_BLUE_INTEGER_EXT: + case GL_ALPHA_INTEGER_EXT: + case GL_RG_INTEGER: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + return (ctx->VersionMajor >= 3 || + ctx->Extensions.EXT_texture_integer) + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_RGB_INTEGER_EXT: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + return (ctx->VersionMajor >= 3 || + ctx->Extensions.EXT_texture_integer) + ? GL_NO_ERROR : GL_INVALID_ENUM; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + return ctx->Extensions.ARB_texture_rgb10_a2ui + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_BGR_INTEGER_EXT: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + /* NOTE: no packed formats w/ BGR format */ + return (ctx->VersionMajor >= 3 || + ctx->Extensions.EXT_texture_integer) + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_RGBA_INTEGER_EXT: + case GL_BGRA_INTEGER_EXT: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + return (ctx->VersionMajor >= 3 || + ctx->Extensions.EXT_texture_integer) + ? GL_NO_ERROR : GL_INVALID_ENUM; + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + return ctx->Extensions.ARB_texture_rgb10_a2ui + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + case GL_LUMINANCE_INTEGER_EXT: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + return ctx->Extensions.EXT_texture_integer + ? GL_NO_ERROR : GL_INVALID_ENUM; + default: + return GL_INVALID_ENUM; + } + + default: + return GL_INVALID_ENUM; + } + return GL_NO_ERROR; +} diff --git a/mesalib/src/mesa/main/glformats.h b/mesalib/src/mesa/main/glformats.h new file mode 100644 index 000000000..d553eae0a --- /dev/null +++ b/mesalib/src/mesa/main/glformats.h @@ -0,0 +1,103 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (c) 2008-2009 VMware, Inc. + * Copyright (c) 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef GLFORMATS_H +#define GLFORMATS_H + + +#include <GL/gl.h> + + +#ifdef __cplusplus +extern "C" { +#endif + +extern GLboolean +_mesa_type_is_packed(GLenum type); + +extern GLint +_mesa_sizeof_type( GLenum type ); + +extern GLint +_mesa_sizeof_packed_type( GLenum type ); + +extern GLint +_mesa_components_in_format( GLenum format ); + +extern GLint +_mesa_bytes_per_pixel( GLenum format, GLenum type ); + +extern GLboolean +_mesa_is_type_integer(GLenum type); + +extern GLboolean +_mesa_is_type_unsigned(GLenum type); + +extern GLboolean +_mesa_is_enum_format_integer(GLenum format); + +extern GLboolean +_mesa_is_enum_format_or_type_integer(GLenum format, GLenum type); + +extern GLboolean +_mesa_is_color_format(GLenum format); + +extern GLboolean +_mesa_is_depth_format(GLenum format); + +extern GLboolean +_mesa_is_stencil_format(GLenum format); + +extern GLboolean +_mesa_is_ycbcr_format(GLenum format); + +extern GLboolean +_mesa_is_depthstencil_format(GLenum format); + +extern GLboolean +_mesa_is_depth_or_stencil_format(GLenum format); + +extern GLboolean +_mesa_is_dudv_format(GLenum format); + +extern GLboolean +_mesa_is_compressed_format(struct gl_context *ctx, GLenum format); + +extern GLenum +_mesa_base_format_to_integer_format(GLenum format); + +extern GLboolean +_mesa_base_format_has_channel(GLenum base_format, GLenum pname); + +extern GLenum +_mesa_error_check_format_and_type(const struct gl_context *ctx, + GLenum format, GLenum type); + + +#ifdef __cplusplus +} +#endif + +#endif /* GLFORMATS_H */ diff --git a/mesalib/src/mesa/main/image.c b/mesalib/src/mesa/main/image.c index 678dfeb2b..91b720373 100644 --- a/mesalib/src/mesa/main/image.c +++ b/mesalib/src/mesa/main/image.c @@ -32,6 +32,7 @@ #include "glheader.h" #include "colormac.h" +#include "glformats.h" #include "image.h" #include "imports.h" #include "macros.h" @@ -41,40 +42,6 @@ /** - * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise. - */ -GLboolean -_mesa_type_is_packed(GLenum type) -{ - switch (type) { - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - case MESA_UNSIGNED_BYTE_4_4: - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - case GL_UNSIGNED_SHORT_8_8_MESA: - case GL_UNSIGNED_SHORT_8_8_REV_MESA: - case GL_UNSIGNED_INT_24_8_EXT: - case GL_UNSIGNED_INT_5_9_9_9_REV: - case GL_UNSIGNED_INT_10F_11F_11F_REV: - case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: - return GL_TRUE; - } - - return GL_FALSE; -} - - - -/** * Flip the order of the 2 bytes in each word in the given array. * * \param p array. @@ -110,1178 +77,6 @@ _mesa_swap4( GLuint *p, GLuint n ) /** - * Get the size of a GL data type. - * - * \param type GL data type. - * - * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1 - * if an invalid type enum. - */ -GLint -_mesa_sizeof_type( GLenum type ) -{ - switch (type) { - case GL_BITMAP: - return 0; - case GL_UNSIGNED_BYTE: - return sizeof(GLubyte); - case GL_BYTE: - return sizeof(GLbyte); - case GL_UNSIGNED_SHORT: - return sizeof(GLushort); - case GL_SHORT: - return sizeof(GLshort); - case GL_UNSIGNED_INT: - return sizeof(GLuint); - case GL_INT: - return sizeof(GLint); - case GL_FLOAT: - return sizeof(GLfloat); - case GL_DOUBLE: - return sizeof(GLdouble); - case GL_HALF_FLOAT_ARB: - return sizeof(GLhalfARB); - case GL_FIXED: - return sizeof(GLfixed); - default: - return -1; - } -} - - -/** - * Same as _mesa_sizeof_type() but also accepting the packed pixel - * format data types. - */ -GLint -_mesa_sizeof_packed_type( GLenum type ) -{ - switch (type) { - case GL_BITMAP: - return 0; - case GL_UNSIGNED_BYTE: - return sizeof(GLubyte); - case GL_BYTE: - return sizeof(GLbyte); - case GL_UNSIGNED_SHORT: - return sizeof(GLushort); - case GL_SHORT: - return sizeof(GLshort); - case GL_UNSIGNED_INT: - return sizeof(GLuint); - case GL_INT: - return sizeof(GLint); - case GL_HALF_FLOAT_ARB: - return sizeof(GLhalfARB); - case GL_FLOAT: - return sizeof(GLfloat); - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - case MESA_UNSIGNED_BYTE_4_4: - return sizeof(GLubyte); - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - case GL_UNSIGNED_SHORT_8_8_MESA: - case GL_UNSIGNED_SHORT_8_8_REV_MESA: - return sizeof(GLushort); - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - case GL_UNSIGNED_INT_24_8_EXT: - case GL_UNSIGNED_INT_5_9_9_9_REV: - case GL_UNSIGNED_INT_10F_11F_11F_REV: - return sizeof(GLuint); - case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: - return 8; - default: - return -1; - } -} - - -/** - * Get the number of components in a pixel format. - * - * \param format pixel format. - * - * \return the number of components in the given format, or -1 if a bad format. - */ -GLint -_mesa_components_in_format( GLenum format ) -{ - switch (format) { - case GL_COLOR_INDEX: - case GL_STENCIL_INDEX: - case GL_DEPTH_COMPONENT: - case GL_RED: - case GL_RED_INTEGER_EXT: - case GL_GREEN: - case GL_GREEN_INTEGER_EXT: - case GL_BLUE: - case GL_BLUE_INTEGER_EXT: - case GL_ALPHA: - case GL_ALPHA_INTEGER_EXT: - case GL_LUMINANCE: - case GL_LUMINANCE_INTEGER_EXT: - case GL_INTENSITY: - return 1; - - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE_ALPHA_INTEGER_EXT: - case GL_RG: - case GL_YCBCR_MESA: - case GL_DEPTH_STENCIL_EXT: - case GL_DUDV_ATI: - case GL_DU8DV8_ATI: - case GL_RG_INTEGER: - return 2; - - case GL_RGB: - case GL_BGR: - case GL_RGB_INTEGER_EXT: - case GL_BGR_INTEGER_EXT: - return 3; - - case GL_RGBA: - case GL_BGRA: - case GL_ABGR_EXT: - case GL_RGBA_INTEGER_EXT: - case GL_BGRA_INTEGER_EXT: - return 4; - - default: - return -1; - } -} - - -/** - * Get the bytes per pixel of pixel format type pair. - * - * \param format pixel format. - * \param type pixel type. - * - * \return bytes per pixel, or -1 if a bad format or type was given. - */ -GLint -_mesa_bytes_per_pixel( GLenum format, GLenum type ) -{ - GLint comps = _mesa_components_in_format( format ); - if (comps < 0) - return -1; - - switch (type) { - case GL_BITMAP: - return 0; /* special case */ - case GL_BYTE: - case GL_UNSIGNED_BYTE: - return comps * sizeof(GLubyte); - case GL_SHORT: - case GL_UNSIGNED_SHORT: - return comps * sizeof(GLshort); - case GL_INT: - case GL_UNSIGNED_INT: - return comps * sizeof(GLint); - case GL_FLOAT: - return comps * sizeof(GLfloat); - case GL_HALF_FLOAT_ARB: - return comps * sizeof(GLhalfARB); - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - if (format == GL_RGB || format == GL_BGR || - format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT) - return sizeof(GLubyte); - else - return -1; /* error */ - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - if (format == GL_RGB || format == GL_BGR || - format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT) - return sizeof(GLushort); - else - return -1; /* error */ - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT || - format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) - return sizeof(GLushort); - else - return -1; - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT || - format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) - return sizeof(GLuint); - else - return -1; - case GL_UNSIGNED_SHORT_8_8_MESA: - case GL_UNSIGNED_SHORT_8_8_REV_MESA: - if (format == GL_YCBCR_MESA) - return sizeof(GLushort); - else - return -1; - case GL_UNSIGNED_INT_24_8_EXT: - if (format == GL_DEPTH_STENCIL_EXT) - return sizeof(GLuint); - else - return -1; - case GL_UNSIGNED_INT_5_9_9_9_REV: - if (format == GL_RGB) - return sizeof(GLuint); - else - return -1; - case GL_UNSIGNED_INT_10F_11F_11F_REV: - if (format == GL_RGB) - return sizeof(GLuint); - else - return -1; - case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: - if (format == GL_DEPTH_STENCIL) - return 8; - else - return -1; - default: - return -1; - } -} - - -/** - * Do error checking of format/type combinations for glReadPixels, - * glDrawPixels and glTex[Sub]Image. Note that depending on the format - * and type values, we may either generate GL_INVALID_OPERATION or - * GL_INVALID_ENUM. - * - * \param format pixel format. - * \param type pixel type. - * - * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR - */ -GLenum -_mesa_error_check_format_and_type(const struct gl_context *ctx, - GLenum format, GLenum type) -{ - /* special type-based checks (see glReadPixels, glDrawPixels error lists) */ - switch (type) { - case GL_BITMAP: - if (format != GL_COLOR_INDEX && format != GL_STENCIL_INDEX) { - return GL_INVALID_ENUM; - } - break; - - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - if (format == GL_RGB) { - break; /* OK */ - } - if (format == GL_RGB_INTEGER_EXT && - ctx->Extensions.ARB_texture_rgb10_a2ui) { - break; /* OK */ - } - return GL_INVALID_OPERATION; - - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - if (format == GL_RGBA || - format == GL_BGRA || - format == GL_ABGR_EXT) { - break; /* OK */ - } - if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) && - ctx->Extensions.ARB_texture_rgb10_a2ui) { - break; /* OK */ - } - return GL_INVALID_OPERATION; - - case GL_UNSIGNED_INT_24_8: - if (!ctx->Extensions.EXT_packed_depth_stencil) { - return GL_INVALID_ENUM; - } - if (format != GL_DEPTH_STENCIL) { - return GL_INVALID_OPERATION; - } - return GL_NO_ERROR; - - case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: - if (!ctx->Extensions.ARB_depth_buffer_float) { - return GL_INVALID_ENUM; - } - if (format != GL_DEPTH_STENCIL) { - return GL_INVALID_OPERATION; - } - return GL_NO_ERROR; - - case GL_UNSIGNED_INT_10F_11F_11F_REV: - if (!ctx->Extensions.EXT_packed_float) { - return GL_INVALID_ENUM; - } - if (format != GL_RGB) { - return GL_INVALID_OPERATION; - } - return GL_NO_ERROR; - - default: - ; /* fall-through */ - } - - /* now, for each format, check the type for compatibility */ - switch (format) { - case GL_COLOR_INDEX: - case GL_STENCIL_INDEX: - switch (type) { - case GL_BITMAP: - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - return GL_NO_ERROR; - case GL_HALF_FLOAT: - return ctx->Extensions.ARB_half_float_pixel - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: -#if 0 /* not legal! see table 3.6 of the 1.5 spec */ - case GL_INTENSITY: -#endif - case GL_LUMINANCE: - case GL_LUMINANCE_ALPHA: - case GL_DEPTH_COMPONENT: - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - return GL_NO_ERROR; - case GL_HALF_FLOAT: - return ctx->Extensions.ARB_half_float_pixel - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_RG: - if (!ctx->Extensions.ARB_texture_rg) - return GL_INVALID_ENUM; - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - return GL_NO_ERROR; - case GL_HALF_FLOAT: - return ctx->Extensions.ARB_half_float_pixel - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_RGB: - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - return GL_NO_ERROR; - case GL_HALF_FLOAT: - return ctx->Extensions.ARB_half_float_pixel - ? GL_NO_ERROR : GL_INVALID_ENUM; - case GL_UNSIGNED_INT_5_9_9_9_REV: - return ctx->Extensions.EXT_texture_shared_exponent - ? GL_NO_ERROR : GL_INVALID_ENUM; - case GL_UNSIGNED_INT_10F_11F_11F_REV: - return ctx->Extensions.EXT_packed_float - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_BGR: - switch (type) { - /* NOTE: no packed types are supported with BGR. That's - * intentional, according to the GL spec. - */ - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - return GL_NO_ERROR; - case GL_HALF_FLOAT: - return ctx->Extensions.ARB_half_float_pixel - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_RGBA: - case GL_BGRA: - case GL_ABGR_EXT: - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - return GL_NO_ERROR; - case GL_HALF_FLOAT: - return ctx->Extensions.ARB_half_float_pixel - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_YCBCR_MESA: - if (!ctx->Extensions.MESA_ycbcr_texture) - return GL_INVALID_ENUM; - if (type == GL_UNSIGNED_SHORT_8_8_MESA || - type == GL_UNSIGNED_SHORT_8_8_REV_MESA) - return GL_NO_ERROR; - else - return GL_INVALID_OPERATION; - - case GL_DEPTH_STENCIL_EXT: - if (ctx->Extensions.EXT_packed_depth_stencil && - type == GL_UNSIGNED_INT_24_8) - return GL_NO_ERROR; - else if (ctx->Extensions.ARB_depth_buffer_float && - type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV) - return GL_NO_ERROR; - else - return GL_INVALID_ENUM; - - case GL_DUDV_ATI: - case GL_DU8DV8_ATI: - if (!ctx->Extensions.ATI_envmap_bumpmap) - return GL_INVALID_ENUM; - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - return GL_NO_ERROR; - default: - return GL_INVALID_ENUM; - } - - /* integer-valued formats */ - case GL_RED_INTEGER_EXT: - case GL_GREEN_INTEGER_EXT: - case GL_BLUE_INTEGER_EXT: - case GL_ALPHA_INTEGER_EXT: - case GL_RG_INTEGER: - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - return (ctx->VersionMajor >= 3 || - ctx->Extensions.EXT_texture_integer) - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_RGB_INTEGER_EXT: - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - return (ctx->VersionMajor >= 3 || - ctx->Extensions.EXT_texture_integer) - ? GL_NO_ERROR : GL_INVALID_ENUM; - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - return ctx->Extensions.ARB_texture_rgb10_a2ui - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_BGR_INTEGER_EXT: - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - /* NOTE: no packed formats w/ BGR format */ - return (ctx->VersionMajor >= 3 || - ctx->Extensions.EXT_texture_integer) - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_RGBA_INTEGER_EXT: - case GL_BGRA_INTEGER_EXT: - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - return (ctx->VersionMajor >= 3 || - ctx->Extensions.EXT_texture_integer) - ? GL_NO_ERROR : GL_INVALID_ENUM; - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - return ctx->Extensions.ARB_texture_rgb10_a2ui - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - case GL_LUMINANCE_INTEGER_EXT: - case GL_LUMINANCE_ALPHA_INTEGER_EXT: - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - return ctx->Extensions.EXT_texture_integer - ? GL_NO_ERROR : GL_INVALID_ENUM; - default: - return GL_INVALID_ENUM; - } - - default: - return GL_INVALID_ENUM; - } - return GL_NO_ERROR; -} - - -/** - * Test if the given image format is a color/RGBA format (i.e., not color - * index, depth, stencil, etc). - * \param format the image format value (may by an internal texture format) - * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise. - */ -GLboolean -_mesa_is_color_format(GLenum format) -{ - switch (format) { - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - case GL_R8: - case GL_R16: - case GL_RG: - case GL_RG8: - case GL_RG16: - case 3: - case GL_RGB: - case GL_BGR: - case GL_R3_G3_B2: - case GL_RGB4: - case GL_RGB5: - case GL_RGB565: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - case 4: - case GL_ABGR_EXT: - case GL_RGBA: - case GL_BGRA: - case GL_RGBA2: - case GL_RGBA4: - case GL_RGB5_A1: - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - /* float texture formats */ - case GL_ALPHA16F_ARB: - case GL_ALPHA32F_ARB: - case GL_LUMINANCE16F_ARB: - case GL_LUMINANCE32F_ARB: - case GL_LUMINANCE_ALPHA16F_ARB: - case GL_LUMINANCE_ALPHA32F_ARB: - case GL_INTENSITY16F_ARB: - case GL_INTENSITY32F_ARB: - case GL_R16F: - case GL_R32F: - case GL_RG16F: - case GL_RG32F: - case GL_RGB16F_ARB: - case GL_RGB32F_ARB: - case GL_RGBA16F_ARB: - case GL_RGBA32F_ARB: - /* compressed formats */ - case GL_COMPRESSED_ALPHA: - case GL_COMPRESSED_LUMINANCE: - case GL_COMPRESSED_LUMINANCE_ALPHA: - case GL_COMPRESSED_INTENSITY: - case GL_COMPRESSED_RED: - case GL_COMPRESSED_RG: - case GL_COMPRESSED_RGB: - case GL_COMPRESSED_RGBA: - case GL_RGB_S3TC: - case GL_RGB4_S3TC: - case GL_RGBA_S3TC: - case GL_RGBA4_S3TC: - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_RGB_FXT1_3DFX: - case GL_COMPRESSED_RGBA_FXT1_3DFX: -#if FEATURE_EXT_texture_sRGB - case GL_SRGB_EXT: - case GL_SRGB8_EXT: - case GL_SRGB_ALPHA_EXT: - case GL_SRGB8_ALPHA8_EXT: - case GL_SLUMINANCE_ALPHA_EXT: - case GL_SLUMINANCE8_ALPHA8_EXT: - case GL_SLUMINANCE_EXT: - case GL_SLUMINANCE8_EXT: - case GL_COMPRESSED_SRGB_EXT: - case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - case GL_COMPRESSED_SLUMINANCE_EXT: - case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: -#endif /* FEATURE_EXT_texture_sRGB */ - case GL_COMPRESSED_RED_RGTC1: - case GL_COMPRESSED_SIGNED_RED_RGTC1: - case GL_COMPRESSED_RG_RGTC2: - case GL_COMPRESSED_SIGNED_RG_RGTC2: - case GL_COMPRESSED_LUMINANCE_LATC1_EXT: - case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: - case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: - case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: - case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: - case GL_ETC1_RGB8_OES: - /* generic integer formats */ - case GL_RED_INTEGER_EXT: - case GL_GREEN_INTEGER_EXT: - case GL_BLUE_INTEGER_EXT: - case GL_ALPHA_INTEGER_EXT: - case GL_RGB_INTEGER_EXT: - case GL_RGBA_INTEGER_EXT: - case GL_BGR_INTEGER_EXT: - case GL_BGRA_INTEGER_EXT: - case GL_RG_INTEGER: - case GL_LUMINANCE_INTEGER_EXT: - case GL_LUMINANCE_ALPHA_INTEGER_EXT: - /* sized integer formats */ - case GL_RGBA32UI_EXT: - case GL_RGB32UI_EXT: - case GL_RG32UI: - case GL_R32UI: - case GL_ALPHA32UI_EXT: - case GL_INTENSITY32UI_EXT: - case GL_LUMINANCE32UI_EXT: - case GL_LUMINANCE_ALPHA32UI_EXT: - case GL_RGBA16UI_EXT: - case GL_RGB16UI_EXT: - case GL_RG16UI: - case GL_R16UI: - case GL_ALPHA16UI_EXT: - case GL_INTENSITY16UI_EXT: - case GL_LUMINANCE16UI_EXT: - case GL_LUMINANCE_ALPHA16UI_EXT: - case GL_RGBA8UI_EXT: - case GL_RGB8UI_EXT: - case GL_RG8UI: - case GL_R8UI: - case GL_ALPHA8UI_EXT: - case GL_INTENSITY8UI_EXT: - case GL_LUMINANCE8UI_EXT: - case GL_LUMINANCE_ALPHA8UI_EXT: - case GL_RGBA32I_EXT: - case GL_RGB32I_EXT: - case GL_RG32I: - case GL_R32I: - case GL_ALPHA32I_EXT: - case GL_INTENSITY32I_EXT: - case GL_LUMINANCE32I_EXT: - case GL_LUMINANCE_ALPHA32I_EXT: - case GL_RGBA16I_EXT: - case GL_RGB16I_EXT: - case GL_RG16I: - case GL_R16I: - case GL_ALPHA16I_EXT: - case GL_INTENSITY16I_EXT: - case GL_LUMINANCE16I_EXT: - case GL_LUMINANCE_ALPHA16I_EXT: - case GL_RGBA8I_EXT: - case GL_RGB8I_EXT: - case GL_RG8I: - case GL_R8I: - case GL_ALPHA8I_EXT: - case GL_INTENSITY8I_EXT: - case GL_LUMINANCE8I_EXT: - case GL_LUMINANCE_ALPHA8I_EXT: - /* signed, normalized texture formats */ - case GL_RED_SNORM: - case GL_R8_SNORM: - case GL_R16_SNORM: - case GL_RG_SNORM: - case GL_RG8_SNORM: - case GL_RG16_SNORM: - case GL_RGB_SNORM: - case GL_RGB8_SNORM: - case GL_RGB16_SNORM: - case GL_RGBA_SNORM: - case GL_RGBA8_SNORM: - case GL_RGBA16_SNORM: - case GL_ALPHA_SNORM: - case GL_ALPHA8_SNORM: - case GL_ALPHA16_SNORM: - case GL_LUMINANCE_SNORM: - case GL_LUMINANCE8_SNORM: - case GL_LUMINANCE16_SNORM: - case GL_LUMINANCE_ALPHA_SNORM: - case GL_LUMINANCE8_ALPHA8_SNORM: - case GL_LUMINANCE16_ALPHA16_SNORM: - case GL_INTENSITY_SNORM: - case GL_INTENSITY8_SNORM: - case GL_INTENSITY16_SNORM: - case GL_RGB9_E5: - case GL_R11F_G11F_B10F: - case GL_RGB10_A2UI: - return GL_TRUE; - case GL_YCBCR_MESA: /* not considered to be RGB */ - /* fall-through */ - default: - return GL_FALSE; - } -} - - -/** - * Test if the given image format is a depth component format. - */ -GLboolean -_mesa_is_depth_format(GLenum format) -{ - switch (format) { - case GL_DEPTH_COMPONENT: - case GL_DEPTH_COMPONENT16: - case GL_DEPTH_COMPONENT24: - case GL_DEPTH_COMPONENT32: - case GL_DEPTH_COMPONENT32F: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - -/** - * Test if the given image format is a stencil format. - */ -GLboolean -_mesa_is_stencil_format(GLenum format) -{ - switch (format) { - case GL_STENCIL_INDEX: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - -/** - * Test if the given image format is a YCbCr format. - */ -GLboolean -_mesa_is_ycbcr_format(GLenum format) -{ - switch (format) { - case GL_YCBCR_MESA: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - -/** - * Test if the given image format is a depth+stencil format. - */ -GLboolean -_mesa_is_depthstencil_format(GLenum format) -{ - switch (format) { - case GL_DEPTH24_STENCIL8_EXT: - case GL_DEPTH_STENCIL_EXT: - case GL_DEPTH32F_STENCIL8: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - -/** - * Test if the given image format is a depth or stencil format. - */ -GLboolean -_mesa_is_depth_or_stencil_format(GLenum format) -{ - switch (format) { - case GL_DEPTH_COMPONENT: - case GL_DEPTH_COMPONENT16: - case GL_DEPTH_COMPONENT24: - case GL_DEPTH_COMPONENT32: - case GL_STENCIL_INDEX: - case GL_STENCIL_INDEX1_EXT: - case GL_STENCIL_INDEX4_EXT: - case GL_STENCIL_INDEX8_EXT: - case GL_STENCIL_INDEX16_EXT: - case GL_DEPTH_STENCIL_EXT: - case GL_DEPTH24_STENCIL8_EXT: - case GL_DEPTH_COMPONENT32F: - case GL_DEPTH32F_STENCIL8: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - -/** - * Test if the given image format is a dudv format. - */ -GLboolean -_mesa_is_dudv_format(GLenum format) -{ - switch (format) { - case GL_DUDV_ATI: - case GL_DU8DV8_ATI: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - -/** - * Test if the given format is an integer (non-normalized) format. - */ -GLboolean -_mesa_is_integer_format(GLenum format) -{ - switch (format) { - /* generic integer formats */ - case GL_RED_INTEGER_EXT: - case GL_GREEN_INTEGER_EXT: - case GL_BLUE_INTEGER_EXT: - case GL_ALPHA_INTEGER_EXT: - case GL_RGB_INTEGER_EXT: - case GL_RGBA_INTEGER_EXT: - case GL_BGR_INTEGER_EXT: - case GL_BGRA_INTEGER_EXT: - case GL_LUMINANCE_INTEGER_EXT: - case GL_LUMINANCE_ALPHA_INTEGER_EXT: - case GL_RG_INTEGER: - /* specific integer formats */ - case GL_RGBA32UI_EXT: - case GL_RGB32UI_EXT: - case GL_RG32UI: - case GL_R32UI: - case GL_ALPHA32UI_EXT: - case GL_INTENSITY32UI_EXT: - case GL_LUMINANCE32UI_EXT: - case GL_LUMINANCE_ALPHA32UI_EXT: - case GL_RGBA16UI_EXT: - case GL_RGB16UI_EXT: - case GL_RG16UI: - case GL_R16UI: - case GL_ALPHA16UI_EXT: - case GL_INTENSITY16UI_EXT: - case GL_LUMINANCE16UI_EXT: - case GL_LUMINANCE_ALPHA16UI_EXT: - case GL_RGBA8UI_EXT: - case GL_RGB8UI_EXT: - case GL_RG8UI: - case GL_R8UI: - case GL_ALPHA8UI_EXT: - case GL_INTENSITY8UI_EXT: - case GL_LUMINANCE8UI_EXT: - case GL_LUMINANCE_ALPHA8UI_EXT: - case GL_RGBA32I_EXT: - case GL_RGB32I_EXT: - case GL_RG32I: - case GL_R32I: - case GL_ALPHA32I_EXT: - case GL_INTENSITY32I_EXT: - case GL_LUMINANCE32I_EXT: - case GL_LUMINANCE_ALPHA32I_EXT: - case GL_RGBA16I_EXT: - case GL_RGB16I_EXT: - case GL_RG16I: - case GL_R16I: - case GL_ALPHA16I_EXT: - case GL_INTENSITY16I_EXT: - case GL_LUMINANCE16I_EXT: - case GL_LUMINANCE_ALPHA16I_EXT: - case GL_RGBA8I_EXT: - case GL_RGB8I_EXT: - case GL_RG8I: - case GL_R8I: - case GL_ALPHA8I_EXT: - case GL_INTENSITY8I_EXT: - case GL_LUMINANCE8I_EXT: - case GL_LUMINANCE_ALPHA8I_EXT: - case GL_RGB10_A2UI: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - -/** - * Test if an image format is a supported compressed format. - * \param format the internal format token provided by the user. - * \return GL_TRUE if compressed, GL_FALSE if uncompressed - */ -GLboolean -_mesa_is_compressed_format(struct gl_context *ctx, GLenum format) -{ - switch (format) { - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - return ctx->Extensions.EXT_texture_compression_s3tc; - case GL_RGB_S3TC: - case GL_RGB4_S3TC: - case GL_RGBA_S3TC: - case GL_RGBA4_S3TC: - return ctx->Extensions.S3_s3tc; - case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - return ctx->Extensions.EXT_texture_sRGB - && ctx->Extensions.EXT_texture_compression_s3tc; - case GL_COMPRESSED_RGB_FXT1_3DFX: - case GL_COMPRESSED_RGBA_FXT1_3DFX: - return ctx->Extensions.TDFX_texture_compression_FXT1; - case GL_COMPRESSED_RED_RGTC1: - case GL_COMPRESSED_SIGNED_RED_RGTC1: - case GL_COMPRESSED_RG_RGTC2: - case GL_COMPRESSED_SIGNED_RG_RGTC2: - return ctx->Extensions.ARB_texture_compression_rgtc; - case GL_COMPRESSED_LUMINANCE_LATC1_EXT: - case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: - case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: - case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: - return ctx->Extensions.EXT_texture_compression_latc; - case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: - return ctx->Extensions.ATI_texture_compression_3dc; - case GL_ETC1_RGB8_OES: - return ctx->Extensions.OES_compressed_ETC1_RGB8_texture; -#if FEATURE_ES - case GL_PALETTE4_RGB8_OES: - case GL_PALETTE4_RGBA8_OES: - case GL_PALETTE4_R5_G6_B5_OES: - case GL_PALETTE4_RGBA4_OES: - case GL_PALETTE4_RGB5_A1_OES: - case GL_PALETTE8_RGB8_OES: - case GL_PALETTE8_RGBA8_OES: - case GL_PALETTE8_R5_G6_B5_OES: - case GL_PALETTE8_RGBA4_OES: - case GL_PALETTE8_RGB5_A1_OES: - return ctx->API == API_OPENGLES; -#endif - default: - return GL_FALSE; - } -} - - -/** - * Does the given base texture/renderbuffer format have the channel - * named by 'pname'? - */ -GLboolean -_mesa_base_format_has_channel(GLenum base_format, GLenum pname) -{ - switch (pname) { - case GL_TEXTURE_RED_SIZE: - case GL_TEXTURE_RED_TYPE: - case GL_RENDERBUFFER_RED_SIZE_EXT: - case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: - if (base_format == GL_RED || - base_format == GL_RG || - base_format == GL_RGB || - base_format == GL_RGBA) { - return GL_TRUE; - } - return GL_FALSE; - case GL_TEXTURE_GREEN_SIZE: - case GL_TEXTURE_GREEN_TYPE: - case GL_RENDERBUFFER_GREEN_SIZE_EXT: - case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: - if (base_format == GL_RG || - base_format == GL_RGB || - base_format == GL_RGBA) { - return GL_TRUE; - } - return GL_FALSE; - case GL_TEXTURE_BLUE_SIZE: - case GL_TEXTURE_BLUE_TYPE: - case GL_RENDERBUFFER_BLUE_SIZE_EXT: - case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: - if (base_format == GL_RGB || - base_format == GL_RGBA) { - return GL_TRUE; - } - return GL_FALSE; - case GL_TEXTURE_ALPHA_SIZE: - case GL_TEXTURE_ALPHA_TYPE: - case GL_RENDERBUFFER_ALPHA_SIZE_EXT: - case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: - if (base_format == GL_RGBA || - base_format == GL_ALPHA || - base_format == GL_LUMINANCE_ALPHA) { - return GL_TRUE; - } - return GL_FALSE; - case GL_TEXTURE_LUMINANCE_SIZE: - case GL_TEXTURE_LUMINANCE_TYPE: - if (base_format == GL_LUMINANCE || - base_format == GL_LUMINANCE_ALPHA) { - return GL_TRUE; - } - return GL_FALSE; - case GL_TEXTURE_INTENSITY_SIZE: - case GL_TEXTURE_INTENSITY_TYPE: - if (base_format == GL_INTENSITY) { - return GL_TRUE; - } - return GL_FALSE; - case GL_TEXTURE_DEPTH_SIZE: - case GL_TEXTURE_DEPTH_TYPE: - case GL_RENDERBUFFER_DEPTH_SIZE_EXT: - case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: - if (base_format == GL_DEPTH_STENCIL || - base_format == GL_DEPTH_COMPONENT) { - return GL_TRUE; - } - return GL_FALSE; - case GL_RENDERBUFFER_STENCIL_SIZE_EXT: - case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: - if (base_format == GL_DEPTH_STENCIL || - base_format == GL_STENCIL_INDEX) { - return GL_TRUE; - } - return GL_FALSE; - default: - _mesa_warning(NULL, "%s: Unexpected channel token 0x%x\n", - __FUNCTION__, pname); - return GL_FALSE; - } - - return GL_FALSE; -} - - -/** * Return the byte offset of a specific pixel in an image (1D, 2D or 3D). * * Pixel unpacking/packing parameters are observed according to \p packing. diff --git a/mesalib/src/mesa/main/image.h b/mesalib/src/mesa/main/image.h index f1ed88379..7e92790b7 100644 --- a/mesalib/src/mesa/main/image.h +++ b/mesalib/src/mesa/main/image.h @@ -38,55 +38,6 @@ _mesa_swap2( GLushort *p, GLuint n ); extern void _mesa_swap4( GLuint *p, GLuint n ); -extern GLboolean -_mesa_type_is_packed(GLenum type); - -extern GLint -_mesa_sizeof_type( GLenum type ); - -extern GLint -_mesa_sizeof_packed_type( GLenum type ); - -extern GLint -_mesa_components_in_format( GLenum format ); - -extern GLint -_mesa_bytes_per_pixel( GLenum format, GLenum type ); - -extern GLenum -_mesa_error_check_format_and_type(const struct gl_context *ctx, - GLenum format, GLenum type); - -extern GLboolean -_mesa_is_color_format(GLenum format); - -extern GLboolean -_mesa_is_depth_format(GLenum format); - -extern GLboolean -_mesa_is_stencil_format(GLenum format); - -extern GLboolean -_mesa_is_ycbcr_format(GLenum format); - -extern GLboolean -_mesa_is_depthstencil_format(GLenum format); - -extern GLboolean -_mesa_is_depth_or_stencil_format(GLenum format); - -extern GLboolean -_mesa_is_dudv_format(GLenum format); - -extern GLboolean -_mesa_is_integer_format(GLenum format); - -extern GLboolean -_mesa_is_compressed_format(struct gl_context *ctx, GLenum format); - -extern GLboolean -_mesa_base_format_has_channel(GLenum base_format, GLenum pname); - extern GLintptr _mesa_image_offset( GLuint dimensions, const struct gl_pixelstore_attrib *packing, diff --git a/mesalib/src/mesa/main/imports.c b/mesalib/src/mesa/main/imports.c index 2d592a68e..0d6b56a51 100644 --- a/mesalib/src/mesa/main/imports.c +++ b/mesalib/src/mesa/main/imports.c @@ -223,19 +223,6 @@ _mesa_realloc(void *oldBuffer, size_t oldSize, size_t newSize) return newBuffer; } -/** - * Fill memory with a constant 16bit word. - * \param dst destination pointer. - * \param val value. - * \param n number of words. - */ -void -_mesa_memset16( unsigned short *dst, unsigned short val, size_t n ) -{ - while (n-- > 0) - *dst++ = val; -} - /*@}*/ @@ -243,213 +230,6 @@ _mesa_memset16( unsigned short *dst, unsigned short val, size_t n ) /** \name Math */ /*@{*/ -/** Wrapper around sqrt() */ -double -_mesa_sqrtd(double x) -{ - return sqrt(x); -} - - -/* - * A High Speed, Low Precision Square Root - * by Paul Lalonde and Robert Dawson - * from "Graphics Gems", Academic Press, 1990 - * - * SPARC implementation of a fast square root by table - * lookup. - * SPARC floating point format is as follows: - * - * BIT 31 30 23 22 0 - * sign exponent mantissa - */ -static short sqrttab[0x100]; /* declare table of square roots */ - -void -_mesa_init_sqrt_table(void) -{ -#if defined(USE_IEEE) && !defined(DEBUG) - unsigned short i; - fi_type fi; /* to access the bits of a float in C quickly */ - /* we use a union defined in glheader.h */ - - for(i=0; i<= 0x7f; i++) { - fi.i = 0; - - /* - * Build a float with the bit pattern i as mantissa - * and an exponent of 0, stored as 127 - */ - - fi.i = (i << 16) | (127 << 23); - fi.f = _mesa_sqrtd(fi.f); - - /* - * Take the square root then strip the first 7 bits of - * the mantissa into the table - */ - - sqrttab[i] = (fi.i & 0x7fffff) >> 16; - - /* - * Repeat the process, this time with an exponent of - * 1, stored as 128 - */ - - fi.i = 0; - fi.i = (i << 16) | (128 << 23); - fi.f = sqrt(fi.f); - sqrttab[i+0x80] = (fi.i & 0x7fffff) >> 16; - } -#else - (void) sqrttab; /* silence compiler warnings */ -#endif /*HAVE_FAST_MATH*/ -} - - -/** - * Single precision square root. - */ -float -_mesa_sqrtf( float x ) -{ -#if defined(USE_IEEE) && !defined(DEBUG) - fi_type num; - /* to access the bits of a float in C - * we use a union from glheader.h */ - - short e; /* the exponent */ - if (x == 0.0F) return 0.0F; /* check for square root of 0 */ - num.f = x; - e = (num.i >> 23) - 127; /* get the exponent - on a SPARC the */ - /* exponent is stored with 127 added */ - num.i &= 0x7fffff; /* leave only the mantissa */ - if (e & 0x01) num.i |= 0x800000; - /* the exponent is odd so we have to */ - /* look it up in the second half of */ - /* the lookup table, so we set the */ - /* high bit */ - e >>= 1; /* divide the exponent by two */ - /* note that in C the shift */ - /* operators are sign preserving */ - /* for signed operands */ - /* Do the table lookup, based on the quaternary mantissa, - * then reconstruct the result back into a float - */ - num.i = ((sqrttab[num.i >> 16]) << 16) | ((e + 127) << 23); - - return num.f; -#else - return (float) _mesa_sqrtd((double) x); -#endif -} - - -/** - inv_sqrt - A single precision 1/sqrt routine for IEEE format floats. - written by Josh Vanderhoof, based on newsgroup posts by James Van Buskirk - and Vesa Karvonen. -*/ -float -_mesa_inv_sqrtf(float n) -{ -#if defined(USE_IEEE) && !defined(DEBUG) - float r0, x0, y0; - float r1, x1, y1; - float r2, x2, y2; -#if 0 /* not used, see below -BP */ - float r3, x3, y3; -#endif - fi_type u; - unsigned int magic; - - /* - Exponent part of the magic number - - - We want to: - 1. subtract the bias from the exponent, - 2. negate it - 3. divide by two (rounding towards -inf) - 4. add the bias back - - Which is the same as subtracting the exponent from 381 and dividing - by 2. - - floor(-(x - 127) / 2) + 127 = floor((381 - x) / 2) - */ - - magic = 381 << 23; - - /* - Significand part of magic number - - - With the current magic number, "(magic - u.i) >> 1" will give you: - - for 1 <= u.f <= 2: 1.25 - u.f / 4 - for 2 <= u.f <= 4: 1.00 - u.f / 8 - - This isn't a bad approximation of 1/sqrt. The maximum difference from - 1/sqrt will be around .06. After three Newton-Raphson iterations, the - maximum difference is less than 4.5e-8. (Which is actually close - enough to make the following bias academic...) - - To get a better approximation you can add a bias to the magic - number. For example, if you subtract 1/2 of the maximum difference in - the first approximation (.03), you will get the following function: - - for 1 <= u.f <= 2: 1.22 - u.f / 4 - for 2 <= u.f <= 3.76: 0.97 - u.f / 8 - for 3.76 <= u.f <= 4: 0.72 - u.f / 16 - (The 3.76 to 4 range is where the result is < .5.) - - This is the closest possible initial approximation, but with a maximum - error of 8e-11 after three NR iterations, it is still not perfect. If - you subtract 0.0332281 instead of .03, the maximum error will be - 2.5e-11 after three NR iterations, which should be about as close as - is possible. - - for 1 <= u.f <= 2: 1.2167719 - u.f / 4 - for 2 <= u.f <= 3.73: 0.9667719 - u.f / 8 - for 3.73 <= u.f <= 4: 0.7167719 - u.f / 16 - - */ - - magic -= (int)(0.0332281 * (1 << 25)); - - u.f = n; - u.i = (magic - u.i) >> 1; - - /* - Instead of Newton-Raphson, we use Goldschmidt's algorithm, which - allows more parallelism. From what I understand, the parallelism - comes at the cost of less precision, because it lets error - accumulate across iterations. - */ - x0 = 1.0f; - y0 = 0.5f * n; - r0 = u.f; - - x1 = x0 * r0; - y1 = y0 * r0 * r0; - r1 = 1.5f - y1; - - x2 = x1 * r1; - y2 = y1 * r1 * r1; - r2 = 1.5f - y2; - -#if 1 - return x2 * r2; /* we can stop here, and be conformant -BP */ -#else - x3 = x2 * r2; - y3 = y2 * r2 * r2; - r3 = 1.5f - y3; - - return x3 * r3; -#endif -#else - return (float) (1.0 / sqrt(n)); -#endif -} #ifndef __GNUC__ /** @@ -762,7 +542,7 @@ float _mesa_strtof( const char *s, char **end ) { #if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \ - !defined(ANDROID) && !defined(__HAIKU__) + !defined(ANDROID) && !defined(__HAIKU__) && !defined(__UCLIBC__) static locale_t loc = NULL; if (!loc) { loc = newlocale(LC_CTYPE_MASK, "C", NULL); diff --git a/mesalib/src/mesa/main/imports.h b/mesalib/src/mesa/main/imports.h index c0b6cecea..73913b5ab 100644 --- a/mesalib/src/mesa/main/imports.h +++ b/mesalib/src/mesa/main/imports.h @@ -99,21 +99,13 @@ typedef union { GLfloat f; GLint i; } fi_type; /*** *** SQRTF: single-precision square root ***/ -#if 0 /* _mesa_sqrtf() not accurate enough - temporarily disabled */ -# define SQRTF(X) _mesa_sqrtf(X) -#else -# define SQRTF(X) (float) sqrt((float) (X)) -#endif +#define SQRTF(X) (float) sqrt((float) (X)) /*** *** INV_SQRTF: single-precision inverse square root ***/ -#if 0 -#define INV_SQRTF(X) _mesa_inv_sqrt(X) -#else -#define INV_SQRTF(X) (1.0F / SQRTF(X)) /* this is faster on a P4 */ -#endif +#define INV_SQRTF(X) (1.0F / SQRTF(X)) /** @@ -127,7 +119,7 @@ typedef union { GLfloat f; GLint i; } fi_type; #define asinf(f) ((float) asin(f)) #define atan2f(x,y) ((float) atan2(x,y)) #define atanf(f) ((float) atan(f)) -#define cielf(f) ((float) ciel(f)) +#define ceilf(f) ((float) ceil(f)) #define cosf(f) ((float) cos(f)) #define coshf(f) ((float) cosh(f)) #define expf(f) ((float) exp(f)) @@ -566,21 +558,6 @@ _mesa_exec_free( void *addr ); extern void * _mesa_realloc( void *oldBuffer, size_t oldSize, size_t newSize ); -extern void -_mesa_memset16( unsigned short *dst, unsigned short val, size_t n ); - -extern double -_mesa_sqrtd(double x); - -extern float -_mesa_sqrtf(float x); - -extern float -_mesa_inv_sqrtf(float x); - -extern void -_mesa_init_sqrt_table(void); - #ifndef FFS_DEFINED #define FFS_DEFINED 1 diff --git a/mesalib/src/mesa/main/matrix.c b/mesalib/src/mesa/main/matrix.c index f479a22b0..b09fa4d3d 100644 --- a/mesalib/src/mesa/main/matrix.c +++ b/mesalib/src/mesa/main/matrix.c @@ -658,8 +658,7 @@ void _mesa_update_modelview_project( struct gl_context *ctx, GLuint new_state ) * \param dirtyFlag dirty flag. * * Allocates an array of \p maxDepth elements for the matrix stack and calls - * _math_matrix_ctr() and _math_matrix_alloc_inv() for each element to - * initialize it. + * _math_matrix_ctr() for each element to initialize it. */ static void init_matrix_stack( struct gl_matrix_stack *stack, @@ -674,7 +673,6 @@ init_matrix_stack( struct gl_matrix_stack *stack, stack->Stack = (GLmatrix *) CALLOC(maxDepth * sizeof(GLmatrix)); for (i = 0; i < maxDepth; i++) { _math_matrix_ctr(&stack->Stack[i]); - _math_matrix_alloc_inv(&stack->Stack[i]); } stack->Top = stack->Stack; } diff --git a/mesalib/src/mesa/main/mipmap.c b/mesalib/src/mesa/main/mipmap.c index 250d3c6dc..9f531ae20 100644 --- a/mesalib/src/mesa/main/mipmap.c +++ b/mesalib/src/mesa/main/mipmap.c @@ -29,6 +29,7 @@ #include "imports.h" #include "formats.h" +#include "glformats.h" #include "mipmap.h" #include "mtypes.h" #include "teximage.h" diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index 1f74e6a83..7d7213f4d 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -2011,6 +2011,7 @@ struct gl_fragment_program { struct gl_program Base; /**< base class */ GLboolean UsesKill; /**< shader uses KIL instruction */ + GLboolean UsesDFdy; /**< shader uses DDY instruction */ GLboolean OriginUpperLeft; GLboolean PixelCenterInteger; enum gl_frag_depth_layout FragDepthLayout; @@ -2215,6 +2216,15 @@ struct gl_shader */ unsigned num_uniform_components; + /** + * This shader's uniform block information. + * + * The offsets of the variables are assigned only for shaders in a program's + * _LinkedShaders[]. + */ + struct gl_uniform_block *UniformBlocks; + unsigned NumUniformBlocks; + struct exec_list *ir; struct glsl_symbol_table *symbols; @@ -2236,6 +2246,37 @@ typedef enum MESA_SHADER_TYPES = 3 } gl_shader_type; +struct gl_uniform_buffer_variable +{ + char *Name; + const struct glsl_type *Type; + unsigned int Buffer; + unsigned int Offset; + GLboolean RowMajor; +}; + +struct gl_uniform_block +{ + /** Declared name of the uniform block */ + char *Name; + + /** Array of supplemental information about UBO ir_variables. */ + struct gl_uniform_buffer_variable *Uniforms; + GLuint NumUniforms; + + /** + * Index (GL_UNIFORM_BLOCK_BINDING) into ctx->UniformBufferBindings[] to use + * with glBindBufferBase to bind a buffer object to this uniform block. When + * updated in the program, _NEW_BUFFER_OBJECT will be set. + */ + GLuint Binding; + + /** + * Minimum size of a buffer object to back this uniform buffer + * (GL_UNIFORM_BLOCK_DATA_SIZE). + */ + GLuint UniformBufferSize; +}; /** * A GLSL program object. @@ -2319,6 +2360,18 @@ struct gl_shader_program unsigned NumUserUniformStorage; struct gl_uniform_storage *UniformStorage; + struct gl_uniform_block *UniformBlocks; + unsigned NumUniformBlocks; + + /** + * Indices into the _LinkedShaders's UniformBlocks[] array for each stage + * they're used in, or -1. + * + * This is used to maintain the Binding values of the stage's UniformBlocks[] + * and to answer the GL_UNIFORM_BLOCK_REFERENCED_BY_*_SHADER queries. + */ + int *UniformBlockStageIndex[MESA_SHADER_TYPES]; + /** * Map of active uniform names to locations * @@ -3281,9 +3334,10 @@ struct gl_debug_state */ typedef enum { - API_OPENGL, + API_OPENGL, /* legacy / compatibility contexts */ API_OPENGLES, - API_OPENGLES2 + API_OPENGLES2, + API_OPENGL_CORE, } gl_api; /** diff --git a/mesalib/src/mesa/main/nvprogram.c b/mesalib/src/mesa/main/nvprogram.c index dae11566e..fc5749afc 100644 --- a/mesalib/src/mesa/main/nvprogram.c +++ b/mesalib/src/mesa/main/nvprogram.c @@ -71,7 +71,7 @@ _mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params) FLUSH_VERTICES(ctx, _NEW_PROGRAM); - vprog = (struct gl_vertex_program *) _mesa_lookup_program(ctx, id); + vprog = gl_vertex_program(_mesa_lookup_program(ctx, id)); if (!vprog || vprog->Base.Target != GL_VERTEX_STATE_PROGRAM_NV) { _mesa_error(ctx, GL_INVALID_OPERATION, "glExecuteProgramNV"); @@ -627,10 +627,9 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len, if ((target == GL_VERTEX_PROGRAM_NV || target == GL_VERTEX_STATE_PROGRAM_NV) && ctx->Extensions.NV_vertex_program) { - struct gl_vertex_program *vprog = (struct gl_vertex_program *) prog; + struct gl_vertex_program *vprog = gl_vertex_program(prog); if (!vprog || prog == &_mesa_DummyProgram) { - vprog = (struct gl_vertex_program *) - ctx->Driver.NewProgram(ctx, target, id); + vprog = gl_vertex_program(ctx->Driver.NewProgram(ctx, target, id)); if (!vprog) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV"); return; @@ -647,10 +646,9 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len, } else if (target == GL_FRAGMENT_PROGRAM_NV && ctx->Extensions.NV_fragment_program) { - struct gl_fragment_program *fprog = (struct gl_fragment_program *) prog; + struct gl_fragment_program *fprog = gl_fragment_program(prog); if (!fprog || prog == &_mesa_DummyProgram) { - fprog = (struct gl_fragment_program *) - ctx->Driver.NewProgram(ctx, target, id); + fprog = gl_fragment_program(ctx->Driver.NewProgram(ctx, target, id)); if (!fprog) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV"); return; @@ -661,10 +659,9 @@ _mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len, } else if (target == GL_FRAGMENT_PROGRAM_ARB && ctx->Extensions.ARB_fragment_program) { - struct gl_fragment_program *fprog = (struct gl_fragment_program *) prog; + struct gl_fragment_program *fprog = gl_fragment_program(prog); if (!fprog || prog == &_mesa_DummyProgram) { - fprog = (struct gl_fragment_program *) - ctx->Driver.NewProgram(ctx, target, id); + fprog = gl_fragment_program(ctx->Driver.NewProgram(ctx, target, id)); if (!fprog) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV"); return; @@ -830,7 +827,7 @@ _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name, return; } - fragProg = (struct gl_fragment_program *) prog; + fragProg = gl_fragment_program(prog); v = _mesa_lookup_parameter_value(fragProg->Base.Parameters, len, (char *) name); if (v) { @@ -895,7 +892,7 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name, return; } - fragProg = (struct gl_fragment_program *) prog; + fragProg = gl_fragment_program(prog); v = _mesa_lookup_parameter_value(fragProg->Base.Parameters, len, (char *) name); if (v) { diff --git a/mesalib/src/mesa/main/pack.c b/mesalib/src/mesa/main/pack.c index c25a02e85..83192c157 100644 --- a/mesalib/src/mesa/main/pack.c +++ b/mesalib/src/mesa/main/pack.c @@ -29,6 +29,19 @@ */ +/* + * XXX: MSVC takes forever to compile this module for x86_64 unless we disable + * this global optimization. + * + * See also: + * - http://msdn.microsoft.com/en-us/library/1yk3ydd7.aspx + * - http://msdn.microsoft.com/en-us/library/chh3fb0k.aspx + */ +#if defined(_MSC_VER) && defined(_M_X64) +# pragma optimize( "g", off ) +#endif + + #include "glheader.h" #include "colormac.h" #include "enums.h" @@ -39,6 +52,7 @@ #include "pack.h" #include "pixeltransfer.h" #include "imports.h" +#include "glformats.h" #include "../../gallium/auxiliary/util/u_format_rgb9e5.h" #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h" @@ -500,26 +514,29 @@ _mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4], { switch(dstType) { case GL_UNSIGNED_INT: - pack_uint_from_uint_rgba(dstAddr, dstFormat, rgba, n); + pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); break; case GL_INT: /* No conversion necessary. */ - pack_uint_from_uint_rgba(dstAddr, dstFormat, rgba, n); + pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); break; case GL_UNSIGNED_SHORT: - pack_ushort_from_uint_rgba(dstAddr, dstFormat, rgba, n); + pack_ushort_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); break; case GL_SHORT: - pack_short_from_uint_rgba(dstAddr, dstFormat, rgba, n); + pack_short_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); break; case GL_UNSIGNED_BYTE: - pack_ubyte_from_uint_rgba(dstAddr, dstFormat, rgba, n); + pack_ubyte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); break; case GL_BYTE: - pack_byte_from_uint_rgba(dstAddr, dstFormat, rgba, n); + pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n); break; default: - assert(0); + _mesa_problem(ctx, + "Unsupported type (%s) for format (%s)", + _mesa_lookup_enum_by_nr(dstType), + _mesa_lookup_enum_by_nr(dstFormat)); return; } } @@ -545,7 +562,7 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4], { GLfloat *luminance; const GLint comps = _mesa_components_in_format(dstFormat); - const GLboolean intDstFormat = _mesa_is_integer_format(dstFormat); + const GLboolean intDstFormat = _mesa_is_enum_format_integer(dstFormat); GLuint i; if (dstFormat == GL_LUMINANCE || @@ -2476,7 +2493,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], stride = _mesa_components_in_format(srcFormat); - intFormat = _mesa_is_integer_format(srcFormat); + intFormat = _mesa_is_enum_format_integer(srcFormat); #define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT_FLT, DEFAULT_INT, TYPE, CONVERSION) \ if ((SRC_INDEX) < 0) { \ @@ -3531,7 +3548,7 @@ _mesa_unpack_color_span_ubyte(struct gl_context *ctx, const struct gl_pixelstore_attrib *srcPacking, GLbitfield transferOps ) { - GLboolean intFormat = _mesa_is_integer_format(srcFormat); + GLboolean intFormat = _mesa_is_enum_format_integer(srcFormat); ASSERT(dstFormat == GL_ALPHA || dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA || @@ -3838,7 +3855,7 @@ _mesa_unpack_color_span_float( struct gl_context *ctx, GLint dstComponents; GLint rDst, gDst, bDst, aDst, lDst, iDst; GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat)); - GLboolean intFormat = _mesa_is_integer_format(srcFormat); + GLboolean intFormat = _mesa_is_enum_format_integer(srcFormat); if (!rgba) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking"); diff --git a/mesalib/src/mesa/main/pack_tmp.h b/mesalib/src/mesa/main/pack_tmp.h index 83b655729..0d4eb387d 100644 --- a/mesalib/src/mesa/main/pack_tmp.h +++ b/mesalib/src/mesa/main/pack_tmp.h @@ -22,7 +22,8 @@ */ static void -FN_NAME(DST_TYPE *dst, +FN_NAME(struct gl_context *ctx, + DST_TYPE *dst, GLenum dstFormat, SRC_TYPE rgba[][4], int n) @@ -111,5 +112,11 @@ FN_NAME(DST_TYPE *dst, dst[i*2+1] = SRC_CONVERT(rgba[i][ACOMP]); } break; + + default: + _mesa_problem(ctx, + "Unsupported format (%s)", + _mesa_lookup_enum_by_nr(dstFormat)); + break; } } diff --git a/mesalib/src/mesa/main/pbo.c b/mesalib/src/mesa/main/pbo.c index d8fa9191d..c73d7492f 100644 --- a/mesalib/src/mesa/main/pbo.c +++ b/mesalib/src/mesa/main/pbo.c @@ -32,6 +32,7 @@ #include "glheader.h" #include "bufferobj.h" +#include "glformats.h" #include "image.h" #include "imports.h" #include "mtypes.h" @@ -172,11 +173,12 @@ _mesa_map_pbo_source(struct gl_context *ctx, */ const GLvoid * _mesa_map_validate_pbo_source(struct gl_context *ctx, - GLuint dimensions, - const struct gl_pixelstore_attrib *unpack, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, GLsizei clientMemSize, - const GLvoid *ptr, const char *where) + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, + GLsizei clientMemSize, + const GLvoid *ptr, const char *where) { ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3); @@ -268,11 +270,11 @@ _mesa_map_pbo_dest(struct gl_context *ctx, */ GLvoid * _mesa_map_validate_pbo_dest(struct gl_context *ctx, - GLuint dimensions, - const struct gl_pixelstore_attrib *unpack, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, GLsizei clientMemSize, - GLvoid *ptr, const char *where) + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLsizei clientMemSize, + GLvoid *ptr, const char *where) { ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3); @@ -339,12 +341,13 @@ _mesa_validate_pbo_teximage(struct gl_context *ctx, GLuint dimensions, return pixels; } if (!_mesa_validate_pbo_access(dimensions, unpack, width, height, depth, - format, type, INT_MAX, pixels)) { + format, type, INT_MAX, pixels)) { _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(invalid PBO access)"); return NULL; } - buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, unpack->BufferObj->Size, + buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, + unpack->BufferObj->Size, GL_MAP_READ_BIT, unpack->BufferObj); if (!buf) { @@ -407,5 +410,3 @@ _mesa_unmap_teximage_pbo(struct gl_context *ctx, ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj); } } - - diff --git a/mesalib/src/mesa/main/readpix.c b/mesalib/src/mesa/main/readpix.c index 138111049..7ac877497 100644 --- a/mesalib/src/mesa/main/readpix.c +++ b/mesalib/src/mesa/main/readpix.c @@ -36,6 +36,8 @@ #include "pack.h" #include "pbo.h" #include "state.h" +#include "glformats.h" +#include "fbobject.h" /** @@ -337,7 +339,7 @@ slow_read_rgba_pixels( struct gl_context *ctx, goto done; for (j = 0; j < height; j++) { - if (_mesa_is_integer_format(format)) { + if (_mesa_is_enum_format_integer(format)) { _mesa_unpack_uint_rgba_row(rbFormat, width, map, (GLuint (*)[4]) rgba); _mesa_rebase_rgba_uint(width, (GLuint (*)[4]) rgba, rb->_BaseFormat); @@ -378,7 +380,7 @@ read_rgba_pixels( struct gl_context *ctx, return; if ((ctx->Color._ClampReadColor == GL_TRUE || type != GL_FLOAT) && - !_mesa_is_integer_format(format)) { + !_mesa_is_enum_format_integer(format)) { transferOps |= IMAGE_CLAMP_BIT; } @@ -713,7 +715,7 @@ _mesa_ReadnPixelsARB( GLint x, GLint y, GLsizei width, GLsizei height, if (ctx->Extensions.EXT_texture_integer && _mesa_is_color_format(format)) { const struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; const GLboolean srcInteger = _mesa_is_format_integer_color(rb->Format); - const GLboolean dstInteger = _mesa_is_integer_format(format); + const GLboolean dstInteger = _mesa_is_enum_format_integer(format); if (dstInteger != srcInteger) { _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(integer / non-integer format mismatch"); @@ -721,7 +723,8 @@ _mesa_ReadnPixelsARB( GLint x, GLint y, GLsizei width, GLsizei height, } } - if (ctx->ReadBuffer->Name != 0 && ctx->ReadBuffer->Visual.samples > 0) { + if (_mesa_is_user_fbo(ctx->ReadBuffer) && + ctx->ReadBuffer->Visual.samples > 0) { _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(multisample FBO)"); return; } diff --git a/mesalib/src/mesa/main/shaderapi.c b/mesalib/src/mesa/main/shaderapi.c index 6927368de..7c97a6359 100644 --- a/mesalib/src/mesa/main/shaderapi.c +++ b/mesalib/src/mesa/main/shaderapi.c @@ -346,10 +346,12 @@ delete_shader(struct gl_context *ctx, GLuint shader) if (!sh) return; - sh->DeletePending = GL_TRUE; + if (!sh->DeletePending) { + sh->DeletePending = GL_TRUE; - /* effectively, decr sh's refcount */ - _mesa_reference_shader(ctx, &sh, NULL); + /* effectively, decr sh's refcount */ + _mesa_reference_shader(ctx, &sh, NULL); + } } diff --git a/mesalib/src/mesa/main/shared.c b/mesalib/src/mesa/main/shared.c index 226947638..58cbc5250 100644 --- a/mesalib/src/mesa/main/shared.c +++ b/mesalib/src/mesa/main/shared.c @@ -71,13 +71,15 @@ _mesa_alloc_shared_state(struct gl_context *ctx) shared->Programs = _mesa_NewHashTable(); #if FEATURE_ARB_vertex_program - shared->DefaultVertexProgram = (struct gl_vertex_program *) - ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); + shared->DefaultVertexProgram = + gl_vertex_program(ctx->Driver.NewProgram(ctx, + GL_VERTEX_PROGRAM_ARB, 0)); #endif #if FEATURE_ARB_fragment_program - shared->DefaultFragmentProgram = (struct gl_fragment_program *) - ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); + shared->DefaultFragmentProgram = + gl_fragment_program(ctx->Driver.NewProgram(ctx, + GL_FRAGMENT_PROGRAM_ARB, 0)); #endif #if FEATURE_ATI_fragment_shader diff --git a/mesalib/src/mesa/main/state.c b/mesalib/src/mesa/main/state.c index db0cc30ec..76946bd93 100644 --- a/mesalib/src/mesa/main/state.c +++ b/mesalib/src/mesa/main/state.c @@ -134,8 +134,7 @@ update_program(struct gl_context *ctx) &ctx->Shader._CurrentFragmentProgram, fsProg); _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, - (struct gl_fragment_program *) - fsProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program); + gl_fragment_program(fsProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program)); _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL); } @@ -157,11 +156,9 @@ update_program(struct gl_context *ctx) &ctx->Shader._CurrentFragmentProgram, f); _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, - (struct gl_fragment_program *) - f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program); + gl_fragment_program(f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program)); _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, - (struct gl_fragment_program *) - f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program); + gl_fragment_program(f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program)); } else { /* No fragment program */ @@ -174,8 +171,7 @@ update_program(struct gl_context *ctx) && gsProg->_LinkedShaders[MESA_SHADER_GEOMETRY]) { /* Use GLSL geometry shader */ _mesa_reference_geomprog(ctx, &ctx->GeometryProgram._Current, - (struct gl_geometry_program *) - gsProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->Program); + gl_geometry_program(gsProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->Program)); } else { /* No geometry program */ _mesa_reference_geomprog(ctx, &ctx->GeometryProgram._Current, NULL); @@ -189,8 +185,7 @@ update_program(struct gl_context *ctx) && vsProg->_LinkedShaders[MESA_SHADER_VERTEX]) { /* Use GLSL vertex shader */ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, - (struct gl_vertex_program *) - vsProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program); + gl_vertex_program(vsProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program)); } else if (ctx->VertexProgram._Enabled) { /* Use user-defined vertex program */ diff --git a/mesalib/src/mesa/main/texformat.c b/mesalib/src/mesa/main/texformat.c index 26bcbc10a..d360f0e22 100644 --- a/mesalib/src/mesa/main/texformat.c +++ b/mesalib/src/mesa/main/texformat.c @@ -887,6 +887,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat, switch (internalFormat) { case GL_RGB10_A2UI: RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010_UINT); + RETURN_IF_SUPPORTED(MESA_FORMAT_ABGR2101010_UINT); break; default: break; @@ -894,7 +895,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat, } /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0). */ - if (ctx->API != API_OPENGL) { + if (_mesa_is_gles(ctx)) { switch (internalFormat) { case GL_BGRA: RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888); diff --git a/mesalib/src/mesa/main/texgetimage.c b/mesalib/src/mesa/main/texgetimage.c index 05b052a01..0ba3ff5b3 100644 --- a/mesalib/src/mesa/main/texgetimage.c +++ b/mesalib/src/mesa/main/texgetimage.c @@ -35,6 +35,7 @@ #include "context.h" #include "formats.h" #include "format_unpack.h" +#include "glformats.h" #include "image.h" #include "mfeatures.h" #include "mtypes.h" diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c index 64b25a82d..d2746c6f3 100644 --- a/mesalib/src/mesa/main/teximage.c +++ b/mesalib/src/mesa/main/teximage.c @@ -47,6 +47,7 @@ #include "texstate.h" #include "texpal.h" #include "mtypes.h" +#include "glformats.h" /** @@ -129,7 +130,7 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0). */ - if (ctx->API != API_OPENGL) { + if (_mesa_is_gles(ctx)) { switch (internalFormat) { case GL_BGRA: return GL_RGBA; @@ -1764,8 +1765,8 @@ texture_error_check( struct gl_context *ctx, /* additional checks for integer textures */ if ((ctx->VersionMajor >= 3 || ctx->Extensions.EXT_texture_integer) && - (_mesa_is_integer_format(format) != - _mesa_is_integer_format(internalFormat))) { + (_mesa_is_enum_format_integer(format) != + _mesa_is_enum_format_integer(internalFormat))) { if (!isProxy) { _mesa_error(ctx, GL_INVALID_OPERATION, "glTexImage%dD(integer/non-integer format mismatch)", @@ -1939,7 +1940,7 @@ subtexture_error_check2( struct gl_context *ctx, GLuint dimensions, if (ctx->VersionMajor >= 3 || ctx->Extensions.EXT_texture_integer) { /* both source and dest must be integer-valued, or neither */ if (_mesa_is_format_integer_color(destTex->TexFormat) != - _mesa_is_integer_format(format)) { + _mesa_is_enum_format_integer(format)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD(integer/non-integer format mismatch)", dimensions); @@ -2042,8 +2043,8 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions, if (_mesa_is_color_format(internalFormat)) { struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; - if (_mesa_is_integer_format(rb->InternalFormat) != - _mesa_is_integer_format(internalFormat)) { + if (_mesa_is_enum_format_integer(rb->InternalFormat) != + _mesa_is_enum_format_integer(internalFormat)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexImage%dD(integer vs non-integer)", dimensions); return GL_TRUE; diff --git a/mesalib/src/mesa/main/texparam.c b/mesalib/src/mesa/main/texparam.c index 9abc503e3..1376219d7 100644 --- a/mesalib/src/mesa/main/texparam.c +++ b/mesalib/src/mesa/main/texparam.c @@ -35,7 +35,7 @@ #include "main/context.h" #include "main/enums.h" #include "main/formats.h" -#include "main/image.h" +#include "main/glformats.h" #include "main/macros.h" #include "main/mfeatures.h" #include "main/mtypes.h" diff --git a/mesalib/src/mesa/main/texstore.c b/mesalib/src/mesa/main/texstore.c index 1ced8aac9..ab9fdf26d 100644 --- a/mesalib/src/mesa/main/texstore.c +++ b/mesalib/src/mesa/main/texstore.c @@ -37,9 +37,8 @@ * However, most device drivers will be able to use the fallback functions * in this file. That is, most drivers will have the following bit of * code: - * ctx->Driver.TexImage1D = _mesa_store_teximage1d; - * ctx->Driver.TexImage2D = _mesa_store_teximage2d; - * ctx->Driver.TexImage3D = _mesa_store_teximage3d; + * ctx->Driver.TexImage = _mesa_store_teximage; + * ctx->Driver.TexSubImage = _mesa_store_texsubimage; * etc... * * Texture image processing is actually kind of complicated. We have to do: @@ -72,6 +71,7 @@ #include "teximage.h" #include "texstore.h" #include "enums.h" +#include "glformats.h" #include "../../gallium/auxiliary/util/u_format_rgb9e5.h" #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h" @@ -3892,6 +3892,72 @@ _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS) } static GLboolean +_mesa_texstore_abgr2101010_uint(TEXSTORE_PARAMS) +{ + const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); + + ASSERT(dstFormat == MESA_FORMAT_ABGR2101010_UINT); + ASSERT(_mesa_get_format_bytes(dstFormat) == 4); + + if (baseInternalFormat == GL_RGBA && + _mesa_format_matches_format_and_type(dstFormat, srcFormat, srcType, + srcPacking->SwapBytes)) { + /* simple memcpy path */ + memcpy_texture(ctx, dims, + dstFormat, + dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, srcFormat, srcType, + srcAddr, srcPacking); + } + else { + /* general path */ + const GLuint *tempImage = make_temp_uint_image(ctx, dims, + baseInternalFormat, + baseFormat, + srcWidth, srcHeight, + srcDepth, srcFormat, + srcType, srcAddr, + srcPacking); + const GLuint *src = tempImage; + GLint img, row, col; + GLboolean is_unsigned = _mesa_is_type_unsigned(srcType); + if (!tempImage) + return GL_FALSE; + for (img = 0; img < srcDepth; img++) { + GLubyte *dstRow = dstSlices[img]; + + for (row = 0; row < srcHeight; row++) { + GLuint *dstUI = (GLuint *) dstRow; + if (is_unsigned) { + for (col = 0; col < srcWidth; col++) { + GLushort a,r,g,b; + r = MIN2(src[RCOMP], 0x3ff); + g = MIN2(src[GCOMP], 0x3ff); + b = MIN2(src[BCOMP], 0x3ff); + a = MIN2(src[ACOMP], 0x003); + dstUI[col] = (a << 30) | (b << 20) | (g << 10) | (r); + src += 4; + } + } else { + for (col = 0; col < srcWidth; col++) { + GLushort a,r,g,b; + r = CLAMP((GLint) src[RCOMP], 0, 0x3ff); + g = CLAMP((GLint) src[GCOMP], 0, 0x3ff); + b = CLAMP((GLint) src[BCOMP], 0, 0x3ff); + a = CLAMP((GLint) src[ACOMP], 0, 0x003); + dstUI[col] = (a << 30) | (b << 20) | (g << 10) | (r); + src += 4; + } + } + dstRow += dstRowStride; + } + } + free((void *) tempImage); + } + return GL_TRUE; +} + +static GLboolean _mesa_texstore_null(TEXSTORE_PARAMS) { (void) ctx; (void) dims; @@ -4085,6 +4151,7 @@ _mesa_get_texstore_func(gl_format format) table[MESA_FORMAT_RGBA_UINT32] = _mesa_texstore_rgba_uint32; table[MESA_FORMAT_ARGB2101010_UINT] = _mesa_texstore_argb2101010_uint; + table[MESA_FORMAT_ABGR2101010_UINT] = _mesa_texstore_abgr2101010_uint; initialized = GL_TRUE; } diff --git a/mesalib/src/mesa/main/uniform_query.cpp b/mesalib/src/mesa/main/uniform_query.cpp index f5d998ffb..816c2779c 100644 --- a/mesalib/src/mesa/main/uniform_query.cpp +++ b/mesalib/src/mesa/main/uniform_query.cpp @@ -74,6 +74,79 @@ _mesa_GetActiveUniformARB(GLhandleARB program, GLuint index, } } +extern "C" void GLAPIENTRY +_mesa_GetActiveUniformsiv(GLuint program, + GLsizei uniformCount, + const GLuint *uniformIndices, + GLenum pname, + GLint *params) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_shader_program *shProg; + GLsizei i; + + shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveUniform"); + if (!shProg) + return; + + if (uniformCount < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetUniformIndices(uniformCount < 0)"); + return; + } + + for (i = 0; i < uniformCount; i++) { + GLuint index = uniformIndices[i]; + const struct gl_uniform_storage *uni = &shProg->UniformStorage[index]; + + if (index >= shProg->NumUserUniformStorage) { + _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniformsiv(index)"); + return; + } + + switch (pname) { + case GL_UNIFORM_TYPE: + params[i] = uni->type->gl_type; + break; + + case GL_UNIFORM_SIZE: + /* array_elements is zero for non-arrays, but the API requires that 1 be + * returned. + */ + params[i] = MAX2(1, uni->array_elements); + break; + + case GL_UNIFORM_NAME_LENGTH: + params[i] = strlen(uni->name) + 1; + break; + + case GL_UNIFORM_BLOCK_INDEX: + params[i] = uni->block_index; + break; + + case GL_UNIFORM_OFFSET: + params[i] = uni->offset; + break; + + case GL_UNIFORM_ARRAY_STRIDE: + params[i] = uni->array_stride; + break; + + case GL_UNIFORM_MATRIX_STRIDE: + params[i] = uni->matrix_stride; + break; + + case GL_UNIFORM_IS_ROW_MAJOR: + params[i] = uni->row_major; + break; + + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glGetActiveUniformsiv(pname)"); + return; + } + } +} + static bool validate_uniform_parameters(struct gl_context *ctx, struct gl_shader_program *shProg, @@ -852,13 +925,17 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg, /** * Called via glGetUniformLocation(). * - * The return value will encode two values, the uniform location and an - * offset (used for arrays, structs). + * Returns the uniform index into UniformStorage (also the + * glGetActiveUniformsiv uniform index), and stores the referenced + * array offset in *offset, or GL_INVALID_INDEX (-1). Those two + * return values can be encoded into a uniform location for + * glUniform* using _mesa_uniform_merge_location_offset(index, offset). */ -extern "C" GLint +extern "C" unsigned _mesa_get_uniform_location(struct gl_context *ctx, struct gl_shader_program *shProg, - const GLchar *name) + const GLchar *name, + unsigned *out_offset) { const size_t len = strlen(name); long offset; @@ -901,13 +978,13 @@ _mesa_get_uniform_location(struct gl_context *ctx, * (or other non-digit characters) before the opening '['. */ if ((i == 0) || name[i-1] != '[') - return -1; + return GL_INVALID_INDEX; /* Return an error if there are no digits between the opening '[' to * match the closing ']'. */ if (i == (len - 1)) - return -1; + return GL_INVALID_INDEX; /* Make a new string that is a copy of the old string up to (but not * including) the '[' character. @@ -919,7 +996,7 @@ _mesa_get_uniform_location(struct gl_context *ctx, offset = strtol(&name[i], NULL, 10); if (offset < 0) { free(name_copy); - return -1; + return GL_INVALID_INDEX; } array_lookup = true; @@ -941,16 +1018,17 @@ _mesa_get_uniform_location(struct gl_context *ctx, free(name_copy); if (!found) - return -1; + return GL_INVALID_INDEX; /* Since array_elements is 0 for non-arrays, this causes look-ups of 'a[0]' * to (correctly) fail if 'a' is not an array. */ if (array_lookup && shProg->UniformStorage[location].array_elements == 0) { - return -1; + return GL_INVALID_INDEX; } - return _mesa_uniform_merge_location_offset(location, offset); + *out_offset = offset; + return location; } extern "C" bool diff --git a/mesalib/src/mesa/main/uniforms.c b/mesalib/src/mesa/main/uniforms.c index e6604b1a4..ccbd753db 100644 --- a/mesalib/src/mesa/main/uniforms.c +++ b/mesalib/src/mesa/main/uniforms.c @@ -497,6 +497,7 @@ GLint GLAPIENTRY _mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name) { struct gl_shader_program *shProg; + GLuint index, offset; GET_CURRENT_CONTEXT(ctx); @@ -516,9 +517,71 @@ _mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name) return -1; } - return _mesa_get_uniform_location(ctx, shProg, name); + index = _mesa_get_uniform_location(ctx, shProg, name, &offset); + if (index == GL_INVALID_INDEX) + return -1; + + return _mesa_uniform_merge_location_offset(index, offset); } +static GLuint GLAPIENTRY +_mesa_GetUniformBlockIndex(GLuint program, + const GLchar *uniformBlockName) +{ + GET_CURRENT_CONTEXT(ctx); + GLuint i; + struct gl_shader_program *shProg; + + if (!ctx->Extensions.ARB_uniform_buffer_object) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformBlockIndex"); + return GL_INVALID_INDEX; + } + + shProg = _mesa_lookup_shader_program_err(ctx, program, + "glGetUniformBlockIndex"); + if (!shProg) + return GL_INVALID_INDEX; + + for (i = 0; i < shProg->NumUniformBlocks; i++) { + if (!strcmp(shProg->UniformBlocks[i].Name, uniformBlockName)) + return i; + } + + return GL_INVALID_INDEX; +} + +static void GLAPIENTRY +_mesa_GetUniformIndices(GLuint program, + GLsizei uniformCount, + const GLchar * const *uniformNames, + GLuint *uniformIndices) +{ + GET_CURRENT_CONTEXT(ctx); + GLsizei i; + struct gl_shader_program *shProg; + + if (!ctx->Extensions.ARB_uniform_buffer_object) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformIndices"); + return; + } + + shProg = _mesa_lookup_shader_program_err(ctx, program, + "glGetUniformIndices"); + if (!shProg) + return; + + if (uniformCount < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetUniformIndices(uniformCount < 0)"); + return; + } + + for (i = 0; i < uniformCount; i++) { + unsigned offset; + uniformIndices[i] = _mesa_get_uniform_location(ctx, shProg, + uniformNames[i], &offset); + } +} /** * Plug in shader uniform-related functions into API dispatch table. @@ -577,5 +640,10 @@ _mesa_init_shader_uniform_dispatch(struct _glapi_table *exec) SET_GetnUniformuivARB(exec, _mesa_GetnUniformuivARB); SET_GetnUniformdvARB(exec, _mesa_GetnUniformdvARB); /* GL 4.0 */ + /* GL_ARB_uniform_buffer_object / GL 3.1 */ + SET_GetUniformBlockIndex(exec, _mesa_GetUniformBlockIndex); + SET_GetUniformIndices(exec, _mesa_GetUniformIndices); + SET_GetActiveUniformsiv(exec, _mesa_GetActiveUniformsiv); + #endif /* FEATURE_GL */ } diff --git a/mesalib/src/mesa/main/uniforms.h b/mesalib/src/mesa/main/uniforms.h index 7b512a527..bb0552476 100644 --- a/mesalib/src/mesa/main/uniforms.h +++ b/mesalib/src/mesa/main/uniforms.h @@ -150,6 +150,13 @@ _mesa_GetActiveUniformARB(GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); extern void GLAPIENTRY +_mesa_GetActiveUniformsiv(GLuint program, + GLsizei uniformCount, + const GLuint *uniformIndices, + GLenum pname, + GLint *params); + +extern void GLAPIENTRY _mesa_GetUniformfvARB(GLhandleARB, GLint, GLfloat *); extern void GLAPIENTRY @@ -176,9 +183,9 @@ _mesa_GetnUniformdvARB(GLhandleARB, GLint, GLsizei, GLdouble *); extern GLint GLAPIENTRY _mesa_GetUniformLocationARB(GLhandleARB, const GLcharARB *); -GLint +unsigned _mesa_get_uniform_location(struct gl_context *ctx, struct gl_shader_program *shProg, - const GLchar *name); + const GLchar *name, unsigned *offset); void _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shader_program, diff --git a/mesalib/src/mesa/main/varray.c b/mesalib/src/mesa/main/varray.c index efa63b07c..7ec7cfee6 100644 --- a/mesalib/src/mesa/main/varray.c +++ b/mesalib/src/mesa/main/varray.c @@ -92,7 +92,7 @@ type_to_bit(const struct gl_context *ctx, GLenum type) case GL_DOUBLE: return DOUBLE_BIT; case GL_FIXED: - return ctx->API == API_OPENGL ? FIXED_GL_BIT : FIXED_ES_BIT; + return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT; case GL_UNSIGNED_INT_2_10_10_10_REV: return UNSIGNED_INT_2_10_10_10_REV_BIT; case GL_INT_2_10_10_10_REV: diff --git a/mesalib/src/mesa/main/version.c b/mesalib/src/mesa/main/version.c index 38d2b3398..0fe3a8412 100644 --- a/mesalib/src/mesa/main/version.c +++ b/mesalib/src/mesa/main/version.c @@ -315,6 +315,7 @@ _mesa_compute_version(struct gl_context *ctx) switch (ctx->API) { case API_OPENGL: + case API_OPENGL_CORE: compute_version(ctx); break; case API_OPENGLES: diff --git a/mesalib/src/mesa/main/vtxfmt.c b/mesalib/src/mesa/main/vtxfmt.c index bf7a54c0a..ce490ed9e 100644 --- a/mesalib/src/mesa/main/vtxfmt.c +++ b/mesalib/src/mesa/main/vtxfmt.c @@ -45,57 +45,64 @@ * API dispatch table. */ static void -install_vtxfmt( struct _glapi_table *tab, const GLvertexformat *vfmt ) +install_vtxfmt(struct gl_context *ctx, struct _glapi_table *tab, + const GLvertexformat *vfmt) { _mesa_install_arrayelt_vtxfmt(tab, vfmt); - SET_Color3f(tab, vfmt->Color3f); - SET_Color3fv(tab, vfmt->Color3fv); - SET_Color4f(tab, vfmt->Color4f); - SET_Color4fv(tab, vfmt->Color4fv); - SET_EdgeFlag(tab, vfmt->EdgeFlag); + if (ctx->API != API_OPENGL_CORE) { + SET_Color3f(tab, vfmt->Color3f); + SET_Color3fv(tab, vfmt->Color3fv); + SET_Color4f(tab, vfmt->Color4f); + SET_Color4fv(tab, vfmt->Color4fv); + SET_EdgeFlag(tab, vfmt->EdgeFlag); + } _mesa_install_eval_vtxfmt(tab, vfmt); - SET_FogCoordfEXT(tab, vfmt->FogCoordfEXT); - SET_FogCoordfvEXT(tab, vfmt->FogCoordfvEXT); - SET_Indexf(tab, vfmt->Indexf); - SET_Indexfv(tab, vfmt->Indexfv); - SET_Materialfv(tab, vfmt->Materialfv); - SET_MultiTexCoord1fARB(tab, vfmt->MultiTexCoord1fARB); - SET_MultiTexCoord1fvARB(tab, vfmt->MultiTexCoord1fvARB); - SET_MultiTexCoord2fARB(tab, vfmt->MultiTexCoord2fARB); - SET_MultiTexCoord2fvARB(tab, vfmt->MultiTexCoord2fvARB); - SET_MultiTexCoord3fARB(tab, vfmt->MultiTexCoord3fARB); - SET_MultiTexCoord3fvARB(tab, vfmt->MultiTexCoord3fvARB); - SET_MultiTexCoord4fARB(tab, vfmt->MultiTexCoord4fARB); - SET_MultiTexCoord4fvARB(tab, vfmt->MultiTexCoord4fvARB); - SET_Normal3f(tab, vfmt->Normal3f); - SET_Normal3fv(tab, vfmt->Normal3fv); - SET_SecondaryColor3fEXT(tab, vfmt->SecondaryColor3fEXT); - SET_SecondaryColor3fvEXT(tab, vfmt->SecondaryColor3fvEXT); - SET_TexCoord1f(tab, vfmt->TexCoord1f); - SET_TexCoord1fv(tab, vfmt->TexCoord1fv); - SET_TexCoord2f(tab, vfmt->TexCoord2f); - SET_TexCoord2fv(tab, vfmt->TexCoord2fv); - SET_TexCoord3f(tab, vfmt->TexCoord3f); - SET_TexCoord3fv(tab, vfmt->TexCoord3fv); - SET_TexCoord4f(tab, vfmt->TexCoord4f); - SET_TexCoord4fv(tab, vfmt->TexCoord4fv); - SET_Vertex2f(tab, vfmt->Vertex2f); - SET_Vertex2fv(tab, vfmt->Vertex2fv); - SET_Vertex3f(tab, vfmt->Vertex3f); - SET_Vertex3fv(tab, vfmt->Vertex3fv); - SET_Vertex4f(tab, vfmt->Vertex4f); - SET_Vertex4fv(tab, vfmt->Vertex4fv); + if (ctx->API != API_OPENGL_CORE) { + SET_FogCoordfEXT(tab, vfmt->FogCoordfEXT); + SET_FogCoordfvEXT(tab, vfmt->FogCoordfvEXT); + SET_Indexf(tab, vfmt->Indexf); + SET_Indexfv(tab, vfmt->Indexfv); + SET_Materialfv(tab, vfmt->Materialfv); + SET_MultiTexCoord1fARB(tab, vfmt->MultiTexCoord1fARB); + SET_MultiTexCoord1fvARB(tab, vfmt->MultiTexCoord1fvARB); + SET_MultiTexCoord2fARB(tab, vfmt->MultiTexCoord2fARB); + SET_MultiTexCoord2fvARB(tab, vfmt->MultiTexCoord2fvARB); + SET_MultiTexCoord3fARB(tab, vfmt->MultiTexCoord3fARB); + SET_MultiTexCoord3fvARB(tab, vfmt->MultiTexCoord3fvARB); + SET_MultiTexCoord4fARB(tab, vfmt->MultiTexCoord4fARB); + SET_MultiTexCoord4fvARB(tab, vfmt->MultiTexCoord4fvARB); + SET_Normal3f(tab, vfmt->Normal3f); + SET_Normal3fv(tab, vfmt->Normal3fv); + SET_SecondaryColor3fEXT(tab, vfmt->SecondaryColor3fEXT); + SET_SecondaryColor3fvEXT(tab, vfmt->SecondaryColor3fvEXT); + SET_TexCoord1f(tab, vfmt->TexCoord1f); + SET_TexCoord1fv(tab, vfmt->TexCoord1fv); + SET_TexCoord2f(tab, vfmt->TexCoord2f); + SET_TexCoord2fv(tab, vfmt->TexCoord2fv); + SET_TexCoord3f(tab, vfmt->TexCoord3f); + SET_TexCoord3fv(tab, vfmt->TexCoord3fv); + SET_TexCoord4f(tab, vfmt->TexCoord4f); + SET_TexCoord4fv(tab, vfmt->TexCoord4fv); + SET_Vertex2f(tab, vfmt->Vertex2f); + SET_Vertex2fv(tab, vfmt->Vertex2fv); + SET_Vertex3f(tab, vfmt->Vertex3f); + SET_Vertex3fv(tab, vfmt->Vertex3fv); + SET_Vertex4f(tab, vfmt->Vertex4f); + SET_Vertex4fv(tab, vfmt->Vertex4fv); + } _mesa_install_dlist_vtxfmt(tab, vfmt); /* glCallList / glCallLists */ - SET_Begin(tab, vfmt->Begin); - SET_End(tab, vfmt->End); - SET_PrimitiveRestartNV(tab, vfmt->PrimitiveRestartNV); + if (ctx->API != API_OPENGL_CORE) { + SET_Begin(tab, vfmt->Begin); + SET_End(tab, vfmt->End); + SET_PrimitiveRestartNV(tab, vfmt->PrimitiveRestartNV); - SET_Rectf(tab, vfmt->Rectf); + SET_Rectf(tab, vfmt->Rectf); + } SET_DrawArrays(tab, vfmt->DrawArrays); SET_DrawElements(tab, vfmt->DrawElements); @@ -154,42 +161,44 @@ install_vtxfmt( struct _glapi_table *tab, const GLvertexformat *vfmt ) SET_VertexAttribI3uivEXT(tab, vfmt->VertexAttribI3uiv); SET_VertexAttribI4uivEXT(tab, vfmt->VertexAttribI4uiv); - /* GL_ARB_vertex_type_10_10_10_2_rev / GL 3.3 */ - SET_VertexP2ui(tab, vfmt->VertexP2ui); - SET_VertexP2uiv(tab, vfmt->VertexP2uiv); - SET_VertexP3ui(tab, vfmt->VertexP3ui); - SET_VertexP3uiv(tab, vfmt->VertexP3uiv); - SET_VertexP4ui(tab, vfmt->VertexP4ui); - SET_VertexP4uiv(tab, vfmt->VertexP4uiv); - - SET_TexCoordP1ui(tab, vfmt->TexCoordP1ui); - SET_TexCoordP1uiv(tab, vfmt->TexCoordP1uiv); - SET_TexCoordP2ui(tab, vfmt->TexCoordP2ui); - SET_TexCoordP2uiv(tab, vfmt->TexCoordP2uiv); - SET_TexCoordP3ui(tab, vfmt->TexCoordP3ui); - SET_TexCoordP3uiv(tab, vfmt->TexCoordP3uiv); - SET_TexCoordP4ui(tab, vfmt->TexCoordP4ui); - SET_TexCoordP4uiv(tab, vfmt->TexCoordP4uiv); - - SET_MultiTexCoordP1ui(tab, vfmt->MultiTexCoordP1ui); - SET_MultiTexCoordP2ui(tab, vfmt->MultiTexCoordP2ui); - SET_MultiTexCoordP3ui(tab, vfmt->MultiTexCoordP3ui); - SET_MultiTexCoordP4ui(tab, vfmt->MultiTexCoordP4ui); - SET_MultiTexCoordP1uiv(tab, vfmt->MultiTexCoordP1uiv); - SET_MultiTexCoordP2uiv(tab, vfmt->MultiTexCoordP2uiv); - SET_MultiTexCoordP3uiv(tab, vfmt->MultiTexCoordP3uiv); - SET_MultiTexCoordP4uiv(tab, vfmt->MultiTexCoordP4uiv); - - SET_NormalP3ui(tab, vfmt->NormalP3ui); - SET_NormalP3uiv(tab, vfmt->NormalP3uiv); - - SET_ColorP3ui(tab, vfmt->ColorP3ui); - SET_ColorP4ui(tab, vfmt->ColorP4ui); - SET_ColorP3uiv(tab, vfmt->ColorP3uiv); - SET_ColorP4uiv(tab, vfmt->ColorP4uiv); - - SET_SecondaryColorP3ui(tab, vfmt->SecondaryColorP3ui); - SET_SecondaryColorP3uiv(tab, vfmt->SecondaryColorP3uiv); + if (ctx->API != API_OPENGL_CORE) { + /* GL_ARB_vertex_type_10_10_10_2_rev / GL 3.3 */ + SET_VertexP2ui(tab, vfmt->VertexP2ui); + SET_VertexP2uiv(tab, vfmt->VertexP2uiv); + SET_VertexP3ui(tab, vfmt->VertexP3ui); + SET_VertexP3uiv(tab, vfmt->VertexP3uiv); + SET_VertexP4ui(tab, vfmt->VertexP4ui); + SET_VertexP4uiv(tab, vfmt->VertexP4uiv); + + SET_TexCoordP1ui(tab, vfmt->TexCoordP1ui); + SET_TexCoordP1uiv(tab, vfmt->TexCoordP1uiv); + SET_TexCoordP2ui(tab, vfmt->TexCoordP2ui); + SET_TexCoordP2uiv(tab, vfmt->TexCoordP2uiv); + SET_TexCoordP3ui(tab, vfmt->TexCoordP3ui); + SET_TexCoordP3uiv(tab, vfmt->TexCoordP3uiv); + SET_TexCoordP4ui(tab, vfmt->TexCoordP4ui); + SET_TexCoordP4uiv(tab, vfmt->TexCoordP4uiv); + + SET_MultiTexCoordP1ui(tab, vfmt->MultiTexCoordP1ui); + SET_MultiTexCoordP2ui(tab, vfmt->MultiTexCoordP2ui); + SET_MultiTexCoordP3ui(tab, vfmt->MultiTexCoordP3ui); + SET_MultiTexCoordP4ui(tab, vfmt->MultiTexCoordP4ui); + SET_MultiTexCoordP1uiv(tab, vfmt->MultiTexCoordP1uiv); + SET_MultiTexCoordP2uiv(tab, vfmt->MultiTexCoordP2uiv); + SET_MultiTexCoordP3uiv(tab, vfmt->MultiTexCoordP3uiv); + SET_MultiTexCoordP4uiv(tab, vfmt->MultiTexCoordP4uiv); + + SET_NormalP3ui(tab, vfmt->NormalP3ui); + SET_NormalP3uiv(tab, vfmt->NormalP3uiv); + + SET_ColorP3ui(tab, vfmt->ColorP3ui); + SET_ColorP4ui(tab, vfmt->ColorP4ui); + SET_ColorP3uiv(tab, vfmt->ColorP3uiv); + SET_ColorP4uiv(tab, vfmt->ColorP4uiv); + + SET_SecondaryColorP3ui(tab, vfmt->SecondaryColorP3ui); + SET_SecondaryColorP3uiv(tab, vfmt->SecondaryColorP3uiv); + } SET_VertexAttribP1ui(tab, vfmt->VertexAttribP1ui); SET_VertexAttribP2ui(tab, vfmt->VertexAttribP2ui); @@ -209,8 +218,8 @@ install_vtxfmt( struct _glapi_table *tab, const GLvertexformat *vfmt ) void _mesa_install_exec_vtxfmt(struct gl_context *ctx, const GLvertexformat *vfmt) { - if (ctx->API == API_OPENGL) - install_vtxfmt( ctx->Exec, vfmt ); + if (_mesa_is_desktop_gl(ctx)) + install_vtxfmt( ctx, ctx->Exec, vfmt ); } @@ -221,8 +230,8 @@ _mesa_install_exec_vtxfmt(struct gl_context *ctx, const GLvertexformat *vfmt) void _mesa_install_save_vtxfmt(struct gl_context *ctx, const GLvertexformat *vfmt) { - if (ctx->API == API_OPENGL) - install_vtxfmt( ctx->Save, vfmt ); + if (_mesa_is_desktop_gl(ctx)) + install_vtxfmt( ctx, ctx->Save, vfmt ); } |