Skip to content

Commit 4fd40d0

Browse files
axe312gerMischa Spiegelmock
authored andcommitted
GLSL and emscripten - JavaScript and WebGL support (#92)
* add glm lib in vendor folder * fix makefile * add more help and context to emscripten readme * add correct output parameter to emcc * add how to restart the process to the readme * simplify emscripten compilation * apply patch * fix blur shaders to work with WebGL
1 parent f2e0a32 commit 4fd40d0

File tree

269 files changed

+56093
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+56093
-44
lines changed

src/libprojectM/Renderer/ShaderEngine.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ bool ShaderEngine::loadPresetShaders(Pipeline &pipeline, const std::string & pre
11541154
ok = false;
11551155
}
11561156
}
1157-
1157+
11581158
if (!pipeline.compositeShader.programSource.empty()) {
11591159
programID_presetComp = loadPresetShader(PresentCompositeShader, pipeline.compositeShader, pipeline.compositeShaderFilename);
11601160
if (programID_presetComp != GL_FALSE) {
@@ -1184,10 +1184,10 @@ GLuint ShaderEngine::loadPresetShader(const ShaderEngine::PresentShaderType shad
11841184
void ShaderEngine::disablePresetShaders() {
11851185
if (presetCompShaderLoaded)
11861186
glDeleteProgram(programID_presetComp);
1187-
1187+
11881188
if (presetWarpShaderLoaded)
11891189
glDeleteProgram(programID_presetWarp);
1190-
1190+
11911191
presetCompShaderLoaded = false;
11921192
presetWarpShaderLoaded = false;
11931193
}
@@ -1246,10 +1246,10 @@ GLuint ShaderEngine::CompileShaderProgram(const std::string & VertexShaderCode,
12461246
glCompileShader(FragmentShaderID);
12471247
checkCompileStatus(FragmentShaderID, "Fragment: " + shaderTypeString);
12481248

1249-
1249+
12501250
// Link the program
12511251
GLuint programID = glCreateProgram();
1252-
1252+
12531253
glAttachShader(programID, VertexShaderID);
12541254
glAttachShader(programID, FragmentShaderID);
12551255
bool linkOK = linkProgram(programID);
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
AM_CPPFLAGS = \
22
${my_CFLAGS} \
33
-include $(top_builddir)/config.h \
4+
-I$(top_builddir)/vendor \
45
-DSYSCONFDIR=\""$(sysconfdir)"\" \
56
-I${top_srcdir}/src/libprojectM \
67
-I${top_srcdir}/src/libprojectM/Renderer \
78
${SDL_CFLAGS}
89

9-
REALSRCDIR=${top_srcdir}/src/projectM-sdl
10-
11-
EMSCRIPTEN_FLAGS = -s USE_SDL=2 -s USE_WEBGL2=1 -s WASM=0
10+
EMSCRIPTEN_FLAGS = -s USE_SDL=2 -s USE_WEBGL2=1
11+
# -s WASM=0
1212

1313
bin_PROGRAMS = projectW.bc
14-
projectW_bc_SOURCES = $(REALSRCDIR)/pmSDL.cpp $(REALSRCDIR)/projectM_SDL_main.cpp $(REALSRCDIR)/pmSDL.hpp
14+
projectW_bc_SOURCES = ../libprojectM/KeyHandler.cpp projectM_SDL_emscripten.cpp
1515
projectW_bc_LDADD = ${SDL_LIBS} ${top_srcdir}/src/libprojectM/libprojectM.la
16-
projectW_bc_LDFLAGS = $(EMSCRIPTEN_FLAGS)
16+
projectW_bc_LDFLAGS = $(EMSCRIPTEN_FLAGS) -static
1717
projectW_bc_PROGRAM = projectW.bc
1818

1919
projectW.html: generate-html
2020

2121
generate-html:
22-
emcc ALLOW_MEMORY_GROWTH=1 $(EMSCRIPTEN_FLAGS) projectW.bc
22+
emcc -s ALLOW_MEMORY_GROWTH=1 $(EMSCRIPTEN_FLAGS) projectW.bc -o projectW.html
2323

2424
run: projectW.html
25-
emrun projectW.html
25+
emrun --browser chrome projectW.html

src/projectM-emscripten/README

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
Running on the web.
22

3-
# Easy way:
4-
* `make run`
5-
6-
7-
8-
9-
# Hard way:
10-
113
## Prepare
124
* Activate the emsdk (https://github.com/juj/emsdk#installation-instructions)
13-
* make sure you are in the root directory of this project
14-
* on fresh repositories: `./autogen.sh`
5+
* Make sure you are in the root directory of this project
6+
* On fresh repositories: `./autogen.sh`
157

168
## Compile
17-
* `emconfigure ./configure --enable-emscripten --enable-gles --enable-sdl`
18-
* `emmake make -j4`
9+
* `emconfigure ./configure --enable-emscripten`
10+
* `emmake make`
1911

2012
## Create wasm & html files
2113
* `cd src/projectM-emscripten`
22-
* `emcc -s USE_SDL=2 -s ALLOW_MEMORY_GROWTH=1 projectW.bc -o projectW.html`
14+
* `make run`
15+
16+
## Troubleshooting
17+
18+
### General
19+
20+
Want to restart the process after pulling or changing config?
21+
* `rm src/projectM-emscripten/projectW*`
22+
* restart with emconfigure or emmake
2323

24-
Does not work? Try:
24+
### OS X troubleshooting:
2525

26-
* `mkdir vendor && cp /usr/local/Cellar/glm/xx/include/glm ./vendor/`
27-
* `emmake make -j4 -lvendor`
26+
#### `./autogen.sh: line 3: autoreconf: command not found`
27+
fix via `brew install automake`

src/projectM-emscripten/projectM_SDL_emscripten.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,36 @@ typedef struct {
2727
SDL_AudioDeviceID audioInputDevice;
2828
} projectMApp;
2929

30+
projectMApp app;
31+
3032
int selectAudioInput(projectMApp *app) {
3133
int i, count = SDL_GetNumAudioDevices(0); // param=isCapture (not yet functional)
32-
34+
3335
if (! count) {
3436
fprintf(stderr, "No audio input capture devices detected\n");
3537
return 0;
3638
}
37-
39+
3840
printf("count: %d\n", count);
3941
for (i = 0; i < count; ++i) {
4042
printf("Audio device %d: %s\n", i, SDL_GetAudioDeviceName(i, 0));
4143
}
42-
44+
4345
return 1;
4446
}
4547

46-
void renderFrame(projectMApp *app) {
48+
void renderFrame() {
4749
int i;
4850
short pcm_data[2][512];
4951
SDL_Event evt;
50-
52+
5153
SDL_PollEvent(&evt);
5254
switch (evt.type) {
5355
case SDL_KEYDOWN:
5456
// ...
5557
break;
5658
case SDL_QUIT:
57-
app->done = true;
59+
app.done = true;
5860
break;
5961
}
6062

@@ -91,31 +93,30 @@ void renderFrame(projectMApp *app) {
9193
}
9294

9395
/** Add the waveform data */
94-
app->pm->pcm()->addPCM16(pcm_data);
96+
app.pm->pcm()->addPCM16(pcm_data);
9597

9698
glClearColor( 0.0, 0.5, 0.0, 0.0 );
9799
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
98100

99-
app->pm->renderFrame();
101+
app.pm->renderFrame();
100102
glFlush();
101103

102104
#if SDL_MAJOR_VERSION==2
103-
SDL_RenderPresent(app->rend);
105+
SDL_RenderPresent(app.rend);
104106
#elif SDL_MAJOR_VERSION==1
105107
SDL_GL_SwapBuffers();
106108
#endif
107109
}
108110

109111
int main( int argc, char *argv[] ) {
110-
projectMApp app;
111112
app.done = 0;
112113

113114
int width = 784,
114115
height = 784;
115116

116117

117118
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
118-
119+
119120
// get an audio input device
120121
if (! selectAudioInput(&app)) {
121122
fprintf(stderr, "Failed to open audio input device\n");
@@ -149,7 +150,7 @@ int main( int argc, char *argv[] ) {
149150
return PROJECTM_ERROR;
150151
}
151152
#endif
152-
153+
153154
#ifdef PANTS
154155
if ( fsaa ) {
155156
SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value );
@@ -159,8 +160,8 @@ int main( int argc, char *argv[] ) {
159160
}
160161
#endif
161162

162-
app.settings.meshX = 1;
163-
app.settings.meshY = 1;
163+
app.settings.meshX = 48;
164+
app.settings.meshY = 32;
164165
app.settings.fps = FPS;
165166
app.settings.textureSize = 2048; // idk?
166167
app.settings.windowWidth = width;
@@ -173,13 +174,13 @@ int main( int argc, char *argv[] ) {
173174
app.settings.shuffleEnabled = 1;
174175
app.settings.softCutRatingsEnabled = 1; // ???
175176
#ifdef EMSCRIPTEN
176-
app.settings.presetURL = "/build/presets";
177+
app.settings.presetURL = "presets";
177178
#else
178179
app.settings.presetURL = "presets_tryptonaut";
179180
app.settings.menuFontURL = "fonts/Vera.ttf";
180181
app.settings.titleFontURL = "fonts/Vera.ttf";
181182
#endif
182-
183+
183184
// init projectM
184185
app.pm = new projectM(app.settings);
185186
printf("init projectM\n");
@@ -188,6 +189,25 @@ int main( int argc, char *argv[] ) {
188189
app.pm->projectM_resetGL(width, height);
189190
printf("resetGL\n");
190191

192+
// Allocate a new a stream given the current directory name
193+
DIR * m_dir;
194+
if ((m_dir = opendir("/")) == NULL)
195+
{
196+
printf("error opening /\n");
197+
} else {
198+
199+
struct dirent * dir_entry;
200+
while ((dir_entry = readdir(m_dir)) != NULL)
201+
{
202+
printf("%s\n", dir_entry->d_name);
203+
}
204+
}
205+
206+
207+
for(int i = 0; i < app.pm->getPlaylistSize(); i++) {
208+
printf("%d\t%s\n", i, app.pm->getPresetName(i).c_str());
209+
}
210+
191211
// mainloop. non-emscripten version here for comparison/testing
192212
#ifdef EMSCRIPTEN
193213
emscripten_set_main_loop(renderFrame, 0, 0);

vendor/glm/CMakeLists.txt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
file(GLOB ROOT_SOURCE *.cpp)
2+
file(GLOB ROOT_INLINE *.inl)
3+
file(GLOB ROOT_HEADER *.hpp)
4+
file(GLOB ROOT_TEXT ../*.txt)
5+
file(GLOB ROOT_MD ../*.md)
6+
file(GLOB ROOT_NAT ../util/glm.natvis)
7+
8+
file(GLOB_RECURSE CORE_SOURCE ./detail/*.cpp)
9+
file(GLOB_RECURSE CORE_INLINE ./detail/*.inl)
10+
file(GLOB_RECURSE CORE_HEADER ./detail/*.hpp)
11+
12+
file(GLOB_RECURSE EXT_SOURCE ./ext/*.cpp)
13+
file(GLOB_RECURSE EXT_INLINE ./ext/*.inl)
14+
file(GLOB_RECURSE EXT_HEADER ./ext/*.hpp)
15+
16+
file(GLOB_RECURSE GTC_SOURCE ./gtc/*.cpp)
17+
file(GLOB_RECURSE GTC_INLINE ./gtc/*.inl)
18+
file(GLOB_RECURSE GTC_HEADER ./gtc/*.hpp)
19+
20+
file(GLOB_RECURSE GTX_SOURCE ./gtx/*.cpp)
21+
file(GLOB_RECURSE GTX_INLINE ./gtx/*.inl)
22+
file(GLOB_RECURSE GTX_HEADER ./gtx/*.hpp)
23+
24+
file(GLOB_RECURSE SIMD_SOURCE ./simd/*.cpp)
25+
file(GLOB_RECURSE SIMD_INLINE ./simd/*.inl)
26+
file(GLOB_RECURSE SIMD_HEADER ./simd/*.h)
27+
28+
source_group("Text Files" FILES ${ROOT_TEXT} ${ROOT_MD})
29+
source_group("Core Files" FILES ${CORE_SOURCE})
30+
source_group("Core Files" FILES ${CORE_INLINE})
31+
source_group("Core Files" FILES ${CORE_HEADER})
32+
source_group("EXT Files" FILES ${EXT_SOURCE})
33+
source_group("EXT Files" FILES ${EXT_INLINE})
34+
source_group("EXT Files" FILES ${EXT_HEADER})
35+
source_group("GTC Files" FILES ${GTC_SOURCE})
36+
source_group("GTC Files" FILES ${GTC_INLINE})
37+
source_group("GTC Files" FILES ${GTC_HEADER})
38+
source_group("GTX Files" FILES ${GTX_SOURCE})
39+
source_group("GTX Files" FILES ${GTX_INLINE})
40+
source_group("GTX Files" FILES ${GTX_HEADER})
41+
source_group("SIMD Files" FILES ${SIMD_SOURCE})
42+
source_group("SIMD Files" FILES ${SIMD_INLINE})
43+
source_group("SIMD Files" FILES ${SIMD_HEADER})
44+
45+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
46+
47+
if(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE)
48+
if(GLM_STATIC_LIBRARY_ENABLE)
49+
add_library(glm_static STATIC ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT}
50+
${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER}
51+
${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER}
52+
${EXT_SOURCE} ${EXT_INLINE} ${EXT_HEADER}
53+
${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER}
54+
${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER}
55+
${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER})
56+
endif(GLM_STATIC_LIBRARY_ENABLE)
57+
58+
if(GLM_DYNAMIC_LIBRARY_ENABLE)
59+
add_library(glm_shared SHARED ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT}
60+
${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER}
61+
${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER}
62+
${EXT_SOURCE} ${EXT_INLINE} ${EXT_HEADER}
63+
${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER}
64+
${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER}
65+
${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER})
66+
endif(GLM_DYNAMIC_LIBRARY_ENABLE)
67+
68+
else(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE)
69+
add_executable(glm_dummy ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT}
70+
${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER}
71+
${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER}
72+
${EXT_SOURCE} ${EXT_INLINE} ${EXT_HEADER}
73+
${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER}
74+
${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER}
75+
${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER})
76+
77+
endif(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE)

0 commit comments

Comments
 (0)