From 125cccaa5a1e82155c868739efa471f7abde1254 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Thu, 4 Apr 2019 08:10:32 +0000 Subject: [PATCH] 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; }