Skip to content

Commit 3649044

Browse files
committed
adjust sdl-test-ui to use GLAD and SDL2 to get gl functions
1 parent c775445 commit 3649044

5 files changed

Lines changed: 76 additions & 44 deletions

File tree

src/sdl-test-ui/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ target_link_libraries(projectM-Test-UI
2323
SDL2::SDL2
2424
SDL2::SDL2main
2525
${CMAKE_DL_LIBS}
26+
glad
2627
)
2728

2829
if(MSVC)
@@ -37,4 +38,11 @@ if(MSVC)
3738
"The resulting projectMSDL executable will not be DPI-aware and possibly render at a "
3839
"lower-than-expected resolution on high-DPI displays.")
3940
endif()
41+
42+
add_custom_command(TARGET projectM-Test-UI POST_BUILD
43+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
44+
$<TARGET_FILE:libprojectM::projectM>
45+
$<TARGET_FILE:libprojectM::playlist>
46+
$<TARGET_FILE_DIR:projectM-Test-UI>
47+
)
4048
endif()

src/sdl-test-ui/opengl.h

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,11 @@
1717
// If a shader compilation failure occurs, it dumps shader source into /tmp instead of stderr
1818
#define DUMP_SHADERS_ON_ERROR 0
1919

20-
#ifdef __APPLE__
21-
# include <OpenGL/gl3.h>
22-
# include <OpenGL/gl3ext.h>
23-
#elif defined(EYETUNE_WINRT)
24-
#define GL_GLEXT_PROTOTYPES
25-
#define GLM_FORCE_CXX03
26-
#include <GLES3/gl31.h>
27-
#include <GLES3/gl3.h>
28-
#include <GLES2/gl2.h>
29-
#include <GLES2/gl2ext.h>
30-
#include <EGL/egl.h>
31-
#include <EGL/eglext.h>
32-
#elif defined(_WIN32)
33-
#define GLM_FORCE_CXX03
34-
# include <windows.h>
35-
#include "GL/glew.h"
36-
#include "GL/wglew.h"
37-
#else /* linux/unix/other */
38-
# ifdef USE_GLES
39-
# include <GLES3/gl3.h>
40-
# else
41-
# if !defined(GL_GLEXT_PROTOTYPES)
42-
# define GL_GLEXT_PROTOTYPES
43-
# endif
44-
# include <GL/gl.h>
45-
# include <GL/glext.h>
46-
# endif
20+
21+
#ifdef USE_GLES
22+
# include <glad/gles2.h>
23+
#else
24+
# include <glad/gl.h>
4725
#endif
4826

4927

src/sdl-test-ui/pmSDL.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,25 @@
3232

3333
#include <vector>
3434

35+
namespace {
36+
auto dispatchLoadProc(const char* name, void* userData) -> void*
37+
{
38+
// Dispatch load proc to SDL
39+
return SDL_GL_GetProcAddress(name);
40+
}
41+
} // namespace
42+
3543
projectMSDL::projectMSDL(SDL_GLContext glCtx, const std::string& presetPath)
3644
: _openGlContext(glCtx)
37-
, _projectM(projectm_create())
45+
, _projectM(projectm_create_with_opengl_load_proc(&dispatchLoadProc, nullptr))
3846
, _playlist(projectm_playlist_create(_projectM))
3947
{
4048
projectm_get_window_size(_projectM, &_width, &_height);
4149
projectm_playlist_set_preset_switched_event_callback(_playlist, &projectMSDL::presetSwitchedEvent, static_cast<void*>(this));
4250
projectm_playlist_add_path(_playlist, presetPath.c_str(), true, false);
4351
projectm_playlist_set_shuffle(_playlist, _shuffle);
52+
dumpOpenGLInfo();
53+
enableGLDebugOutput();
4454
}
4555

4656
projectMSDL::~projectMSDL()

src/sdl-test-ui/pmSDL.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#pragma once
2929

30+
#include "opengl.h"
3031
#include <SDL2/SDL.h>
3132

3233
// Disable LOOPBACK and FAKE audio to enable microphone input
@@ -45,7 +46,6 @@
4546
// projectM SDL
4647
#include "audioCapture.hpp"
4748
#include "loopback.hpp"
48-
#include "opengl.h"
4949
#include "setup.hpp"
5050

5151

@@ -72,8 +72,8 @@
7272
#include <stdio.h>
7373

7474

75-
#define LOG(format, ...) wprintf(format L"\n", __VA_ARGS__)
76-
#define ERR(format, ...) LOG(L"Error: " format, __VA_ARGS__)
75+
#define LOG(format, ...) wprintf(format L"\n", ##__VA_ARGS__)
76+
#define ERR(format, ...) LOG(L"Error: " format, ##__VA_ARGS__)
7777

7878
#endif /** WASAPI_LOOPBACK */
7979

src/sdl-test-ui/setup.cpp

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "setup.hpp"
22

3+
#include <projectM-4/logging.h>
34
#include "ConfigFile.h"
45

56
#include <SDL2/SDL_hints.h>
@@ -47,7 +48,11 @@ std::string getConfigFilePath(std::string datadir_path) {
4748
#if defined _MSC_VER
4849
_mkdir(projectM_home.c_str());
4950
#else
50-
mkdir(projectM_home.c_str(), 0755);
51+
#ifdef _WIN32
52+
mkdir(projectM_home.c_str());
53+
#else
54+
mkdir(projectM_home.c_str(), 0755);
55+
#endif
5156
#endif
5257

5358
projectM_home += "/config.inp";
@@ -88,14 +93,14 @@ void seedRand() {
8893

8994
void initGL() {
9095
#ifdef USE_GLES
91-
// use GLES 3.0
96+
// use GLES 3.2
9297
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
93-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
98+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
9499
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
95100
#else
96101
// Disabling compatibility profile
97-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
98-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
102+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
103+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
99104
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
100105
#endif
101106
}
@@ -128,11 +133,39 @@ void enableGLDebugOutput() {
128133
#endif
129134
}
130135

136+
namespace {
137+
void logMessage(const char* message, projectm_log_level severity, void* userData)
138+
{
139+
switch (severity)
140+
{
141+
case PROJECTM_LOG_LEVEL_FATAL:
142+
case PROJECTM_LOG_LEVEL_ERROR:
143+
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", message);
144+
break;
145+
case PROJECTM_LOG_LEVEL_WARN:
146+
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "%s\n", message);
147+
break;
148+
case PROJECTM_LOG_LEVEL_TRACE:
149+
case PROJECTM_LOG_LEVEL_DEBUG:
150+
// redirect debug logs to info for now
151+
//SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%s\n", message);
152+
//break;
153+
case PROJECTM_LOG_LEVEL_NOTSET:
154+
case PROJECTM_LOG_LEVEL_INFO:
155+
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%s\n", message);
156+
break;
157+
}
158+
}
159+
}
160+
131161
// initialize SDL, openGL, config
132162
projectMSDL *setupSDLApp() {
133163
projectMSDL *app;
134164
seedRand();
135-
165+
166+
projectm_set_log_callback(&logMessage, false, nullptr);
167+
projectm_set_log_level(PROJECTM_LOG_LEVEL_DEBUG, false);
168+
136169
if (!initLoopback())
137170
{
138171
SDL_Log("Failed to initialize audio loopback device.");
@@ -174,12 +207,6 @@ projectMSDL *setupSDLApp() {
174207

175208
SDL_GLContext glCtx = SDL_GL_CreateContext(win);
176209

177-
#if defined(_WIN32)
178-
GLenum err = glewInit();
179-
#endif /** _WIN32 */
180-
181-
dumpOpenGLInfo();
182-
183210
SDL_SetWindowTitle(win, "projectM");
184211

185212
SDL_GL_MakeCurrent(win, glCtx); // associate GL context with main window
@@ -188,6 +215,16 @@ projectMSDL *setupSDLApp() {
188215
SDL_GL_SetSwapInterval(1); // enable updates synchronized with vertical retrace
189216
}
190217

218+
#ifdef USE_GLES
219+
if (!gladLoadGLES2(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress))) {
220+
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error loading GLAD for GLES2\n");
221+
}
222+
#else
223+
if (!gladLoadGL(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress))) {
224+
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error loading GLAD for GL Core Profile\n");
225+
}
226+
#endif
227+
191228
std::string base_path = DATADIR_PATH;
192229
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Using data directory: %s\n", base_path.c_str());
193230

@@ -248,7 +285,6 @@ projectMSDL *setupSDLApp() {
248285
app->fakeAudio = true;
249286
#endif
250287

251-
enableGLDebugOutput();
252288
configureLoopback(app);
253289

254290
#if !FAKE_AUDIO && !WASAPI_LOOPBACK

0 commit comments

Comments
 (0)