diff --git a/workload/glperfbench/include/glad/gl-headers.h b/workload/glperfbench/include/glad/gl-headers.h index 7d1bd20d7bb8b6522477469709c2d471a6951ab5..0830096f217371f8d5bf6876f6b5454d948a1f2a 100644 --- a/workload/glperfbench/include/glad/gl-headers.h +++ b/workload/glperfbench/include/glad/gl-headers.h @@ -1,6 +1,23 @@ #ifndef GL_HEADERS_H #define GL_HEADERS_H +#ifdef USE_GLES +#include + +/* These are GL definitions, used to indicate that we need some convertions in GLES path */ +#define GL_BGR 0x80E0 +#define GL_R16 0x822A + +/* These are GL extensions, mark as not supported */ +#define GLAD_GL_ARB_fragment_layer_viewport 0 +#define GLAD_GL_ARB_shader_atomic_counters 0 +#define GLAD_GL_ARB_shader_storage_buffer_object 0 +#define GLAD_GL_ARB_shading_language_420pack 0 +#define GLAD_GL_ARB_texture_storage 0 +#define GLAD_GL_ARB_shader_image_load_store 0 + +#else #include +#endif #endif \ No newline at end of file diff --git a/workload/glperfbench/include/node.h b/workload/glperfbench/include/node.h index 962ea294dd48a410981188bf8cdeb083e04c2f47..1eebfc47a0bebe8d8cf8cbd8dace6a52f9edb486 100644 --- a/workload/glperfbench/include/node.h +++ b/workload/glperfbench/include/node.h @@ -7,7 +7,6 @@ #include #include "glad/gl-headers.h" -#include #include "textrender.h" #include "window.h" diff --git a/workload/glperfbench/include/window.h b/workload/glperfbench/include/window.h index 256f22b50dcb72685972024923a564dd7c3a3019..7608f230115aadc8115dd23e2fc260f972af974d 100644 --- a/workload/glperfbench/include/window.h +++ b/workload/glperfbench/include/window.h @@ -5,7 +5,9 @@ #include #include #define GLFW_NO_GLU 1 +#ifndef USE_GLES #define GLFW_INCLUDE_GLCOREARB 1 +#endif #include diff --git a/workload/glperfbench/media/shaders/computeshader/cs.glsl b/workload/glperfbench/media/shaders/computeshader/cs.glsl index 73f74c2e66ab9add51db25540b6fc66ba744a268..e50397839cb866667353cee37540b282c7b795a6 100644 --- a/workload/glperfbench/media/shaders/computeshader/cs.glsl +++ b/workload/glperfbench/media/shaders/computeshader/cs.glsl @@ -21,8 +21,8 @@ void main(void) + gl_LocalInvocationID.y * gl_WorkGroupSize.x \ + gl_LocalInvocationID.x; - float hAngle = (float(gl_WorkGroupID.x) * (360.0f / gl_NumWorkGroups.x)) \ - + ((1.0f / float(gl_WorkGroupSize.x)) * gl_LocalInvocationID.x); + float hAngle = (float(gl_WorkGroupID.x) * (360.0f / float(gl_NumWorkGroups.x))) \ + + ((1.0f / float(gl_WorkGroupSize.x)) * float(gl_LocalInvocationID.x)); bufferData.vertices[vertexId].prop[0] = radius * cos(radians(hAngle)); bufferData.vertices[vertexId].prop[1] = float(gl_WorkGroupID.y) * (0.00005f + speedAdded / 5.0f); diff --git a/workload/glperfbench/media/shaders/computeshader/csless.glsl b/workload/glperfbench/media/shaders/computeshader/csless.glsl index 57afd8ebb15db9aa736a7e584f0e84cc4eef5e96..4f156ad1b810da85f1e88538d042dfc07a883062 100644 --- a/workload/glperfbench/media/shaders/computeshader/csless.glsl +++ b/workload/glperfbench/media/shaders/computeshader/csless.glsl @@ -13,7 +13,7 @@ uniform float speedAdded; void main(void) { float radius = 0.0005f + speedAdded; - radius = radius + ((0.0005f +speedAdded) * ( float(gl_WorkGroupID.y) / float(gl_NumWorkGroups.y) * 0.5f) * (gl_NumWorkGroups.y-gl_WorkGroupID.y/2)); + radius = radius + ((0.0005f +speedAdded) * ( float(gl_WorkGroupID.y) / float(gl_NumWorkGroups.y) * 0.5f) * (float(gl_NumWorkGroups.y) - float(gl_WorkGroupID.y)/2.0f)); uint vertexId = gl_WorkGroupID.z * gl_NumWorkGroups.y * gl_NumWorkGroups.x \ + gl_WorkGroupID.y * gl_NumWorkGroups.x \ + gl_WorkGroupID.x \ @@ -21,16 +21,16 @@ void main(void) + gl_LocalInvocationID.y * gl_WorkGroupSize.x \ + gl_LocalInvocationID.x; - float hAngle = (gl_WorkGroupID.x * (360 / gl_NumWorkGroups.x)) \ - + ((1.0f / float(gl_WorkGroupSize.x)) * gl_LocalInvocationID.x); + float hAngle = (float(gl_WorkGroupID.x) * (360.0f / float(gl_NumWorkGroups.x))) \ + + ((1.0f / float(gl_WorkGroupSize.x)) * float(gl_LocalInvocationID.x)); bufferData.vertices[vertexId].prop[0] = radius * cos(radians(hAngle)); bufferData.vertices[vertexId].prop[1] = float(gl_WorkGroupID.y) * (0.00005f + speedAdded / 5.0f); bufferData.vertices[vertexId].prop[2] = radius * sin(radians(hAngle)); bufferData.vertices[vertexId].prop[3] = 1.0f; - bufferData.vertices[vertexId].prop[4] = (130.0f * (1 - (float(gl_WorkGroupID.y) / float(gl_NumWorkGroups.y)))) / 255.0f; + bufferData.vertices[vertexId].prop[4] = (130.0f * (1.0f - (float(gl_WorkGroupID.y) / float(gl_NumWorkGroups.y)))) / 255.0f; bufferData.vertices[vertexId].prop[5] = 0.0f; - bufferData.vertices[vertexId].prop[6] = (1 - (float(gl_WorkGroupID.y) / float(gl_NumWorkGroups.y))) * (1.0f/2.0f); + bufferData.vertices[vertexId].prop[6] = (1.0f - (float(gl_WorkGroupID.y) / float(gl_NumWorkGroups.y))) * (1.0f/2.0f); } diff --git a/workload/glperfbench/media/shaders/fog/400/resolve.fs.glsl b/workload/glperfbench/media/shaders/fog/400/resolve.fs.glsl index 16d05fee9633174142f9b4bc4f30ffd570eaf87f..bfaaad385f19f567e13700c21807a64557e2d102 100644 --- a/workload/glperfbench/media/shaders/fog/400/resolve.fs.glsl +++ b/workload/glperfbench/media/shaders/fog/400/resolve.fs.glsl @@ -24,11 +24,11 @@ layout (binding = 0, std430) buffer list_item_block layout (location = 0) out vec4 color; -const uint max_fragments = 100; +const uint max_fragments = 100u; void main(void) { - uint frag_count = 0; + uint frag_count = 0u; float depth_accum = 0.0; ivec2 P = ivec2(gl_FragCoord.xy); diff --git a/workload/glperfbench/media/shaders/fog/430/resolve.fs.glsl b/workload/glperfbench/media/shaders/fog/430/resolve.fs.glsl index 3b5d427d3c152642dc9470c92a679e91543b6a58..20a913d3bed5c6e345528bd286df5f3296e1f6c0 100644 --- a/workload/glperfbench/media/shaders/fog/430/resolve.fs.glsl +++ b/workload/glperfbench/media/shaders/fog/430/resolve.fs.glsl @@ -21,11 +21,11 @@ layout (binding = 0, std430) buffer list_item_block layout (location = 0) out vec4 color; -const uint max_fragments = 100; +const uint max_fragments = 100u; void main(void) { - uint frag_count = 0; + uint frag_count = 0u; float depth_accum = 0.0; ivec2 P = ivec2(gl_FragCoord.xy); diff --git a/workload/glperfbench/media/shaders/instance/400/instance.fs.glsl b/workload/glperfbench/media/shaders/instance/400/instance.fs.glsl index 6905c9f9d210ecf128b4fcc049a7b697c38b066e..80769485e2b9f8dbe75ea8c0a540002bb9a2bf33 100644 --- a/workload/glperfbench/media/shaders/instance/400/instance.fs.glsl +++ b/workload/glperfbench/media/shaders/instance/400/instance.fs.glsl @@ -1,5 +1,6 @@ #version 400 core precision highp float; +precision highp samplerBuffer; #extension GL_ARB_shading_language_420pack : enable #extension GL_ARB_fragment_layer_viewport : enable diff --git a/workload/glperfbench/media/shaders/instance/430/instance.fs.glsl b/workload/glperfbench/media/shaders/instance/430/instance.fs.glsl index 9be74da346352953170ee1f2338cb371008cdb10..a1ed72f880fb00f4222bdbaffcb9d47f025a21f1 100644 --- a/workload/glperfbench/media/shaders/instance/430/instance.fs.glsl +++ b/workload/glperfbench/media/shaders/instance/430/instance.fs.glsl @@ -1,5 +1,6 @@ #version 430 core precision highp float; +precision highp samplerBuffer; in GS_OUT { diff --git a/workload/glperfbench/media/shaders/waterwave/waterwave.fs.glsl b/workload/glperfbench/media/shaders/waterwave/waterwave.fs.glsl index e1e56704c2e53859ebfcab9da5b5e98aa3fa8ebc..52bea9b1effb5b9b30d8ea2278a2f6e3f779fe50 100644 --- a/workload/glperfbench/media/shaders/waterwave/waterwave.fs.glsl +++ b/workload/glperfbench/media/shaders/waterwave/waterwave.fs.glsl @@ -1,4 +1,5 @@ #version 330 core +precision highp float; layout (location = 0) out vec4 fragColor; @@ -205,4 +206,4 @@ void main() // post fragColor = vec4(pow(color,vec3(0.65)), 1.0); -} \ No newline at end of file +} diff --git a/workload/glperfbench/media/shaders/waterwave/waterwave.vs.glsl b/workload/glperfbench/media/shaders/waterwave/waterwave.vs.glsl index cf04ab34879df87499cf392859167153e816729e..20b5b468d7ea8da9ebf337d08100272c9c5efbbf 100644 --- a/workload/glperfbench/media/shaders/waterwave/waterwave.vs.glsl +++ b/workload/glperfbench/media/shaders/waterwave/waterwave.vs.glsl @@ -7,8 +7,8 @@ void main(void) vec2(-1.0, 1.0), vec2(1.0, 1.0)); - vec2 pos_out = pos[gl_VertexID] + vec2(gl_InstanceID * 2.0, 0.0); + vec2 pos_out = pos[gl_VertexID] + vec2(float(gl_InstanceID) * 2.0, 0.0); gl_Position = vec4(pos_out.xy, 0.0, 1.0); -} \ No newline at end of file +} diff --git a/workload/glperfbench/src/CMakeLists.txt b/workload/glperfbench/src/CMakeLists.txt index 34ba98514d9545a6c07bfe2fa412ae5b76fd11c7..04685f6edc8342ec761e5a9a87a454b0f9d83028 100644 --- a/workload/glperfbench/src/CMakeLists.txt +++ b/workload/glperfbench/src/CMakeLists.txt @@ -74,7 +74,13 @@ add_definitions(-DGLSL_PATH="${PROJECT_SOURCE_DIR}/../media/") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LINUX -std=c++11") +SET(USE_GLES 0) +if(${USE_GLES} MATCHES 1) +add_definitions(-DUSE_GLES=1) +add_library(glad glad/gles2.c) +else() add_library(glad glad/gl.c) +endif() add_library(ftgl ftgl/distance-field.c ftgl/edtaa3func.c diff --git a/workload/glperfbench/src/fog/fog.cpp b/workload/glperfbench/src/fog/fog.cpp index e4d5061703bfdf998881b5d873b51a5619d8e071..2efe65b21902e7c1b3c0f858fa71fc5603a3e609 100644 --- a/workload/glperfbench/src/fog/fog.cpp +++ b/workload/glperfbench/src/fog/fog.cpp @@ -54,6 +54,10 @@ Fog::Fog() bool Fog::startup() { +#ifdef USE_GLES + /* Disable fog on GLES for now */ + return false; +#endif // glBindImageTexture/glMemoryBarrier added in 4.2 or ARB_shader_image_load_store // glTexStorage2D added in 4.2 or ARB_texture_storage // GL_ATOMIC_COUNTER_BUFFER added in 4.2 or ARB_shader_atomic_counters diff --git a/workload/glperfbench/src/glpbcommon/glslprogram.cpp b/workload/glperfbench/src/glpbcommon/glslprogram.cpp index 5107c7256392e7ae8617500109279e09d062c43e..7246c7cf873ad0919df70a48ba4d1bc9ed559747 100644 --- a/workload/glperfbench/src/glpbcommon/glslprogram.cpp +++ b/workload/glperfbench/src/glpbcommon/glslprogram.cpp @@ -93,6 +93,18 @@ bool GLSLProgram::compileShader(const char *file, GLSLShaderType shaderType) std::string source(sstream.str()); +#ifdef USE_GLES + std::string glsl_version_gles; + glsl_version_gles = "#version 320 es\n"; + + /* Find the first line */ + size_t pos = source.find('\n'); + if (pos != std::string::npos) { + /* Replace the first line with GLES */ + source.replace(0, pos + 1, glsl_version_gles); + } +#endif + GLuint shader = glCreateShader(shaderType); if (0 == shader) { Log::error("unspported shader type - %s\n", toString(shaderType).data()); diff --git a/workload/glperfbench/src/glpbcommon/texture.cpp b/workload/glperfbench/src/glpbcommon/texture.cpp index 90da9500a3071200babfb1340ab70e09f3342f7a..3d3a2b469fbc5df94d74d17162d629d18508f4a8 100644 --- a/workload/glperfbench/src/glpbcommon/texture.cpp +++ b/workload/glperfbench/src/glpbcommon/texture.cpp @@ -64,11 +64,9 @@ static unsigned int calculateStride(const header &h, unsigned int width, unsigne case GL_RG: channels = 2; break; - case GL_BGR: case GL_RGB: channels = 3; break; - case GL_BGRA: case GL_RGBA: channels = 4; break; @@ -129,11 +127,23 @@ GLuint Texture::loadKtxImage(const std::string &image) // Guess target (texture type) if (h.pixelHeight == 0) { +#ifdef USE_GLES + /* For GLES, there is no GL_TEXTURE_1D. Force to use TEXTURE_2D with height = 1 */ + h.pixelHeight = 1; + + if (h.arrayElements == 0) { + target = GL_TEXTURE_2D; + } + else { + target = GL_TEXTURE_2D_ARRAY; + } +#else if (h.arrayElements == 0) { target = GL_TEXTURE_1D; } else { target = GL_TEXTURE_1D_ARRAY; } +#endif } else if (h.pixelDepth == 0) { if (h.arrayElements == 0) { if (h.faces == 0) { @@ -172,29 +182,50 @@ GLuint Texture::loadKtxImage(const std::string &image) if (h.mipLevels == 0) h.mipLevels = 1; +#ifdef USE_GLES + /* GL_R16 indicates that the format has 16 bits in red, but does not specify + * whether the format is a 16-bit integer, unsigned integer, or floating point. + * GLES requires internal format to specify whether to use GL_R16I, GL_R16UI, or GL_16F. + * In GCBS tests, the texture is sampled in shader as GL_R16UI. So we specify it here */ + if (h.glInternalFormat == GL_R16 && h.glFormat == GL_RED) { + h.glInternalFormat = GL_R16UI; + h.glFormat = GL_RED_INTEGER; + } + + /* glTexImage2D in OpenGL supports both GL_BGR and GL_RGB. + * However, glTexImage2D in OpenGL ES only supports GL_RGB. + * Forcibly converting glFormat from GL_BGR to GL_RGB results in red and blue inversion, + * but the performance should not be affected. */ + if (h.glFormat == GL_BGR) { + h.glFormat = GL_RGB; + } +#endif + GLuint tex = 0; glGenTextures(1, &tex); glBindTexture(target, tex); switch (target) { +#ifndef USE_GLES case GL_TEXTURE_1D: glTexStorage1D(GL_TEXTURE_1D, h.mipLevels, h.glInternalFormat, h.pixelWidth); glTexSubImage1D(GL_TEXTURE_1D, 0, 0, h.pixelWidth, h.glFormat, h.glInternalFormat, data); break; +#endif case GL_TEXTURE_2D: if (h.glType == GL_NONE) { glCompressedTexImage2D(GL_TEXTURE_2D, 0, h.glInternalFormat, h.pixelWidth, h.pixelHeight, 0, 420 * 380 / 2, data); } else { - //glTexStorage2D(GL_TEXTURE_2D, h.mipLevels, h.glInternalFormat, h.pixelWidth, h.pixelHeight); + glTexStorage2D(GL_TEXTURE_2D, h.mipLevels, h.glInternalFormat, h.pixelWidth, h.pixelHeight); unsigned char *ptr = data; unsigned int height = h.pixelHeight; unsigned int width = h.pixelWidth; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for (unsigned int i = 0; i < h.mipLevels; i++) { - glTexImage2D(GL_TEXTURE_2D, i, h.glInternalFormat, width, height, 0, h.glFormat, h.glType, ptr); - //glTexSubImage2D(GL_TEXTURE_2D, i, 0, 0, width, height, h.glFormat, h.glType, ptr); + //glTexImage2D(GL_TEXTURE_2D, i, h.glInternalFormat, width, height, 0, h.glFormat, h.glType, ptr); + glTexSubImage2D(GL_TEXTURE_2D, i, 0, 0, width, height, h.glFormat, h.glType, ptr); ptr += height * calculateStride(h, width, 1); height >>= 1; width >>= 1; @@ -212,11 +243,13 @@ GLuint Texture::loadKtxImage(const std::string &image) glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, h.pixelWidth, h.pixelHeight, h.pixelDepth, h.glFormat, h.glType, data); break; +#ifndef USE_GLES case GL_TEXTURE_1D_ARRAY: glTexStorage2D(GL_TEXTURE_1D_ARRAY, h.mipLevels, h.glInternalFormat, h.pixelWidth, h.arrayElements); glTexSubImage2D(GL_TEXTURE_1D_ARRAY, 0, 0, 0, h.pixelWidth, h.arrayElements, h.glFormat, h.glType, data); break; +#endif case GL_TEXTURE_2D_ARRAY: glTexStorage3D(GL_TEXTURE_2D_ARRAY, h.mipLevels, h.glInternalFormat, h.pixelWidth, h.pixelHeight, h.arrayElements); diff --git a/workload/glperfbench/src/glpbcommon/window.cpp b/workload/glperfbench/src/glpbcommon/window.cpp index 97fc795f649e58466283f3d3eb753d85476e950e..9083684a485a92a34bd8abd7323ec86c254a24b1 100644 --- a/workload/glperfbench/src/glpbcommon/window.cpp +++ b/workload/glperfbench/src/glpbcommon/window.cpp @@ -27,7 +27,9 @@ int PerfWindow::windowHeight = 600; bool PerfWindow::isOpenGLSupported() { +#ifndef USE_GLES checBestGLVersion(); +#endif if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); @@ -35,6 +37,19 @@ bool PerfWindow::isOpenGLSupported() } glfwWindowHint(GLFW_VISIBLE, GL_FALSE); +#ifdef USE_GLES + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); + + glfwWindowHint(GLFW_ALPHA_BITS, 0); + + /* When using OpenGL ES, use fake GL version as 4.3 */ + PerfGLVersionManager::major = 4; + PerfGLVersionManager::minor = 3; + glVersion = 430; +#else if (PerfGLVersionManager::major * 10 + PerfGLVersionManager::minor >= 33) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, PerfGLVersionManager::major); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, PerfGLVersionManager::minor); @@ -42,7 +57,7 @@ bool PerfWindow::isOpenGLSupported() } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE); } - +#endif GLFWwindow *window = glfwCreateWindow(200, 200, "opengl version", NULL, NULL); if (!window) { fprintf(stderr, "failed to open window\n"); @@ -52,6 +67,12 @@ bool PerfWindow::isOpenGLSupported() glfwMakeContextCurrent(window); glfwHideWindow(window); +#ifdef USE_GLES + gladLoadGLES2(glfwGetProcAddress); + glfwSwapInterval(0); + + glVersion = 430; +#else gladLoadGL(glfwGetProcAddress); const unsigned char *version = glGetString(GL_VERSION); @@ -74,7 +95,7 @@ bool PerfWindow::isOpenGLSupported() printf("warning! GL Version is %d.%d, The GL version less than 3.3 !\n", version[0] - '0', version[2] - '0'); } - +#endif glfwDestroyWindow(window); glfwTerminate(); return true; @@ -169,6 +190,17 @@ bool PerfWindow::create() } glfwWindowHint(GLFW_SAMPLES, 16); + +#ifdef USE_GLES + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); + + /* ALPHA_BITS is set to 0 here manually to fix a bug on some GLFW versions with wayland backend. + * See GLFW commit 6281f49 fixed it. */ + glfwWindowHint(GLFW_ALPHA_BITS, 0); +#else if (glVersion >= 330) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, glVersion / 100); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, (glVersion / 10) % 10); @@ -176,6 +208,7 @@ bool PerfWindow::create() } else { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE); } +#endif glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); int desktopWidth = width; @@ -213,9 +246,15 @@ bool PerfWindow::create() glfwSetWindowSizeCallback(glfwWindow, &PerfWindow::onWindowResized); glfwMakeContextCurrent(glfwWindow); +#ifdef USE_GLES + gladLoadGLES2(glfwGetProcAddress); + glfwSwapInterval(0); +#else gladLoadGL(glfwGetProcAddress); glDisable(GL_MULTISAMPLE); +#endif + return true; } diff --git a/workload/glperfbench/src/mesh/mesh.cpp b/workload/glperfbench/src/mesh/mesh.cpp index 6db900bb792c0a51ce67b7a3af35c6ce6aa0bb36..8ec5434bb8b32ba80bde3ea184c0cdaba5662545 100644 --- a/workload/glperfbench/src/mesh/mesh.cpp +++ b/workload/glperfbench/src/mesh/mesh.cpp @@ -70,8 +70,11 @@ bool Mesh::startup() model->setUseGLPath(GL_TRUE); +#ifndef USE_GLES + /* glLogicOp is only provided in GLES 1.0 */ glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_OR); +#endif glEnable(GL_DEPTH_TEST); glPatchParameteri(GL_PATCH_VERTICES, 3); @@ -124,7 +127,10 @@ void Mesh::render(double currentTime, double difTime) glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); +#ifndef USE_GLES + /* GL_FILL is an inherent mode for GLES to draw polygons. No need to set GL_FILL.*/ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +#endif model->renderModel(); } @@ -133,14 +139,17 @@ void Mesh::shutdown() { glBindVertexArray(0); +#ifndef USE_GLES glDisable(GL_COLOR_LOGIC_OP); +#endif model->clearModel(); program.clear(); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); +#ifndef USE_GLES glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - +#endif glUseProgram(0); } diff --git a/workload/glperfbench/src/msaa/msaa.cpp b/workload/glperfbench/src/msaa/msaa.cpp index 19095107e46692172c602753081e0aaa3d55f264..542d4c3b6f5bed422ae895ddd0104cd1e38b226b 100644 --- a/workload/glperfbench/src/msaa/msaa.cpp +++ b/workload/glperfbench/src/msaa/msaa.cpp @@ -131,16 +131,23 @@ void Msaa::render(double currentTime, double difTime) if (loc >= 0) { glUniformMatrix4fv(loc, 1, GL_FALSE, projMatrix); } - +#ifndef USE_GLES glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +#endif glViewport(getWidth() >> 1, 0, getWidth() >> 1, getHeight()); glDrawArrays(GL_PATCHES, 0, 16); glViewport(0, 0, getWidth() >> 1, getHeight()); +#ifndef USE_GLES + /* glEnable(GL_MULTISAMPLE) is not supported on GLES for now. + * GLES specify GL_SAMPLES when create context. */ glEnable(GL_MULTISAMPLE); +#endif glDrawArrays(GL_PATCHES, 0, 16); +#ifndef USE_GLES glDisable(GL_MULTISAMPLE); +#endif glDisable(GL_DEPTH_TEST); } diff --git a/workload/glperfbench/src/skybox/skybox.cpp b/workload/glperfbench/src/skybox/skybox.cpp index 562e33ee36d846efc212bfb0168590e924303c45..836ba22959d7a0b33aa20f90f968b70c54254d05 100644 --- a/workload/glperfbench/src/skybox/skybox.cpp +++ b/workload/glperfbench/src/skybox/skybox.cpp @@ -60,7 +60,12 @@ bool Skybox::startup() "../media/shaders/skybox/skybox.fs.glsl")) return false; +#ifndef USE_GLES + /* OpenGL ES 3.0 requires that all cube map filtering be seamless, + * (See Appendix F.2 "Differences in Runtime Behavior" of the OpenGL ES 3.0 spec) + * so no longer need to enable GL_TEXTURE_CUBE_MAP_SEAMLESS for GLES. */ glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); +#endif std::array pictures = { "../media/textures/SanFrancisco3/posx.jpg", @@ -151,7 +156,9 @@ void Skybox::shutdown() glBindTexture(GL_TEXTURE_CUBE_MAP, 0); glUseProgram(0); glBindVertexArray(0); +#ifndef USE_GLES glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); +#endif glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); diff --git a/workload/glperfbench/src/sprite/sprite.cpp b/workload/glperfbench/src/sprite/sprite.cpp index 890441a32a2a4189e345fcf99cd944f81c1923df..961c5545933075aab8a0f856900964d597f61311 100644 --- a/workload/glperfbench/src/sprite/sprite.cpp +++ b/workload/glperfbench/src/sprite/sprite.cpp @@ -118,22 +118,30 @@ void Sprite::render(double currentTime, double difTime) glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); - +#ifndef USE_GLES + /* In OpenGL, user need to enable GL_PROGRAM_POINT_SIZE before using gl_PointSize in shader. + * In GLES, user can use gl_PointSize without calling glEnable. + */ glEnable(GL_PROGRAM_POINT_SIZE); +#endif glBindVertexArray(starVao); glBindTexture(GL_TEXTURE_2D, starTexture); glDrawArrays(GL_POINTS, 0, NUM_STARS); +#ifndef USE_GLES glDisable(GL_PROGRAM_POINT_SIZE); +#endif glDisable(GL_BLEND); } void Sprite::shutdown() { program.clear(); +#ifndef USE_GLES glDisable(GL_PROGRAM_POINT_SIZE); +#endif glDisable(GL_BLEND); glDeleteTextures(1, &starTexture); glDeleteBuffers(1, &starBuffer); diff --git a/workload/glperfbench/src/terrain/terrain.cpp b/workload/glperfbench/src/terrain/terrain.cpp index 825b73c3b030f06e8132392feae231025c0bee1a..6479403f1271ea27e04e112c0c92afcbec040645 100644 --- a/workload/glperfbench/src/terrain/terrain.cpp +++ b/workload/glperfbench/src/terrain/terrain.cpp @@ -166,7 +166,10 @@ void Terrain::render(double currentTime, double difTime) glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); +#ifndef USE_GLES + /* GL_FILL is an inherent mode for GLES to draw polygons. No need to set GL_FILL.*/ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +#endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); @@ -179,7 +182,9 @@ void Terrain::render(double currentTime, double difTime) glViewport(0, 0, getWidth(), getHeight()); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); +#ifndef USE_GLES glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +#endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); vmath::vec3 viewPos = vmath::vec3(eye[0], 10.0f, eye[2]); vmath::vec3 viewUp = vmath::vec3(0.0f, 0.0f, -1.0f); @@ -190,11 +195,11 @@ void Terrain::render(double currentTime, double difTime) glDrawArraysInstanced(GL_PATCHES, 0, 4, 64 * 64); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); - glReadPixels(0, 0, getWidth(), getHeight(), GL_RGB, GL_UNSIGNED_BYTE, nullptr); + glReadPixels(0, 0, getWidth(), getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, rightTopTex); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWidth(), getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWidth(), getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glGenerateMipmap(GL_TEXTURE_2D); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); @@ -221,7 +226,9 @@ void Terrain::shutdown() glActiveTexture(GL_TEXTURE0); glDisable(GL_DEPTH_TEST); +#ifndef USE_GLES glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +#endif glDeleteTextures(1, &texDisplacement); glDeleteTextures(1, &texColor); @@ -247,7 +254,7 @@ void Terrain::makeFrameBuffer() glGenTextures(1, &frameTexture); glBindTexture(GL_TEXTURE_2D, frameTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWidth(), getHeight(), 0, GL_RGBA, GL_UNSIGNED_INT, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWidth(), getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, frameTexture, 0); glBindTexture(GL_TEXTURE_2D, 0); @@ -283,7 +290,7 @@ void Terrain::makePbo() glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); glBufferData(GL_PIXEL_PACK_BUFFER, - static_cast(getWidth() * getHeight()) * sizeof(GLbyte) * 3, nullptr, GL_DYNAMIC_COPY); + static_cast(getWidth() * getHeight()) * sizeof(GLbyte) * 4, nullptr, GL_DYNAMIC_COPY); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); }