X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fattrib.c;h=f859191f69c76dc4c3724170804a47b6da5e4c56;hb=f5ac1d366e81ee9ad11f44ee64a5b556bc6f1989;hp=87c7f66eb1129bdfe469e2e2812ae865bd92a383;hpb=12cbe995edbbf2791459579918486413965d4bf0;p=mesa.git diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index 87c7f66eb11..f859191f69c 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -32,7 +32,6 @@ #include "buffers.h" #include "bufferobj.h" #include "clear.h" -#include "colormac.h" #include "context.h" #include "depth.h" #include "enable.h" @@ -112,7 +111,7 @@ struct gl_enable_attrib GLboolean PolygonSmooth; GLboolean PolygonStipple; GLboolean RescaleNormals; - GLboolean Scissor; + GLbitfield Scissor; GLboolean Stencil; GLboolean StencilTwoSide; /* GL_EXT_stencil_two_side */ GLboolean MultisampleEnabled; /* GL_ARB_multisample */ @@ -178,11 +177,15 @@ struct texture_state }; +/** An unused GL_*_BIT value */ +#define DUMMY_BIT 0x10000000 + + /** * Allocate new attribute node of given type/kind. Attach payload data. * Insert it into the linked list named by 'head'. */ -static void +static bool save_attrib_data(struct gl_attrib_node **head, GLbitfield kind, void *payload) { @@ -196,7 +199,42 @@ save_attrib_data(struct gl_attrib_node **head, } else { /* out of memory! */ + return false; + } + return true; +} + + +/** + * Helper function for_mesa_PushAttrib for simple attributes. + * Allocates memory for attribute data and copies the given attribute data. + * \param head head of linked list to insert attribute data into + * \param attr_bit one of the GL__BIT flags + * \param attr_size number of bytes to allocate for attribute data + * \param attr_data the attribute data to copy + * \return true for success, false for out of memory + */ +static bool +push_attrib(struct gl_context *ctx, struct gl_attrib_node **head, + GLbitfield attr_bit, GLuint attr_size, const void *attr_data) +{ + void *attribute; + + attribute = malloc(attr_size); + if (attribute == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + return false; + } + + if (save_attrib_data(head, attr_bit, attribute)) { + memcpy(attribute, attr_data, attr_size); + } + else { + free(attribute); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + return false; } + return true; } @@ -219,43 +257,68 @@ _mesa_PushAttrib(GLbitfield mask) /* groups specified by the mask. */ head = NULL; + if (mask == 0) { + /* if mask is zero we still need to push something so that we + * don't get a GL_STACK_UNDERFLOW error in glPopAttrib(). + */ + GLuint dummy = 0; + if (!push_attrib(ctx, &head, DUMMY_BIT, sizeof(dummy), &dummy)) + goto end; + } + if (mask & GL_ACCUM_BUFFER_BIT) { - struct gl_accum_attrib *attr; - attr = MALLOC_STRUCT( gl_accum_attrib ); - memcpy( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) ); - save_attrib_data(&head, GL_ACCUM_BUFFER_BIT, attr); + if (!push_attrib(ctx, &head, GL_ACCUM_BUFFER_BIT, + sizeof(struct gl_accum_attrib), + (void*)&ctx->Accum)) + goto end; } if (mask & GL_COLOR_BUFFER_BIT) { GLuint i; struct gl_colorbuffer_attrib *attr; attr = MALLOC_STRUCT( gl_colorbuffer_attrib ); - memcpy( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) ); - /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */ - for (i = 0; i < ctx->Const.MaxDrawBuffers; i ++) - attr->DrawBuffer[i] = ctx->DrawBuffer->ColorDrawBuffer[i]; - save_attrib_data(&head, GL_COLOR_BUFFER_BIT, attr); + if (attr == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + goto end; + } + + if (save_attrib_data(&head, GL_COLOR_BUFFER_BIT, attr)) { + memcpy(attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib)); + /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */ + for (i = 0; i < ctx->Const.MaxDrawBuffers; i ++) + attr->DrawBuffer[i] = ctx->DrawBuffer->ColorDrawBuffer[i]; + } + else { + free(attr); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + goto end; + } } if (mask & GL_CURRENT_BIT) { - struct gl_current_attrib *attr; - FLUSH_CURRENT( ctx, 0 ); - attr = MALLOC_STRUCT( gl_current_attrib ); - memcpy( attr, &ctx->Current, sizeof(struct gl_current_attrib) ); - save_attrib_data(&head, GL_CURRENT_BIT, attr); + FLUSH_CURRENT(ctx, 0); + if (!push_attrib(ctx, &head, GL_CURRENT_BIT, + sizeof(struct gl_current_attrib), + (void*)&ctx->Current)) + goto end; } if (mask & GL_DEPTH_BUFFER_BIT) { - struct gl_depthbuffer_attrib *attr; - attr = MALLOC_STRUCT( gl_depthbuffer_attrib ); - memcpy( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) ); - save_attrib_data(&head, GL_DEPTH_BUFFER_BIT, attr); + if (!push_attrib(ctx, &head, GL_DEPTH_BUFFER_BIT, + sizeof(struct gl_depthbuffer_attrib), + (void*)&ctx->Depth)) + goto end; } if (mask & GL_ENABLE_BIT) { struct gl_enable_attrib *attr; GLuint i; attr = MALLOC_STRUCT( gl_enable_attrib ); + if (attr == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + goto end; + } + /* Copy enable flags from all other attributes into the enable struct. */ attr->AlphaTest = ctx->Color.AlphaEnabled; attr->AutoNormal = ctx->Eval.AutoNormal; @@ -303,7 +366,7 @@ _mesa_PushAttrib(GLbitfield mask) attr->PolygonSmooth = ctx->Polygon.SmoothFlag; attr->PolygonStipple = ctx->Polygon.StippleFlag; attr->RescaleNormals = ctx->Transform.RescaleNormals; - attr->Scissor = ctx->Scissor.Enabled; + attr->Scissor = ctx->Scissor.EnableFlags; attr->Stencil = ctx->Stencil.Enabled; attr->StencilTwoSide = ctx->Stencil.TestTwoSide; attr->MultisampleEnabled = ctx->Multisample.Enabled; @@ -322,97 +385,112 @@ _mesa_PushAttrib(GLbitfield mask) /* GL_ARB_fragment_program */ attr->FragmentProgram = ctx->FragmentProgram.Enabled; - save_attrib_data(&head, GL_ENABLE_BIT, attr); + if (!save_attrib_data(&head, GL_ENABLE_BIT, attr)) { + free(attr); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + goto end; + } /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */ attr->sRGBEnabled = ctx->Color.sRGBEnabled; } if (mask & GL_EVAL_BIT) { - struct gl_eval_attrib *attr; - attr = MALLOC_STRUCT( gl_eval_attrib ); - memcpy( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) ); - save_attrib_data(&head, GL_EVAL_BIT, attr); + if (!push_attrib(ctx, &head, GL_EVAL_BIT, + sizeof(struct gl_eval_attrib), + (void*)&ctx->Eval)) + goto end; } if (mask & GL_FOG_BIT) { - struct gl_fog_attrib *attr; - attr = MALLOC_STRUCT( gl_fog_attrib ); - memcpy( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) ); - save_attrib_data(&head, GL_FOG_BIT, attr); + if (!push_attrib(ctx, &head, GL_FOG_BIT, + sizeof(struct gl_fog_attrib), + (void*)&ctx->Fog)) + goto end; } if (mask & GL_HINT_BIT) { - struct gl_hint_attrib *attr; - attr = MALLOC_STRUCT( gl_hint_attrib ); - memcpy( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) ); - save_attrib_data(&head, GL_HINT_BIT, attr); + if (!push_attrib(ctx, &head, GL_HINT_BIT, + sizeof(struct gl_hint_attrib), + (void*)&ctx->Hint)) + goto end; } if (mask & GL_LIGHTING_BIT) { - struct gl_light_attrib *attr; - FLUSH_CURRENT(ctx, 0); /* flush material changes */ - attr = MALLOC_STRUCT( gl_light_attrib ); - memcpy( attr, &ctx->Light, sizeof(struct gl_light_attrib) ); - save_attrib_data(&head, GL_LIGHTING_BIT, attr); + FLUSH_CURRENT(ctx, 0); /* flush material changes */ + if (!push_attrib(ctx, &head, GL_LIGHTING_BIT, + sizeof(struct gl_light_attrib), + (void*)&ctx->Light)) + goto end; } if (mask & GL_LINE_BIT) { - struct gl_line_attrib *attr; - attr = MALLOC_STRUCT( gl_line_attrib ); - memcpy( attr, &ctx->Line, sizeof(struct gl_line_attrib) ); - save_attrib_data(&head, GL_LINE_BIT, attr); + if (!push_attrib(ctx, &head, GL_LINE_BIT, + sizeof(struct gl_line_attrib), + (void*)&ctx->Line)) + goto end; } if (mask & GL_LIST_BIT) { - struct gl_list_attrib *attr; - attr = MALLOC_STRUCT( gl_list_attrib ); - memcpy( attr, &ctx->List, sizeof(struct gl_list_attrib) ); - save_attrib_data(&head, GL_LIST_BIT, attr); + if (!push_attrib(ctx, &head, GL_LIST_BIT, + sizeof(struct gl_list_attrib), + (void*)&ctx->List)) + goto end; } if (mask & GL_PIXEL_MODE_BIT) { struct gl_pixel_attrib *attr; attr = MALLOC_STRUCT( gl_pixel_attrib ); - memcpy( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) ); - /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */ - attr->ReadBuffer = ctx->ReadBuffer->ColorReadBuffer; - save_attrib_data(&head, GL_PIXEL_MODE_BIT, attr); + if (attr == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + goto end; + } + + if (save_attrib_data(&head, GL_PIXEL_MODE_BIT, attr)) { + memcpy(attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib)); + /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */ + attr->ReadBuffer = ctx->ReadBuffer->ColorReadBuffer; + } + else { + free(attr); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib"); + goto end; + } } if (mask & GL_POINT_BIT) { - struct gl_point_attrib *attr; - attr = MALLOC_STRUCT( gl_point_attrib ); - memcpy( attr, &ctx->Point, sizeof(struct gl_point_attrib) ); - save_attrib_data(&head, GL_POINT_BIT, attr); + if (!push_attrib(ctx, &head, GL_POINT_BIT, + sizeof(struct gl_point_attrib), + (void*)&ctx->Point)) + goto end; } if (mask & GL_POLYGON_BIT) { - struct gl_polygon_attrib *attr; - attr = MALLOC_STRUCT( gl_polygon_attrib ); - memcpy( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) ); - save_attrib_data(&head, GL_POLYGON_BIT, attr); + if (!push_attrib(ctx, &head, GL_POLYGON_BIT, + sizeof(struct gl_polygon_attrib), + (void*)&ctx->Polygon)) + goto end; } if (mask & GL_POLYGON_STIPPLE_BIT) { - GLuint *stipple; - stipple = malloc( 32*sizeof(GLuint) ); - memcpy( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) ); - save_attrib_data(&head, GL_POLYGON_STIPPLE_BIT, stipple); + if (!push_attrib(ctx, &head, GL_POLYGON_STIPPLE_BIT, + sizeof(ctx->PolygonStipple), + (void*)&ctx->PolygonStipple)) + goto end; } if (mask & GL_SCISSOR_BIT) { - struct gl_scissor_attrib *attr; - attr = MALLOC_STRUCT( gl_scissor_attrib ); - memcpy( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) ); - save_attrib_data(&head, GL_SCISSOR_BIT, attr); + if (!push_attrib(ctx, &head, GL_SCISSOR_BIT, + sizeof(struct gl_scissor_attrib), + (void*)&ctx->Scissor)) + goto end; } if (mask & GL_STENCIL_BUFFER_BIT) { - struct gl_stencil_attrib *attr; - attr = MALLOC_STRUCT( gl_stencil_attrib ); - memcpy( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) ); - save_attrib_data(&head, GL_STENCIL_BUFFER_BIT, attr); + if (!push_attrib(ctx, &head, GL_STENCIL_BUFFER_BIT, + sizeof(struct gl_stencil_attrib), + (void*)&ctx->Stencil)) + goto end; } if (mask & GL_TEXTURE_BIT) { @@ -424,6 +502,12 @@ _mesa_PushAttrib(GLbitfield mask) goto end; } + if (!save_attrib_data(&head, GL_TEXTURE_BIT, texstate)) { + free(texstate); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib(GL_TEXTURE_BIT)"); + goto end; + } + _mesa_lock_context_textures(ctx); /* copy/save the bulk of texture state here */ @@ -450,35 +534,36 @@ _mesa_PushAttrib(GLbitfield mask) _mesa_reference_shared_state(ctx, &texstate->SharedRef, ctx->Shared); _mesa_unlock_context_textures(ctx); - - save_attrib_data(&head, GL_TEXTURE_BIT, texstate); } if (mask & GL_TRANSFORM_BIT) { - struct gl_transform_attrib *attr; - attr = MALLOC_STRUCT( gl_transform_attrib ); - memcpy( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) ); - save_attrib_data(&head, GL_TRANSFORM_BIT, attr); + if (!push_attrib(ctx, &head, GL_TRANSFORM_BIT, + sizeof(struct gl_transform_attrib), + (void*)&ctx->Transform)) + goto end; } if (mask & GL_VIEWPORT_BIT) { - struct gl_viewport_attrib *attr; - attr = MALLOC_STRUCT( gl_viewport_attrib ); - memcpy( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) ); - save_attrib_data(&head, GL_VIEWPORT_BIT, attr); + if (!push_attrib(ctx, &head, GL_VIEWPORT_BIT, + sizeof(struct gl_viewport_attrib) + * ctx->Const.MaxViewports, + (void*)&ctx->ViewportArray)) + goto end; } /* GL_ARB_multisample */ if (mask & GL_MULTISAMPLE_BIT_ARB) { - struct gl_multisample_attrib *attr; - attr = MALLOC_STRUCT( gl_multisample_attrib ); - memcpy( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) ); - save_attrib_data(&head, GL_MULTISAMPLE_BIT_ARB, attr); + if (!push_attrib(ctx, &head, GL_MULTISAMPLE_BIT_ARB, + sizeof(struct gl_multisample_attrib), + (void*)&ctx->Multisample)) + goto end; } end: - ctx->AttribStack[ctx->AttribStackDepth] = head; - ctx->AttribStackDepth++; + if (head != NULL) { + ctx->AttribStack[ctx->AttribStackDepth] = head; + ctx->AttribStackDepth++; + } } @@ -586,7 +671,13 @@ pop_enable_group(struct gl_context *ctx, const struct gl_enable_attrib *enable) GL_POLYGON_SMOOTH); TEST_AND_UPDATE(ctx->Polygon.StippleFlag, enable->PolygonStipple, GL_POLYGON_STIPPLE); - TEST_AND_UPDATE(ctx->Scissor.Enabled, enable->Scissor, GL_SCISSOR_TEST); + if (ctx->Scissor.EnableFlags != enable->Scissor) { + unsigned i; + + for (i = 0; i < ctx->Const.MaxViewports; i++) { + _mesa_set_enablei(ctx, GL_SCISSOR_TEST, i, (enable->Scissor >> i) & 1); + } + } TEST_AND_UPDATE(ctx->Stencil.Enabled, enable->Stencil, GL_STENCIL_TEST); if (ctx->Extensions.EXT_stencil_two_side) { TEST_AND_UPDATE(ctx->Stencil.TestTwoSide, enable->StencilTwoSide, GL_STENCIL_TEST_TWO_SIDE_EXT); @@ -641,12 +732,6 @@ pop_enable_group(struct gl_context *ctx, const struct gl_enable_attrib *enable) _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, !!(enabled & TEXTURE_CUBE_BIT)); } - if (ctx->Extensions.MESA_texture_array) { - _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT, - !!(enabled & TEXTURE_1D_ARRAY_BIT)); - _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT, - !!(enabled & TEXTURE_2D_ARRAY_BIT)); - } } if (ctx->Texture.Unit[i].TexGenEnabled != genEnabled) { @@ -681,19 +766,13 @@ pop_texture_group(struct gl_context *ctx, struct texture_state *texstate) _mesa_set_enable(ctx, GL_TEXTURE_2D, !!(unit->Enabled & TEXTURE_2D_BIT)); _mesa_set_enable(ctx, GL_TEXTURE_3D, !!(unit->Enabled & TEXTURE_3D_BIT)); if (ctx->Extensions.ARB_texture_cube_map) { - _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP_ARB, + _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, !!(unit->Enabled & TEXTURE_CUBE_BIT)); } if (ctx->Extensions.NV_texture_rectangle) { _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_NV, !!(unit->Enabled & TEXTURE_RECT_BIT)); } - if (ctx->Extensions.MESA_texture_array) { - _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT, - !!(unit->Enabled & TEXTURE_1D_ARRAY_BIT)); - _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT, - !!(unit->Enabled & TEXTURE_2D_ARRAY_BIT)); - } _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode); _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor); _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenS.Mode); @@ -758,7 +837,7 @@ pop_texture_group(struct gl_context *ctx, struct texture_state *texstate) /* don't restore state for unsupported targets to prevent * raising GL errors. */ - if (obj->Target == GL_TEXTURE_CUBE_MAP_ARB && + if (obj->Target == GL_TEXTURE_CUBE_MAP && !ctx->Extensions.ARB_texture_cube_map) { continue; } @@ -768,7 +847,7 @@ pop_texture_group(struct gl_context *ctx, struct texture_state *texstate) } else if ((obj->Target == GL_TEXTURE_1D_ARRAY_EXT || obj->Target == GL_TEXTURE_2D_ARRAY_EXT) && - !ctx->Extensions.MESA_texture_array) { + !ctx->Extensions.EXT_texture_array) { continue; } else if (obj->Target == GL_TEXTURE_CUBE_MAP_ARRAY && @@ -858,10 +937,14 @@ _mesa_PopAttrib(void) if (MESA_VERBOSE & VERBOSE_API) { _mesa_debug(ctx, "glPopAttrib %s\n", - _mesa_lookup_enum_by_nr(attr->kind)); + _mesa_enum_to_string(attr->kind)); } switch (attr->kind) { + case DUMMY_BIT: + /* do nothing */ + break; + case GL_ACCUM_BUFFER_BIT: { const struct gl_accum_attrib *accum; @@ -1008,6 +1091,11 @@ _mesa_PopAttrib(void) _mesa_ClearDepth(depth->Clear); _mesa_set_enable(ctx, GL_DEPTH_TEST, depth->Test); _mesa_DepthMask(depth->Mask); + if (ctx->Extensions.EXT_depth_bounds_test) { + _mesa_set_enable(ctx, GL_DEPTH_BOUNDS_TEST_EXT, + depth->BoundsTest); + _mesa_DepthBoundsEXT(depth->BoundsMin, depth->BoundsMax); + } } break; case GL_ENABLE_BIT: @@ -1159,7 +1247,7 @@ _mesa_PopAttrib(void) GLuint u; for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, - (GLint) point->CoordReplace[u]); + !!(point->CoordReplace & (1u << u))); } _mesa_set_enable(ctx, GL_POINT_SPRITE_NV,point->PointSprite); if (ctx->Extensions.NV_point_sprite) @@ -1181,8 +1269,10 @@ _mesa_PopAttrib(void) _mesa_FrontFace(polygon->FrontFace); _mesa_PolygonMode(GL_FRONT, polygon->FrontMode); _mesa_PolygonMode(GL_BACK, polygon->BackMode); - _mesa_PolygonOffset(polygon->OffsetFactor, - polygon->OffsetUnits); + _mesa_polygon_offset_clamp(ctx, + polygon->OffsetFactor, + polygon->OffsetUnits, + polygon->OffsetClamp); _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, polygon->SmoothFlag); _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, polygon->StippleFlag); _mesa_set_enable(ctx, GL_CULL_FACE, polygon->CullFlag); @@ -1202,11 +1292,26 @@ _mesa_PopAttrib(void) break; case GL_SCISSOR_BIT: { + unsigned i; const struct gl_scissor_attrib *scissor; scissor = (const struct gl_scissor_attrib *) attr->data; - _mesa_Scissor(scissor->X, scissor->Y, - scissor->Width, scissor->Height); - _mesa_set_enable(ctx, GL_SCISSOR_TEST, scissor->Enabled); + + for (i = 0; i < ctx->Const.MaxViewports; i++) { + _mesa_set_scissor(ctx, i, + scissor->ScissorArray[i].X, + scissor->ScissorArray[i].Y, + scissor->ScissorArray[i].Width, + scissor->ScissorArray[i].Height); + _mesa_set_enablei(ctx, GL_SCISSOR_TEST, i, + (scissor->EnableFlags >> i) & 1); + } + if (ctx->Extensions.EXT_window_rectangles) { + STATIC_ASSERT(sizeof(struct gl_scissor_rect) == + 4 * sizeof(GLint)); + _mesa_WindowRectanglesEXT( + scissor->WindowRectMode, scissor->NumWindowRects, + (const GLint *)scissor->WindowRects); + } } break; case GL_STENCIL_BUFFER_BIT: @@ -1270,6 +1375,8 @@ _mesa_PopAttrib(void) if (xform->DepthClamp != ctx->Transform.DepthClamp) _mesa_set_enable(ctx, GL_DEPTH_CLAMP, ctx->Transform.DepthClamp); + if (ctx->Extensions.ARB_clip_control) + _mesa_ClipControl(xform->ClipOrigin, xform->ClipDepthMode); } break; case GL_TEXTURE_BIT: @@ -1282,10 +1389,15 @@ _mesa_PopAttrib(void) break; case GL_VIEWPORT_BIT: { + unsigned i; const struct gl_viewport_attrib *vp; vp = (const struct gl_viewport_attrib *) attr->data; - _mesa_Viewport(vp->X, vp->Y, vp->Width, vp->Height); - _mesa_DepthRange(vp->Near, vp->Far); + + for (i = 0; i < ctx->Const.MaxViewports; i++) { + _mesa_set_viewport(ctx, i, vp[i].X, vp[i].Y, vp[i].Width, + vp[i].Height); + _mesa_set_depth_range(ctx, i, vp[i].Near, vp[i].Far); + } } break; case GL_MULTISAMPLE_BIT_ARB: @@ -1353,13 +1465,13 @@ copy_pixelstore(struct gl_context *ctx, #define GL_CLIENT_UNPACK_BIT (1<<21) /** - * Copy gl_array_object from src to dest. + * Copy gl_vertex_array_object from src to dest. * 'dest' must be in an initialized state. */ static void copy_array_object(struct gl_context *ctx, - struct gl_array_object *dest, - struct gl_array_object *src) + struct gl_vertex_array_object *dest, + struct gl_vertex_array_object *src) { GLuint i; @@ -1369,12 +1481,15 @@ copy_array_object(struct gl_context *ctx, /* In theory must be the same anyway, but on recreate make sure it matches */ dest->ARBsemantics = src->ARBsemantics; - for (i = 0; i < Elements(src->_VertexAttrib); i++) + for (i = 0; i < ARRAY_SIZE(src->VertexAttrib); i++) { _mesa_copy_client_array(ctx, &dest->_VertexAttrib[i], &src->_VertexAttrib[i]); + _mesa_copy_vertex_attrib_array(ctx, &dest->VertexAttrib[i], &src->VertexAttrib[i]); + _mesa_copy_vertex_buffer_binding(ctx, &dest->VertexBinding[i], &src->VertexBinding[i]); + } /* _Enabled must be the same than on push */ dest->_Enabled = src->_Enabled; - dest->_MaxElement = src->_MaxElement; + dest->NewArrays = src->NewArrays; } /** @@ -1400,10 +1515,14 @@ copy_array_attrib(struct gl_context *ctx, /* skip RebindArrays */ if (!vbo_deleted) - copy_array_object(ctx, dest->ArrayObj, src->ArrayObj); + copy_array_object(ctx, dest->VAO, src->VAO); /* skip ArrayBufferObj */ - /* skip ElementArrayBufferObj */ + /* skip IndexBufferObj */ + + /* Invalidate draw state. It will be updated during the next draw. */ + dest->DrawMethod = DRAW_NONE; + dest->_DrawArrays = NULL; } /** @@ -1416,15 +1535,15 @@ save_array_attrib(struct gl_context *ctx, { /* Set the Name, needed for restore, but do never overwrite. * Needs to match value in the object hash. */ - dest->ArrayObj->Name = src->ArrayObj->Name; + dest->VAO->Name = src->VAO->Name; /* And copy all of the rest. */ copy_array_attrib(ctx, dest, src, false); /* Just reference them here */ _mesa_reference_buffer_object(ctx, &dest->ArrayBufferObj, src->ArrayBufferObj); - _mesa_reference_buffer_object(ctx, &dest->ArrayObj->ElementArrayBufferObj, - src->ArrayObj->ElementArrayBufferObj); + _mesa_reference_buffer_object(ctx, &dest->VAO->IndexBufferObj, + src->VAO->IndexBufferObj); } /** @@ -1447,13 +1566,13 @@ restore_array_attrib(struct gl_context *ctx, * The semantics of objects created using APPLE_vertex_array_objects behave * differently. These objects expect to be recreated by pop. Alas. */ - const bool arb_vao = (src->ArrayObj->Name != 0 - && src->ArrayObj->ARBsemantics); + const bool arb_vao = (src->VAO->Name != 0 + && src->VAO->ARBsemantics); - if (arb_vao && !_mesa_IsVertexArray(src->ArrayObj->Name)) + if (arb_vao && !_mesa_IsVertexArray(src->VAO->Name)) return; - _mesa_BindVertexArrayAPPLE(src->ArrayObj->Name); + _mesa_BindVertexArrayAPPLE(src->VAO->Name); /* Restore or recreate the buffer objects by the names ... */ if (!arb_vao @@ -1469,23 +1588,30 @@ restore_array_attrib(struct gl_context *ctx, } if (!arb_vao - || src->ArrayObj->ElementArrayBufferObj->Name == 0 - || _mesa_IsBuffer(src->ArrayObj->ElementArrayBufferObj->Name)) + || src->VAO->IndexBufferObj->Name == 0 + || _mesa_IsBuffer(src->VAO->IndexBufferObj->Name)) _mesa_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, - src->ArrayObj->ElementArrayBufferObj->Name); + src->VAO->IndexBufferObj->Name); } /** * init/alloc the fields of 'attrib'. * Needs to the init part matching free_array_attrib_data below. */ -static void +static bool init_array_attrib_data(struct gl_context *ctx, struct gl_array_attrib *attrib) { - /* Get a non driver gl_array_object. */ - attrib->ArrayObj = CALLOC_STRUCT( gl_array_object ); - _mesa_initialize_array_object(ctx, attrib->ArrayObj, 0); + /* Get a non driver gl_vertex_array_object. */ + attrib->VAO = CALLOC_STRUCT( gl_vertex_array_object ); + + if (attrib->VAO == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib"); + return false; + } + + _mesa_initialize_vao(ctx, attrib->VAO, 0); + return true; } /** @@ -1499,8 +1625,8 @@ free_array_attrib_data(struct gl_context *ctx, { /* We use a non driver array object, so don't just unref since we would * end up using the drivers DeleteArrayObject function for deletion. */ - _mesa_delete_array_object(ctx, attrib->ArrayObj); - attrib->ArrayObj = 0; + _mesa_delete_vao(ctx, attrib->VAO); + attrib->VAO = 0; _mesa_reference_buffer_object(ctx, &attrib->ArrayBufferObj, NULL); } @@ -1526,24 +1652,65 @@ _mesa_PushClientAttrib(GLbitfield mask) struct gl_pixelstore_attrib *attr; /* packing attribs */ attr = CALLOC_STRUCT( gl_pixelstore_attrib ); - copy_pixelstore(ctx, attr, &ctx->Pack); - save_attrib_data(&head, GL_CLIENT_PACK_BIT, attr); + if (attr == NULL) { + _mesa_error( ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib" ); + goto end; + } + if (save_attrib_data(&head, GL_CLIENT_PACK_BIT, attr)) { + copy_pixelstore(ctx, attr, &ctx->Pack); + } + else { + _mesa_error( ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib" ); + free(attr); + goto end; + } + /* unpacking attribs */ attr = CALLOC_STRUCT( gl_pixelstore_attrib ); - copy_pixelstore(ctx, attr, &ctx->Unpack); - save_attrib_data(&head, GL_CLIENT_UNPACK_BIT, attr); + if (attr == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib"); + goto end; + } + + if (save_attrib_data(&head, GL_CLIENT_UNPACK_BIT, attr)) { + copy_pixelstore(ctx, attr, &ctx->Unpack); + } + else { + _mesa_error( ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib" ); + free(attr); + goto end; + } } if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { struct gl_array_attrib *attr; attr = CALLOC_STRUCT( gl_array_attrib ); - init_array_attrib_data(ctx, attr); - save_array_attrib(ctx, attr, &ctx->Array); - save_attrib_data(&head, GL_CLIENT_VERTEX_ARRAY_BIT, attr); - } + if (attr == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib"); + goto end; + } - ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head; - ctx->ClientAttribStackDepth++; + if (!init_array_attrib_data(ctx, attr)) { + free(attr); + goto end; + } + + if (save_attrib_data(&head, GL_CLIENT_VERTEX_ARRAY_BIT, attr)) { + save_array_attrib(ctx, attr, &ctx->Array); + } + else { + free_array_attrib_data(ctx, attr); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib"); + free(attr); + /* goto to keep safe from possible later changes */ + goto end; + } + } +end: + if (head != NULL) { + ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head; + ctx->ClientAttribStackDepth++; + } }