Skip to content

Commit 54fa76e

Browse files
authored
Merge pull request #45 from zakki/fix-mmman-sdl
Fix mmman sdl
2 parents b270c08 + 233c7a8 commit 54fa76e

File tree

12 files changed

+508
-522
lines changed

12 files changed

+508
-522
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ jobs:
4242
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
4343
- name: Build hsp3dish.js
4444
run: |
45-
cd src/hsp3dish
4645
make -f makefile.emscripten -j2
4746
- name: Build hspcmp.js
4847
run: |
@@ -53,7 +52,7 @@ jobs:
5352
with:
5453
name: openhsp-js
5554
path: |
56-
src/hsp3dish/*.js
57-
src/hsp3dish/*.wasm
55+
*.js
56+
*.wasm
5857
src/hspcmp/*.js
5958
src/hspcmp/*.wasm

makefile.emscripten

Lines changed: 451 additions & 0 deletions
Large diffs are not rendered by default.

src/hsp3dish/emscripten/fontsystem.cpp

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
#define USE_JAVA_FONT
6464
#define FONT_TEX_SX 512
6565
#define FONT_TEX_SY 128
66-
int hgio_fontsystem_get_texid(void);
6766
#endif
6867

6968
#if defined(HSPLINUX) || defined(HSPEMSCRIPTEN)
@@ -753,7 +752,6 @@ static int fontdata_size;
753752
static int fontdata_color;
754753
static int fontsystem_size;
755754
static int fontsystem_style;
756-
static int fontsystem_texid;
757755

758756
static int Get2N(int val)
759757
{
@@ -765,11 +763,6 @@ static int Get2N(int val)
765763
return res;
766764
}
767765

768-
int hgio_fontsystem_get_texid(void)
769-
{
770-
return fontsystem_texid;
771-
}
772-
773766
void hgio_fontsystem_term(void)
774767
{
775768
// フォントレンダリング解放
@@ -811,10 +804,11 @@ int hgio_fontsystem_exec(char* msg, unsigned char* buffer, int pitch, int* out_s
811804
}
812805
d.style.setProperty("font", $1 + "px 'sans-serif'");
813806

814-
const t = document.createTextNode(UTF8ToString($0));
815-
if (d.hasChildNodes())
816-
d.removeChild(d.firstChild);
817-
d.appendChild(t);
807+
//const t = document.createTextNode(UTF8ToString($0));
808+
//if (d.hasChildNodes())
809+
// d.removeChild(d.firstChild);
810+
//d.appendChild(t);
811+
d.innerText = UTF8ToString($0);
818812
HEAP32[$2 >> 2] = d.clientWidth | 0;
819813
HEAP32[$3 >> 2] = d.clientHeight | 0;
820814

@@ -854,33 +848,22 @@ int hgio_fontsystem_exec(char* msg, unsigned char* buffer, int pitch, int* out_s
854848
int sx = Get2N(fontsystem_sx);
855849
int sy = Get2N(fontsystem_sy);
856850

857-
GLuint id;
858-
glGenTextures( 1, &id );
859-
glBindTexture( GL_TEXTURE_2D, id );
860-
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, sx, sy, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
861-
862-
glBindTexture( GL_TEXTURE_2D, id );
863-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
864-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
865-
866-
glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
867-
868851
EM_ASM_({
869852
var canvas = document.getElementById('hsp3dishFontCanvas');
870-
if (canvas) {
871-
document.body.removeChild(canvas);
853+
if (!canvas) {
854+
//document.body.removeChild(canvas);
855+
canvas = document.createElement("canvas");
856+
canvas.id = 'hsp3dishFontCanvas';
857+
canvas.style.setProperty("visibility", "hidden");
858+
canvas.style.setProperty("position", "absolute");
859+
canvas.style.setProperty("top", "0");
860+
canvas.style.setProperty("left", "0");
861+
canvas.width = $2;
862+
canvas.height = $3;
863+
document.body.appendChild(canvas);
872864
}
873-
canvas = document.createElement("canvas");
874-
canvas.id = 'hsp3dishFontCanvas';
875-
canvas.style.setProperty("visibility", "hidden");
876-
canvas.style.setProperty("position", "absolute");
877-
canvas.style.setProperty("top", "0");
878-
canvas.style.setProperty("left", "0");
879-
canvas.width = $2;
880-
canvas.height = $3;
881-
document.body.appendChild(canvas);
882-
883-
var context = canvas.getContext("2d");
865+
866+
var context = canvas.getContext("2d", { willReadFrequently: true });
884867
context.font = $1 + "px 'sans-serif'";
885868

886869
var msg = UTF8ToString($0);
@@ -889,12 +872,11 @@ int hgio_fontsystem_exec(char* msg, unsigned char* buffer, int pitch, int* out_s
889872
context.fillText(msg, 0, $1);
890873
//console.log(msg);
891874

892-
GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, canvas);
893-
}, msg, fontsystem_size, sx, sy);
894-
875+
//GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, context.getImageData(0, 0, $2, $3));
876+
var imageData = context.getImageData(0, 0, $2, $3);
877+
HEAPU8.set(imageData.data, $4);
895878

896-
glBindTexture(GL_TEXTURE_2D, 0);
897-
fontsystem_texid = (int)id;
879+
}, msg, fontsystem_size, sx, sy, buffer);
898880

899881
//Alertf( "Init:Surface(%d,%d) %d destpitch%d",fontsystem_sx,fontsystem_sy,fontdata_color,pitch );
900882
*out_sx = fontsystem_sx;

src/hsp3dish/emscripten/hgiox.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
#define USE_JAVA_FONT
6464
#define FONT_TEX_SX 512
6565
#define FONT_TEX_SY 128
66-
int hgio_fontsystem_get_texid(void);
6766
#endif
6867

6968
#if defined(HSPLINUX) || defined(HSPEMSCRIPTEN)
@@ -493,9 +492,11 @@ void hgio_reset( void )
493492
//ポイントの設定
494493
glEnable(GL_POINT_SMOOTH);
495494

495+
#if !defined(HSPEMSCRIPTEN)
496496
//前処理
497497
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
498498
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
499+
#endif
499500

500501
//テクスチャ設定リセット
501502
TexReset();
@@ -2163,9 +2164,6 @@ void hgio_fontsystem_delete(int id)
21632164

21642165
int hgio_fontsystem_setup(int sx, int sy, void *buffer)
21652166
{
2166-
#if defined(HSPEMSCRIPTEN)
2167-
return hgio_fontsystem_get_texid();
2168-
#else
21692167
GLuint id;
21702168
glGenTextures( 1, &id );
21712169
glBindTexture( GL_TEXTURE_2D, id );
@@ -2175,7 +2173,6 @@ int hgio_fontsystem_setup(int sx, int sy, void *buffer)
21752173
ChangeTex( tid );
21762174
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, sx,sy, GL_RGBA, GL_UNSIGNED_BYTE, (char *)buffer);
21772175
return tid;
2178-
#endif
21792176
}
21802177

21812178

src/hsp3dish/emscripten/hgtex.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
#define USE_JAVA_FONT
6262
#define FONT_TEX_SX 512
6363
#define FONT_TEX_SY 128
64-
int hgio_fontsystem_get_texid(void);
6564
#endif
6665

6766
#if defined(HSPLINUX) || defined(HSPEMSCRIPTEN)

src/hsp3dish/emscripten/mmman.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,18 @@ MMMan::MMMan()
141141
engine_flag = false;
142142
MusicInit();
143143

144-
Mix_Init(MIX_INIT_OGG|MIX_INIT_MP3);
144+
int init_result = Mix_Init(MIX_INIT_OGG|MIX_INIT_MP3);
145+
if (init_result != (MIX_INIT_OGG|MIX_INIT_MP3)) {
146+
Alertf("[MMMan] Mix_Init: %d OGG:%d MP3:%d\n", init_result, init_result & MIX_INIT_OGG, init_result & MIX_INIT_MP3);
147+
}
145148

146-
Mix_ReserveChannels(16);
147149
int ret = Mix_OpenAudio(0, 0, 0, 0);
150+
151+
int allocated_channels = Mix_AllocateChannels(MIX_MAX_CHANNEL);
152+
if (allocated_channels != MIX_MAX_CHANNEL) {
153+
printf("[MMMan] Mix_AllocateChannels: %d\n", allocated_channels);
154+
}
155+
148156
//assert(ret == 0);
149157
engine_flag = ret == 0;
150158
}
@@ -155,9 +163,10 @@ MMMan::~MMMan()
155163
ClearAllBank();
156164
MusicTerm();
157165

166+
Mix_CloseAudio();
167+
158168
while(Mix_Init(0))
159169
Mix_Quit();
160-
Mix_CloseAudio();
161170
}
162171

163172
void MMMan::DeleteBank( int bank )

src/hsp3dish/gameplay/src/Base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ using std::va_list;
297297
#else
298298
#error "Unsupported Apple Device"
299299
#endif
300-
#elif EMSCRIPTEN
300+
#elif __EMSCRIPTEN__
301301
#define GLEW_STATIC
302302
#include <GL/glew.h>
303303
#define OPENGL_ES
304-
#define USE_VAO
304+
#define GP_USE_VAO
305305
#endif
306306

307307
// Graphics (GLSL)

src/hsp3dish/gameplay/src/DepthStencilTarget.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ DepthStencilTarget* DepthStencilTarget::create(const char* id, Format format, un
5050
__gl_error_code = glGetError();
5151
if ( __gl_error_code != GL_NO_ERROR)
5252
{
53+
#ifdef __EMSCRIPTEN__
54+
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height);
55+
}
56+
57+
__gl_error_code = glGetError();
58+
if ( __gl_error_code != GL_NO_ERROR)
59+
{
60+
#endif
5361
const char* extString = (const char*)glGetString(GL_EXTENSIONS);
5462

5563
if (strstr(extString, "GL_OES_packed_depth_stencil") != 0)

src/hsp3dish/gameplay/src/FrameBuffer.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ void FrameBuffer::setRenderTarget(RenderTarget* target, unsigned int index, GLen
221221

222222
// Restore the FBO binding
223223
GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, _currentFrameBuffer->_handle) );
224-
225-
// FIXME: Without this, setDepthStencilTarget will fail
226-
glGetError();
227224
}
228225
}
229226

@@ -261,14 +258,21 @@ void FrameBuffer::setDepthStencilTarget(DepthStencilTarget* target)
261258
GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, _handle) );
262259

263260
// Attach the render buffer to the framebuffer
264-
GL_ASSERT( glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthStencilTarget->_depthBuffer) );
265261
if (target->isPacked())
266262
{
267-
GL_ASSERT( glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthStencilTarget->_depthBuffer) );
263+
GL_ASSERT( glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthStencilTarget->_depthBuffer) );
268264
}
269265
else if (target->getFormat() == DepthStencilTarget::DEPTH_STENCIL)
270266
{
267+
#ifdef __EMSCRIPTEN__
268+
GP_WARN("Unexpected status %d %zu %zu", target->isPacked(), _depthStencilTarget->_depthBuffer, _depthStencilTarget->_stencilBuffer);
269+
GL_ASSERT( glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthStencilTarget->_depthBuffer) );
271270
GL_ASSERT( glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthStencilTarget->_stencilBuffer) );
271+
#endif
272+
}
273+
else
274+
{
275+
GL_ASSERT( glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthStencilTarget->_depthBuffer) );
272276
}
273277

274278
// Check the framebuffer is good to go.

0 commit comments

Comments
 (0)