From 1750b0b34cb97ff9149bbc10284c37e662033e30 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Fri, 17 Jan 2020 21:13:51 +0000 Subject: [PATCH] Fixes GLES mode builds on Mesa and running on Intel Iris drivers. Patch By: linkmauve Tested By: Stan Differential Revision: https://code.wildfiregames.com/D2448 This was SVN commit r23410. --- binaries/data/mods/mod/hwdetect/hwdetect.js | 7 +++- .../mods/public/shaders/glsl/model_common.fs | 8 ++--- source/gui/ObjectTypes/CChart.cpp | 6 +++- source/lib/external_libraries/glext_funcs.h | 35 ++++++++++++++----- source/ps/GameSetup/HWDetect.cpp | 8 +++-- source/renderer/Renderer.cpp | 5 --- source/renderer/SkyManager.cpp | 6 ++-- 7 files changed, 49 insertions(+), 26 deletions(-) diff --git a/binaries/data/mods/mod/hwdetect/hwdetect.js b/binaries/data/mods/mod/hwdetect/hwdetect.js index affed13804..97cd9e6862 100644 --- a/binaries/data/mods/mod/hwdetect/hwdetect.js +++ b/binaries/data/mods/mod/hwdetect/hwdetect.js @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -219,6 +219,11 @@ function RunDetection(settings) if (GL_VERSION.match(/^[3-9]/)) enable_glsl = true; + // Enable GLSL on OpenGL ES 2.0+, which doesn’t support the fixed + // function fallbacks + if (GL_VERSION.match(/^OpenGL ES /)) + enable_glsl = true; + // Enable most graphics options on OpenGL 4+, which should be // able to properly manage them if (GL_VERSION.match(/^[4-9]/)) diff --git a/binaries/data/mods/public/shaders/glsl/model_common.fs b/binaries/data/mods/public/shaders/glsl/model_common.fs index b5d5300cce..79480a5ba2 100644 --- a/binaries/data/mods/public/shaders/glsl/model_common.fs +++ b/binaries/data/mods/public/shaders/glsl/model_common.fs @@ -129,13 +129,13 @@ void main() float height = 1.0; float scale = effectSettings.z; - int iter = int(min(20, 25.0 - dist/10.0)); + int iter = int(min(20.0, 25.0 - dist/10.0)); - if (iter > 0.01) + if (iter > 0) { - float s = 1.0/iter; + float s = 1.0/float(iter); float t = s; - move = vec2(-eyeDir.x, eyeDir.y) * scale / (eyeDir.z * iter); + move = vec2(-eyeDir.x, eyeDir.y) * scale / (eyeDir.z * float(iter)); vec2 nil = vec2(0.0); for (int i = 0; i < iter; ++i) { diff --git a/source/gui/ObjectTypes/CChart.cpp b/source/gui/ObjectTypes/CChart.cpp index a7a8ac812e..3c5113ba57 100644 --- a/source/gui/ObjectTypes/CChart.cpp +++ b/source/gui/ObjectTypes/CChart.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -86,12 +86,16 @@ void CChart::DrawLine(const CShaderProgramPtr& shader, const CGUIColor& color, c shader->VertexPointer(3, GL_FLOAT, 0, &vertices[0]); shader->AssertPointersBound(); +#if !CONFIG2_GLES glEnable(GL_LINE_SMOOTH); +#endif glLineWidth(1.1f); if (!g_Renderer.m_SkipSubmit) glDrawArrays(GL_LINE_STRIP, 0, vertices.size() / 3); glLineWidth(1.0f); +#if !CONFIG2_GLES glDisable(GL_LINE_SMOOTH); +#endif } void CChart::DrawTriangleStrip(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector& vertices) const diff --git a/source/lib/external_libraries/glext_funcs.h b/source/lib/external_libraries/glext_funcs.h index 99c930c7b3..1816940c53 100644 --- a/source/lib/external_libraries/glext_funcs.h +++ b/source/lib/external_libraries/glext_funcs.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -65,8 +65,6 @@ actually supported). #if CONFIG2_GLES -// no GLES extensions used yet - // some functions that are extensions in GL are core functions in GLES, // so we should use them without the function pointer indirection #define pglActiveTextureARB glActiveTexture @@ -106,22 +104,41 @@ actually supported). #define pglBufferSubDataARB glBufferSubData #define pglDeleteBuffersARB glDeleteBuffers #define pglGenBuffersARB glGenBuffers -#define pglMapBufferARB glMapBuffer -#define pglUnmapBufferARB glUnmapBuffer +// Those EXT symbols don’t exist in GLES 2.0, since it imported the ARB version instead. #define pglBindFramebufferEXT glBindFramebuffer #define pglCheckFramebufferStatusEXT glCheckFramebufferStatus #define pglDeleteFramebuffersEXT glDeleteFramebuffers #define pglFramebufferTexture2DEXT glFramebufferTexture2D #define pglGenFramebuffersEXT glGenFramebuffers - -#define GL_DEPTH_ATTACHMENT_EXT GL_DEPTH_ATTACHMENT -#define GL_COLOR_ATTACHMENT0_EXT GL_COLOR_ATTACHMENT0 #define GL_FRAMEBUFFER_BINDING_EXT GL_FRAMEBUFFER_BINDING #define GL_FRAMEBUFFER_COMPLETE_EXT GL_FRAMEBUFFER_COMPLETE #define GL_FRAMEBUFFER_EXT GL_FRAMEBUFFER -#define GL_CLAMP_TO_BORDER GL_CLAMP_TO_EDGE // TODO: should fix code that relies on GL_CLAMP_TO_BORDER +// Those should come from GLES 2.0 core, not from GL_EXT_draw_buffers. +#ifndef GL_COLOR_ATTACHMENT0_EXT +#define GL_COLOR_ATTACHMENT0_EXT GL_COLOR_ATTACHMENT0 +#define GL_COLOR_ATTACHMENT1_EXT GL_COLOR_ATTACHMENT1 +#endif +#ifndef GL_DEPTH_ATTACHMENT_EXT +#define GL_DEPTH_ATTACHMENT_EXT GL_DEPTH_ATTACHMENT +#endif + +// GL_OES_mapbuffer +FUNC(GLvoid*, glMapBufferOES, (GLenum target, GLenum access)) +FUNC(GLboolean, glUnmapBufferOES, (GLenum target)) +#define pglMapBufferARB pglMapBufferOES +#define pglUnmapBufferARB pglUnmapBufferOES +#define GL_WRITE_ONLY GL_WRITE_ONLY_OES + +// GL_OES_texture_border_clamp +#define GL_CLAMP_TO_BORDER GL_CLAMP_TO_EDGE + +// GL_OES_rgb8_rgba8 +#define GL_RGBA8 GL_RGBA8_OES + +// GL_OES_depth32 +#define GL_DEPTH_COMPONENT32 GL_DEPTH_COMPONENT32_OES typedef GLuint GLhandleARB; diff --git a/source/ps/GameSetup/HWDetect.cpp b/source/ps/GameSetup/HWDetect.cpp index cca604b32a..ead5030c0c 100644 --- a/source/ps/GameSetup/HWDetect.cpp +++ b/source/ps/GameSetup/HWDetect.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -44,7 +44,8 @@ #include "ps/UserReport.h" #include "ps/VideoMode.h" -#ifdef SDL_VIDEO_DRIVER_X11 +// TODO: Support OpenGL platforms which don’t use GLX as well. +#if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES #include #include "SDL_syswm.h" @@ -712,7 +713,8 @@ static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleVal #endif // CONFIG2_GLES -#ifdef SDL_VIDEO_DRIVER_X11 +// TODO: Support OpenGL platforms which don’t use GLX as well. +#if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES #define GLXQCR_INTEGER(id) do { \ unsigned int i = UINT_MAX; \ diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index 8fa9af6a2f..59da4544b6 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -433,11 +433,6 @@ CRenderer::CRenderer() if (skycolor.ParseString(skystring, 255.f)) SetClearColor(skycolor.AsSColor4ub()); -#if CONFIG2_GLES - // Override config option since GLES only supports GLSL - g_RenderingOptions.GetPreferGLSL() = true; -#endif - m_ShadowZBias = 0.02f; m_ShadowMapSize = 0; diff --git a/source/renderer/SkyManager.cpp b/source/renderer/SkyManager.cpp index bd1220c1ee..22273bbab8 100644 --- a/source/renderer/SkyManager.cpp +++ b/source/renderer/SkyManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -126,11 +126,11 @@ void SkyManager::LoadSkyTextures() } } - glTexImage2D(types[i], 0, GL_RGB, tex.m_Width, tex.m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &rotated[0]); + glTexImage2D(types[i], 0, GL_RGBA, tex.m_Width, tex.m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &rotated[0]); } else { - glTexImage2D(types[i], 0, GL_RGB, tex.m_Width, tex.m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + glTexImage2D(types[i], 0, GL_RGBA, tex.m_Width, tex.m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); } }