Skip to content

Commit

Permalink
Avoid glGetError on emscripten. Clear vertex attrib bindings on start
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugh Sanderson committed Sep 20, 2024
1 parent 170ee5a commit d5c2675
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion project/ToolkitBuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@
<compilerflag value="-DNME_SIMD_D" if="NME_SIMD_D" />
<compilerflag value="${NME_SIMD_D}" if="NME_SIMD_D" />
<compilerflag value="-I${ANGLE_DIR}/include" if="NME_ANGLE" />

<compilerflag value="-DNME_GFX_DEBUG" if="NME_GFX_DEBUG" />
<compilerflag value="-DNME_NO_GLGETERROR" if="emscripten" unless="NME_GFX_DEBUG" />

<cache value="1" unless="winrpi" />
<cache value="1" asLibrary="true" if="winrpi NME_STATIC_LINK" />
Expand Down
1 change: 0 additions & 1 deletion project/src/common/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define NME_NO_LZMA
#endif


#ifdef ANDROID
#include <android/log.h>
#endif
Expand Down
4 changes: 4 additions & 0 deletions project/src/opengl/OGLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ class OGLTexture : public Texture

if (mMipmaps)
{
#if (!defined(EMSCRIPTEN) || !defined(NME_NO_GETERROR))
glGetError();
glGenerateMipmap(GL_TEXTURE_2D);
int err = glGetError();
Expand All @@ -395,6 +396,7 @@ class OGLTexture : public Texture
ELOG("Error creating mipmaps @ %dx%d,%d/%d : %d\n", mTextureWidth, mTextureHeight, store_format,pixel_format, err);
mMipmaps = false;
}
#endif
}

mUploadedFormat = store_format;
Expand Down Expand Up @@ -528,9 +530,11 @@ class OGLTexture : public Texture
if (mMipmaps)
glGenerateMipmap(GL_TEXTURE_2D);

#ifndef NME_NO_GETERROR
int err = glGetError();
if (err != GL_NO_ERROR)
ELOG("GL Error: %d %dx%d", err, mDirtyRect.w, mDirtyRect.h);
#endif
mDirtyRect = Rect();
}
}
Expand Down
19 changes: 16 additions & 3 deletions project/src/opengl/OpenGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ void ReloadExtentions();

// --- HardwareRenderer Interface ---------------------------------------------------------



void ResetHardwareContext()
{
//__android_log_print(ANDROID_LOG_ERROR, "NME", "ResetHardwareContext");
Expand Down Expand Up @@ -108,8 +106,20 @@ class OGLContext : public HardwareRenderer
for(int i=0;i<PROG_COUNT;i++)
mProg[i] = 0;


makeCurrent();

#ifdef NME_GFX_DEBUG
printf("Vendor: %s\n", (char *)glGetString(GL_VENDOR) );
printf("Renderer: %s\n", (char *)glGetString(GL_RENDERER) );
printf("Sahder: %s\n", (char *)glGetString(GL_SHADING_LANGUAGE_VERSION) );
#endif

#ifdef EMSCRIPTEN
for(int i=0;i<4;i++)
glDisableVertexAttribArray(i);
#endif

const char *ext = (const char *)glGetString(GL_EXTENSIONS);
if (ext && *ext)
{
Expand Down Expand Up @@ -470,20 +480,23 @@ class OGLContext : public HardwareRenderer
void BeginDirectRender()
{
gDirectMaxAttribArray = 0;
#ifndef NME_NO_GETERROR
int err0 = glGetError();
if (err0 != GL_NO_ERROR)
ELOG("GL Error Before BeginDirectRender %d\n", err0);

#endif
}

void EndDirectRender()
{
for(int i=0;i<gDirectMaxAttribArray;i++)
glDisableVertexAttribArray(i);

#ifndef NME_NO_GETERROR
int err = glGetError();
if (err != GL_NO_ERROR)
ELOG("GL Error in DirectRender %d\n", err);
#endif
}


Expand Down
3 changes: 3 additions & 0 deletions project/src/sdl2/SDL2Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,6 +2961,7 @@ EMSCRIPTEN_KEEPALIVE int nmeOnCanvasSize()
}
}


void StartAnimation()
{
SDL_Event event;
Expand All @@ -2974,7 +2975,9 @@ void StartAnimation()
#endif
}

#ifndef NME_NO_AUDIO
clUpdateAsyncChannels();
#endif

if (sCheckCanvasSize)
{
Expand Down

0 comments on commit d5c2675

Please sign in to comment.