forked from organicmaps/organicmaps
Fixed crash in debug renderer initialization
This commit is contained in:
parent
1e82139ccf
commit
b235d5b2c9
1 changed files with 23 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "drape/debug_rect_renderer.hpp"
|
||||
|
||||
#include "drape/glextensions_list.hpp"
|
||||
#include "drape/glfunctions.hpp"
|
||||
#include "drape/gpu_program_manager.hpp"
|
||||
|
||||
|
@ -37,12 +38,14 @@ DebugRectRenderer::~DebugRectRenderer()
|
|||
|
||||
void DebugRectRenderer::Init(ref_ptr<dp::GpuProgramManager> mng, int programId)
|
||||
{
|
||||
if (dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::VertexArrayObject))
|
||||
{
|
||||
m_VAO = GLFunctions::glGenVertexArray();
|
||||
GLFunctions::glBindVertexArray(m_VAO);
|
||||
}
|
||||
|
||||
m_vertexBuffer = GLFunctions::glGenBuffer();
|
||||
GLFunctions::glBindBuffer(m_vertexBuffer, gl_const::GLArrayBuffer);
|
||||
|
||||
m_VAO = GLFunctions::glGenVertexArray();
|
||||
GLFunctions::glBindVertexArray(m_VAO);
|
||||
|
||||
m_program = mng->GetProgram(programId);
|
||||
int8_t attributeLocation = m_program->GetAttributeLocation("a_position");
|
||||
ASSERT_NOT_EQUAL(attributeLocation, -1, ());
|
||||
|
@ -50,8 +53,10 @@ void DebugRectRenderer::Init(ref_ptr<dp::GpuProgramManager> mng, int programId)
|
|||
GLFunctions::glVertexAttributePointer(attributeLocation, 2, gl_const::GLFloatType, false,
|
||||
sizeof(float) * 2, 0);
|
||||
|
||||
if (m_VAO != 0)
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
|
||||
GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void DebugRectRenderer::Destroy()
|
||||
|
@ -80,6 +85,7 @@ void DebugRectRenderer::SetEnabled(bool enabled)
|
|||
{
|
||||
m_isEnabled = enabled;
|
||||
}
|
||||
|
||||
void DebugRectRenderer::DrawRect(ScreenBase const & screen, m2::RectF const & rect,
|
||||
dp::Color const & color) const
|
||||
{
|
||||
|
@ -90,7 +96,9 @@ void DebugRectRenderer::DrawRect(ScreenBase const & screen, m2::RectF const & re
|
|||
m_program->Bind();
|
||||
|
||||
GLFunctions::glBindBuffer(m_vertexBuffer, gl_const::GLArrayBuffer);
|
||||
GLFunctions::glBindVertexArray(m_VAO);
|
||||
|
||||
if (m_VAO != 0)
|
||||
GLFunctions::glBindVertexArray(m_VAO);
|
||||
|
||||
array<m2::PointF, 5> vertices;
|
||||
vertices[0] = PixelPointToScreenSpace(screen, rect.LeftBottom());
|
||||
|
@ -110,8 +118,10 @@ void DebugRectRenderer::DrawRect(ScreenBase const & screen, m2::RectF const & re
|
|||
|
||||
GLFunctions::glDrawArrays(gl_const::GLLineStrip, 0, static_cast<uint32_t>(vertices.size()));
|
||||
|
||||
if (m_VAO != 0)
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
|
||||
GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
|
||||
m_program->Unbind();
|
||||
}
|
||||
|
@ -129,7 +139,9 @@ void DebugRectRenderer::DrawArrow(ScreenBase const & screen,
|
|||
m_program->Bind();
|
||||
|
||||
GLFunctions::glBindBuffer(m_vertexBuffer, gl_const::GLArrayBuffer);
|
||||
GLFunctions::glBindVertexArray(m_VAO);
|
||||
|
||||
if (m_VAO != 0)
|
||||
GLFunctions::glBindVertexArray(m_VAO);
|
||||
|
||||
array<m2::PointF, 5> vertices;
|
||||
m2::PointF const dir = (data.m_arrowEnd - data.m_arrowStart).Normalize();
|
||||
|
@ -151,8 +163,10 @@ void DebugRectRenderer::DrawArrow(ScreenBase const & screen,
|
|||
|
||||
GLFunctions::glDrawArrays(gl_const::GLLineStrip, 0, static_cast<uint32_t>(vertices.size()));
|
||||
|
||||
if (m_VAO != 0)
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
|
||||
GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
|
||||
m_program->Unbind();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue