From eadf3047c0560045af9fb3e1bdb8d1b57fcdcf0b Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Wed, 3 Apr 2019 20:24:28 +0000 Subject: [PATCH 1/4] gles: no runtime load of libGLESv2 on non-android platforms --- core/rend/gles/gles.cpp | 3 +++ core/rend/gles/gles.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 6965ec97d..8aab28fe0 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -560,7 +560,10 @@ GLuint fogTextureId; return false; } #ifdef GLES +// EGL only supports runtime loading with android? TDB +#ifdef _ANDROID load_gles_symbols(); +#endif #else egl_makecurrent(); if (gl3wInit()) diff --git a/core/rend/gles/gles.h b/core/rend/gles/gles.h index 2b907c156..4fb98e656 100755 --- a/core/rend/gles/gles.h +++ b/core/rend/gles/gles.h @@ -15,7 +15,9 @@ #endif #include #include +#ifdef _ANDROID #include "gl32funcs.h" +#endif #ifndef GL_NV_draw_path //IMGTEC GLES emulation From 125cccaa5a1e82155c868739efa471f7abde1254 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Thu, 4 Apr 2019 08:10:32 +0000 Subject: [PATCH 2/4] gles: only use GLES3 functions on android --- core/rend/gles/gldraw.cpp | 6 ++++-- core/rend/gles/gles.cpp | 4 ++++ core/rend/gles/imgui_impl_opengl3.cpp | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/rend/gles/gldraw.cpp b/core/rend/gles/gldraw.cpp index 5ed09a66e..4d58204b8 100644 --- a/core/rend/gles/gldraw.cpp +++ b/core/rend/gles/gldraw.cpp @@ -934,9 +934,10 @@ void SetMVS_Mode(ModifierVolumeMode mv_mode, ISP_Modvol ispc) static void SetupMainVBO() { +#if !defined(GLES) || defined(_ANDROID) if (gl.gl_major >= 3) glBindVertexArray(gl.vbo.vao); - +#endif glBindBuffer(GL_ARRAY_BUFFER, gl.vbo.geometry); glCheck(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl.vbo.idxs); glCheck(); @@ -956,9 +957,10 @@ static void SetupMainVBO() void SetupModvolVBO() { +#if !defined(GLES) || defined(_ANDROID) if (gl.gl_major >= 3) glBindVertexArray(gl.vbo.vao); - +#endif glBindBuffer(GL_ARRAY_BUFFER, gl.vbo.modvols); glCheck(); //setup vertex buffers attrib pointers diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 8aab28fe0..3bf1ecfb7 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -1150,7 +1150,9 @@ bool gl_create_resources() //create vao //This is really not "proper", vaos are supposed to be defined once //i keep updating the same one to make the es2 code work in 3.1 context +#if !defined(GLES) || defined(_ANDROID) glGenVertexArrays(1, &gl.vbo.vao); +#endif } //create vbos @@ -1991,8 +1993,10 @@ struct glesrend : Renderer void DrawOSD(bool clear_screen) { +#if !defined(GLES) || defined(_ANDROID) if (gl.gl_major >= 3) glBindVertexArray(gl.vbo.vao); +#endif glBindBuffer(GL_ARRAY_BUFFER, gl.vbo.geometry); glCheck(); glEnableVertexAttribArray(VERTEX_POS_ARRAY); glVertexAttribPointer(VERTEX_POS_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,x)); diff --git a/core/rend/gles/imgui_impl_opengl3.cpp b/core/rend/gles/imgui_impl_opengl3.cpp index fce30f9fa..3107feaf2 100644 --- a/core/rend/gles/imgui_impl_opengl3.cpp +++ b/core/rend/gles/imgui_impl_opengl3.cpp @@ -161,6 +161,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr if (save_background) { +#if !defined(GLES) || defined(_ANDROID) if (!gl.is_gles && glReadBuffer != NULL) glReadBuffer(GL_FRONT); @@ -177,6 +178,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr // Copy the current framebuffer into it glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, fb_width, fb_height); +#endif } // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill @@ -208,10 +210,12 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr glUseProgram(g_ShaderHandle); glUniform1i(g_AttribLocationTex, 0); glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); +#if !defined(GLES) || defined(_ANDROID) if (gl.gl_major >= 3 && glBindSampler != NULL) glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise. - +#endif GLuint vao_handle = 0; +#if !defined(GLES) || defined(_ANDROID) if (gl.gl_major >= 3) { // Recreate the VAO every time @@ -219,6 +223,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr glGenVertexArrays(1, &vao_handle); glBindVertexArray(vao_handle); } +#endif glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); glEnableVertexAttribArray(g_AttribLocationPosition); glEnableVertexAttribArray(g_AttribLocationUV); @@ -267,18 +272,23 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr idx_buffer_offset += pcmd->ElemCount; } } +#if !defined(GLES) || defined(_ANDROID) if (vao_handle != 0) glDeleteVertexArrays(1, &vao_handle); - +#endif // Restore modified GL state glUseProgram(last_program); glBindTexture(GL_TEXTURE_2D, last_texture); +#if !defined(GLES) || defined(_ANDROID) if (gl.gl_major >= 3 && glBindSampler != NULL) glBindSampler(0, last_sampler); +#endif glActiveTexture(last_active_texture); glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); +#if !defined(GLES) || defined(_ANDROID) if (gl.gl_major >= 3) glBindVertexArray(last_vertex_array); +#endif glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha); glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha); if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND); @@ -537,8 +547,10 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects() // Restore modified GL state glBindTexture(GL_TEXTURE_2D, last_texture); glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); +#if !defined(GLES) || defined(_ANDROID) if (gl.gl_major >= 3) glBindVertexArray(last_vertex_array); +#endif return true; } From d9f2f9ae1d45a3d2478a68b7969719471af6d28e Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Wed, 15 May 2019 12:54:03 +0200 Subject: [PATCH 3/4] rend: define GLES2 and GLES3 GLES2 will only use GL ES 2.0 API functions, compile-time linked GLES3 loads functions dynamically and supports both GL ES 2.0 and 3.0 --- core/build.h | 4 ++++ core/rend/gles/gl32funcs.c | 3 ++- core/rend/gles/gldraw.cpp | 4 ++-- core/rend/gles/gles.cpp | 6 ++---- core/rend/gles/gles.h | 2 +- core/rend/gles/imgui_impl_opengl3.cpp | 8 ++++---- shell/android-studio/reicast/src/main/jni/Android.mk | 8 ++------ shell/linux/Makefile | 7 +++---- 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/core/build.h b/core/build.h index 57a00a46c..dc665872a 100755 --- a/core/build.h +++ b/core/build.h @@ -431,3 +431,7 @@ #define SH4_RAM_CLOCK (100*1000*1000) //[100000000] XTal(13.5) -> PLL (33.3) -> PLL 1:3 (100) , also suplied to HOLLY chip #define G2_BUS_CLOCK (25*1000*1000) //[25000000] from Holly, from SH4_RAM_CLOCK w/ 2 2:1 plls +#if defined(GLES) && !defined(GLES3) +// Only use GL ES 2.0 API functions +#define GLES2 +#endif diff --git a/core/rend/gles/gl32funcs.c b/core/rend/gles/gl32funcs.c index de06ae4ad..55625a428 100644 --- a/core/rend/gles/gl32funcs.c +++ b/core/rend/gles/gl32funcs.c @@ -2,10 +2,11 @@ #include #include #include "gl32funcs.h" +#include "build.h" void load_gles_symbols() { -#ifdef _ANDROID +#ifndef GLES2 for (int i = 0; rglgen_symbol_map[i].sym != NULL; i++) *(void **)rglgen_symbol_map[i].ptr = eglGetProcAddress(rglgen_symbol_map[i].sym); #endif diff --git a/core/rend/gles/gldraw.cpp b/core/rend/gles/gldraw.cpp index a8d3288c3..f25369414 100644 --- a/core/rend/gles/gldraw.cpp +++ b/core/rend/gles/gldraw.cpp @@ -948,7 +948,7 @@ void SetMVS_Mode(ModifierVolumeMode mv_mode, ISP_Modvol ispc) static void SetupMainVBO() { -#if !defined(GLES) || defined(_ANDROID) +#ifndef GLES2 if (gl.gl_major >= 3) glBindVertexArray(gl.vbo.vao); #endif @@ -971,7 +971,7 @@ static void SetupMainVBO() void SetupModvolVBO() { -#if !defined(GLES) || defined(_ANDROID) +#ifndef GLES2 if (gl.gl_major >= 3) glBindVertexArray(gl.vbo.vao); #endif diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 487981db3..0f65d02b4 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -565,9 +565,7 @@ GLuint fogTextureId; } #ifdef GLES // EGL only supports runtime loading with android? TDB -#ifdef _ANDROID load_gles_symbols(); -#endif #else egl_makecurrent(); if (gl3wInit()) @@ -1205,7 +1203,7 @@ bool gl_create_resources() //create vao //This is really not "proper", vaos are supposed to be defined once //i keep updating the same one to make the es2 code work in 3.1 context -#if !defined(GLES) || defined(_ANDROID) +#ifndef GLES2 glGenVertexArrays(1, &gl.vbo.vao); #endif } @@ -2006,7 +2004,7 @@ struct glesrend : Renderer void DrawOSD(bool clear_screen) { -#if !defined(GLES) || defined(_ANDROID) +#ifndef GLES2 if (gl.gl_major >= 3) glBindVertexArray(gl.vbo.vao); #endif diff --git a/core/rend/gles/gles.h b/core/rend/gles/gles.h index 6c2b892b2..dec2f287d 100755 --- a/core/rend/gles/gles.h +++ b/core/rend/gles/gles.h @@ -17,7 +17,7 @@ #endif #include #include -#ifdef _ANDROID +#ifndef GLES2 #include "gl32funcs.h" #endif diff --git a/core/rend/gles/imgui_impl_opengl3.cpp b/core/rend/gles/imgui_impl_opengl3.cpp index 4026341f1..4d2936b10 100644 --- a/core/rend/gles/imgui_impl_opengl3.cpp +++ b/core/rend/gles/imgui_impl_opengl3.cpp @@ -141,7 +141,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr if (save_background) { -#if !defined(GLES) || defined(_ANDROID) +#ifndef GLES2 if (!gl.is_gles && glReadBuffer != NULL) glReadBuffer(GL_FRONT); @@ -190,12 +190,12 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr glcache.UseProgram(g_ShaderHandle); glUniform1i(g_AttribLocationTex, 0); glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); -#if !defined(GLES) || defined(_ANDROID) +#ifndef GLES2 if (gl.gl_major >= 3 && glBindSampler != NULL) glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise. #endif GLuint vao_handle = 0; -#if !defined(GLES) || defined(_ANDROID) +#ifndef GLES2 if (gl.gl_major >= 3) { // Recreate the VAO every time @@ -252,7 +252,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr idx_buffer_offset += pcmd->ElemCount; } } -#if !defined(GLES) || defined(_ANDROID) +#ifndef GLES2 if (vao_handle != 0) glDeleteVertexArrays(1, &vao_handle); #endif diff --git a/shell/android-studio/reicast/src/main/jni/Android.mk b/shell/android-studio/reicast/src/main/jni/Android.mk index 0eb55d90a..3e0b41f8b 100644 --- a/shell/android-studio/reicast/src/main/jni/Android.mk +++ b/shell/android-studio/reicast/src/main/jni/Android.mk @@ -76,19 +76,15 @@ ifdef CHD5_FLAC endif ifdef NAOMI -LOCAL_CFLAGS += -DTARGET_NAOMI=1 -LOCAL_CPPFLAGS += -DTARGET_NAOMI=1 -LOCAL_CXXFLAGS += -DTARGET_NAOMI=1 + LOCAL_CFLAGS += -DTARGET_NAOMI=1 endif -# LOCAL_CFLAGS += -std=c++11 +LOCAL_CFLAGS += -DGLES3 LOCAL_CXXFLAGS += -std=c++11 -fopenmp LOCAL_LDFLAGS += -fopenmp ifeq ($(TARGET_ARCH_ABI),x86) LOCAL_CFLAGS+= -DTARGET_NO_AREC -DTARGET_NO_OPENMP - LOCAL_CXXFLAGS+= -DTARGET_NO_AREC -fpermissive -DTARGET_NO_OPENMP - LOCAL_CPPFLAGS+= -DTARGET_NO_AREC -DTARGET_NO_OPENMP endif LOCAL_CPP_FEATURES := diff --git a/shell/linux/Makefile b/shell/linux/Makefile index c3a32668a..355903c09 100644 --- a/shell/linux/Makefile +++ b/shell/linux/Makefile @@ -171,8 +171,7 @@ else ifneq (,$(findstring rpi,$(platform))) INCS += -I/opt/vc/include/ -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads LIBS += -L/opt/vc/lib/ -lbcm_host -ldl LIBS += -lbrcmEGL -lbrcmGLESv2 - CFLAGS += -D TARGET_VIDEOCORE - CXXFLAGS += -DGLES + CFLAGS += -D TARGET_VIDEOCORE -DGLES USE_OMX := 1 USE_DISPMANX := 1 endif @@ -208,7 +207,7 @@ else ifneq (,$(findstring odroid,$(platform))) ifneq (,$(findstring odroidxu3,$(platform))) MFLAGS += -march=armv7ve -mtune=cortex-a15.cortex-a7 ASFLAGS += -march=armv7ve - + CFLAGS += -DGLES3 # Other ODROIDs else MFLAGS += -march=armv7-a @@ -382,7 +381,7 @@ endif # GLES on x11? ifdef USE_GLES - CXXFLAGS += -DGLES + CFLAGS += -DGLES LIBS += -lEGL -lGLESv2 else ifdef FOR_LINUX LIBS += -ldl -lGL #for desktop gl From 6053a465f799a2fa4ec3680c05450704c4fada14 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Wed, 15 May 2019 13:07:52 +0200 Subject: [PATCH 4/4] fix win32 build --- core/rend/gles/gl32funcs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rend/gles/gl32funcs.c b/core/rend/gles/gl32funcs.c index 55625a428..05e54c41e 100644 --- a/core/rend/gles/gl32funcs.c +++ b/core/rend/gles/gl32funcs.c @@ -6,7 +6,7 @@ void load_gles_symbols() { -#ifndef GLES2 +#ifdef GLES3 for (int i = 0; rglgen_symbol_map[i].sym != NULL; i++) *(void **)rglgen_symbol_map[i].ptr = eglGetProcAddress(rglgen_symbol_map[i].sym); #endif