From: Rich Geldreich Date: Wed, 19 Mar 2014 21:06:30 +0000 (-0700) Subject: - Fixing polygon stipple saving/restoring so it doesn't stomp memory after the polygo... X-Git-Url: https://git.cworth.org/git?p=vogl;a=commitdiff_plain;h=048eec5a4b5387c0b14b2a417de0649e3c8461cd - Fixing polygon stipple saving/restoring so it doesn't stomp memory after the polygon stipple object (whoops!) --- diff --git a/src/voglcommon/vogl_general_context_state.cpp b/src/voglcommon/vogl_general_context_state.cpp index ef3db73..d2d25a4 100644 --- a/src/voglcommon/vogl_general_context_state.cpp +++ b/src/voglcommon/vogl_general_context_state.cpp @@ -2630,8 +2630,10 @@ bool vogl_polygon_stipple_state::snapshot(const vogl_context_info &context_info) clear(); - GL_ENTRYPOINT(glGetPolygonStipple)(reinterpret_cast(m_pattern)); + vogl_scoped_state_saver pixelstore_state_saver(cGSTPixelStore); + vogl_reset_pixel_store_states(); + GL_ENTRYPOINT(glGetPolygonStipple)(m_pattern); VOGL_CHECK_GL_ERROR; m_valid = true; @@ -2650,8 +2652,10 @@ bool vogl_polygon_stipple_state::restore(const vogl_context_info &context_info) VOGL_CHECK_GL_ERROR; - GL_ENTRYPOINT(glPolygonStipple)(reinterpret_cast(m_pattern)); + vogl_scoped_state_saver pixelstore_state_saver(cGSTPixelStore); + vogl_reset_pixel_store_states(); + GL_ENTRYPOINT(glPolygonStipple)(m_pattern); VOGL_CHECK_GL_ERROR; return true; @@ -2675,7 +2679,7 @@ bool vogl_polygon_stipple_state::serialize(json_node &node, vogl_blob_manager &b return false; json_node &arr_node = node.add_array("pattern"); - for (uint i = 0; i < 32; i++) + for (uint i = 0; i < VOGL_ARRAY_SIZE(m_pattern); i++) arr_node.add_value(m_pattern[i]); return true; @@ -2693,11 +2697,19 @@ bool vogl_polygon_stipple_state::deserialize(const json_node &node, const vogl_b if (!pArr_node) return false; - if ((pArr_node->size() != 32) || (!pArr_node->are_all_children_values())) + if (!pArr_node->are_all_children_values()) return false; - for (uint i = 0; i < 32; i++) - m_pattern[i] = pArr_node->value_as_uint32(i); + // An earlier version wrote the wrong size, so ignore that data. + if (pArr_node->size() == VOGL_ARRAY_SIZE(m_pattern)) + { + for (uint i = 0; i < VOGL_ARRAY_SIZE(m_pattern); i++) + m_pattern[i] = static_cast(pArr_node->value_as_uint32(i)); + } + else + { + vogl_warning_printf("%s: Polygon stipple data is not valid in this older trace file so it's being ignored - please recapture (sorry)\n", VOGL_METHOD_NAME); + } m_valid = true; @@ -2709,8 +2721,9 @@ uint vogl_polygon_stipple_state::get_num_pattern_rows() const return 32; } -uint32 vogl_polygon_stipple_state::get_pattern_row(uint rowIndex) const +uint32 vogl_polygon_stipple_state::get_pattern_row(uint row_index) const { - VOGL_ASSERT(rowIndex < 32); - return m_pattern[rowIndex]; + VOGL_ASSERT(row_index < 32); + + return m_pattern[4 * row_index] | (m_pattern[4 * row_index + 1] << 8U) | (m_pattern[4 * row_index + 2] << 16U) | (m_pattern[4 * row_index + 3] << 24U); } diff --git a/src/voglcommon/vogl_general_context_state.h b/src/voglcommon/vogl_general_context_state.h index 7f10c9e..d024b87 100644 --- a/src/voglcommon/vogl_general_context_state.h +++ b/src/voglcommon/vogl_general_context_state.h @@ -96,11 +96,11 @@ public: bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager); uint get_num_pattern_rows() const; - uint32 get_pattern_row(uint rowIndex) const; + uint32 get_pattern_row(uint row_index) const; private: bool m_valid; - uint32 m_pattern[32]; + uint8 m_pattern[32 * 4]; }; #endif // VOGL_BASIC_CONTEXT_STATE_H