Skip to content

Commit

Permalink
awgl: replace static library with a shared library
Browse files Browse the repository at this point in the history
I need to make them all either static or shared, mixing types doesn't
work. With shared library I had two instances of GL loader with only one
initialized which caused crashes.
  • Loading branch information
Hedede committed Nov 18, 2024
1 parent 53168b2 commit 861341b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
18 changes: 11 additions & 7 deletions graphics/gl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

find_package(OpenGL REQUIRED)

aw_add_library(awgl STATIC
aw_add_library(awgl SHARED
GLOB_HEADERS
SOURCES
enum_check.c++
Expand All @@ -11,26 +11,30 @@ aw_add_library(awgl STATIC
gl
)

target_compile_definitions(awgl
PRIVATE
AW_MODULE_GL_LOADER
)

target_sources(awgl
PRIVATE
include/aw/gl/export.h
)

target_link_libraries(awgl
PUBLIC
awalgo
awutils
PRIVATE
OpenGL::GL)


if (WIN32)
target_link_libraries(awgl
PRIVATE
OpenGL::GL
awplatform)
elseif (APPLE)
target_link_libraries(awgl
PRIVATE
OpenGL::GL)
elseif (UNIX)
target_link_libraries(awgl
PRIVATE
OpenGL::OpenGL
OpenGL::GLX)
endif()
1 change: 1 addition & 0 deletions graphics/gl/include/aw/gl/api/gl_33.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define aw_gl_ext_opengl_3_3_h
#include "types.h"
#include "gl_enum_33.h"
#include "aw/gl/export.h"

namespace gl {
namespace ext {
Expand Down
2 changes: 0 additions & 2 deletions graphics/gl/include/aw/gl/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <aw/types/types.h>
#include <aw/config.h>

#define AW_GL_EXP // TODO

#if (AW_PLATFORM_SPECIFIC == AW_PLATFORM_APPLE)
typedef void *GLhandleARB;
#else
Expand Down
9 changes: 9 additions & 0 deletions graphics/gl/include/aw/gl/export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef aw_gl_export_h
#define aw_gl_export_h
#include <aw/config.h>
#ifdef AW_MODULE_GL_LOADER
#define AW_GL_EXP AW_EXPORT
#else
#define AW_GL_EXP AW_IMPORT
#endif
#endif//aw_gl_export_h
5 changes: 2 additions & 3 deletions graphics/gl/loader.c++
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ bool TestPointer(PROC ptr)

unknown_fn* get_proc_address(const char* name)
{
HMODULE glMod = nullptr;
PROC pFunc = wglGetProcAddress((LPCSTR)name);
PROC pFunc = wglGetProcAddress((LPCSTR)name);
if (TestPointer(pFunc))
return (unknown_fn*)pFunc;
glMod = GetModuleHandleA("OpenGL32.dll");
HMODULE glMod = GetModuleHandleA("OpenGL32.dll");
return (unknown_fn*)GetProcAddress(glMod, (LPCSTR)name);
}
} // namespace aw::wgl
Expand Down

0 comments on commit 861341b

Please sign in to comment.