Skip to content

Commit

Permalink
Fix opengl in msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Mar 14, 2020
1 parent 48e913c commit 858862d
Show file tree
Hide file tree
Showing 12 changed files with 44,256 additions and 16,156 deletions.
2,618 changes: 2,618 additions & 0 deletions 3rdparty/glew/include/GL/eglew.h

Large diffs are not rendered by default.

23,836 changes: 16,255 additions & 7,581 deletions 3rdparty/glew/include/GL/glew.h

Large diffs are not rendered by default.

1,577 changes: 892 additions & 685 deletions 3rdparty/glew/include/GL/glxew.h

Large diffs are not rendered by default.

1,285 changes: 705 additions & 580 deletions 3rdparty/glew/include/GL/wglew.h

Large diffs are not rendered by default.

31,023 changes: 23,723 additions & 7,300 deletions 3rdparty/glew/src/glew.c

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions libs/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ if(BUILD_mrpt-gui)
target_link_libraries(gui PRIVATE ${MRPT_OPENGL_LIBS})
endif()

if (TARGET mrpt_glew) # Basically, for Windows
target_link_libraries(gui PRIVATE mrpt_glew)
endif()

endif()
6 changes: 5 additions & 1 deletion libs/gui/src/CDisplayWindow3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,14 @@ CDisplayWindow3D::Ptr CDisplayWindow3D::Create(
CDisplayWindow3D::~CDisplayWindow3D()
{
// get lock so we make sure nobody else is touching the window right now.
m_csAccess3DScene.try_lock_for(std::chrono::seconds(2));
bool lock_ok = m_csAccess3DScene.try_lock_for(std::chrono::seconds(2));
m_csAccess3DScene.unlock();

CBaseGUIWindow::destroyWxWindow();

if (!lock_ok)
std::cerr
<< "[~CDisplayWindow3D] Warning: Timeout acquiring mutex lock.\n";
}

/*---------------------------------------------------------------
Expand Down
20 changes: 17 additions & 3 deletions libs/opengl/src/COpenGLBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ void COpenGLBuffer::RAII_Impl::destroy()
{
if (!created) return;
#if MRPT_HAS_OPENGL_GLUT
release();
glDeleteBuffers(1, &buffer_id);
try
{
release();
glDeleteBuffers(1, &buffer_id);
}
catch (...)
{
// For Windows: ignore errors if GLEW was already unloaded...
}
#endif
buffer_id = 0;
created = false;
Expand All @@ -61,7 +68,14 @@ void COpenGLBuffer::RAII_Impl::release()
{
#if MRPT_HAS_OPENGL_GLUT
if (!created) return;
glBindBuffer(static_cast<GLenum>(type), 0);
try
{
glBindBuffer(static_cast<GLenum>(type), 0);
}
catch (...)
{
// For Windows: ignore errors if GLEW was already unloaded...
}
#endif
}

Expand Down
25 changes: 20 additions & 5 deletions libs/opengl/src/COpenGLVertexArrayObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */

#include "opengl-precomp.h" // Precompiled header
#include "opengl-precomp.h" // Precompiled header

#include <mrpt/core/exceptions.h>
#include <mrpt/opengl/COpenGLVertexArrayObject.h>
#include <mrpt/opengl/opengl_api.h>


using namespace mrpt::opengl;

COpenGLVertexArrayObject::COpenGLVertexArrayObject()
Expand Down Expand Up @@ -41,8 +42,15 @@ void COpenGLVertexArrayObject::RAII_Impl::destroy()
{
if (!created) return;
#if MRPT_HAS_OPENGL_GLUT
release();
glDeleteVertexArrays(1, &buffer_id);
try
{
release();
glDeleteVertexArrays(1, &buffer_id);
}
catch (...)
{
// For Windows: ignore errors if GLEW was already unloaded...
}
#endif
buffer_id = 0;
created = false;
Expand All @@ -59,7 +67,14 @@ void COpenGLVertexArrayObject::RAII_Impl::bind()
void COpenGLVertexArrayObject::RAII_Impl::release()
{
#if MRPT_HAS_OPENGL_GLUT
if (!created) return;
glBindVertexArray(0);
try
{
if (!created) return;
glBindVertexArray(0);
}
catch (...)
{
// For Windows: ignore errors if GLEW was already unloaded...
}
#endif
}
3 changes: 2 additions & 1 deletion libs/opengl/src/COpenGLViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <mrpt/opengl/opengl_api.h>


using namespace mrpt;
using namespace mrpt::poses;
using namespace mrpt::opengl;
Expand Down Expand Up @@ -164,7 +165,7 @@ void COpenGLViewport::renderImageMode() const

// Prepare raster pos & pixel copy direction in -Y.
glRasterPos2f(-0.5f, -0.5f);
glPixelZoom(vw / float(ortho_w), -vh / float(ortho_h));
glPixelZoom(vw / float(ortho_w), vh / float(-ortho_h));

// Prepare image data types:
const GLenum img_type = GL_UNSIGNED_BYTE;
Expand Down
10 changes: 10 additions & 0 deletions libs/opengl/src/CRenderizableShaderTexturedTriangles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| https://www.mrpt.org/ |
| |
| Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
| See: https://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */

#include "opengl-precomp.h" // Precompiled header
5 changes: 5 additions & 0 deletions libs/opengl/src/DefaultShaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ Program::Ptr mrpt::opengl::LoadDefaultShader(const shader_id_t id)
"Unknown shader_id_t=%u", static_cast<unsigned>(id));
};

// Init GLEW if not already done:
#ifdef _WIN32
glewInit();
#endif

auto shader = std::make_shared<Program>();

std::string errMsgs;
Expand Down

0 comments on commit 858862d

Please sign in to comment.