From 7fe60026beb1ab3f6aa4b95840c25196bb13a9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 26 May 2021 22:20:10 +0200 Subject: [PATCH] OpenGLRenderer: Minor fixes --- .../OpenGLRenderer/OpenGLFboFramebuffer.hpp | 6 +- include/Nazara/OpenGLRenderer/Wrapper.hpp | 1 - .../OpenGLRenderer/Wrapper/CoreFunctions.hpp | 24 +++---- .../OpenGLRenderer/Wrapper/RenderBuffer.hpp | 47 ------------- .../OpenGLRenderer/Wrapper/RenderBuffer.inl | 68 ------------------- .../OpenGLRenderer/OpenGLCommandBuffer.cpp | 5 +- .../OpenGLRenderer/OpenGLShaderBinding.cpp | 8 +-- .../OpenGLRenderer/OpenGLShaderModule.cpp | 2 +- src/Nazara/OpenGLRenderer/Wrapper/Context.cpp | 3 + 9 files changed, 26 insertions(+), 138 deletions(-) delete mode 100644 include/Nazara/OpenGLRenderer/Wrapper/RenderBuffer.hpp delete mode 100644 include/Nazara/OpenGLRenderer/Wrapper/RenderBuffer.inl diff --git a/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp b/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp index f4c5f960c..215012e04 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp +++ b/include/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef NAZARA_OPENGLRENDERER_OPENGLWINDOWFRAMEBUFFER_HPP -#define NAZARA_OPENGLRENDERER_OPENGLWINDOWFRAMEBUFFER_HPP +#ifndef NAZARA_OPENGLRENDERER_OPENGLFBOFRAMEBUFFER_HPP +#define NAZARA_OPENGLRENDERER_OPENGLFBOFRAMEBUFFER_HPP #include #include @@ -42,4 +42,4 @@ namespace Nz #include -#endif // NAZARA_OPENGLRENDERER_OpenGLWindowFramebuffer_HPP +#endif diff --git a/include/Nazara/OpenGLRenderer/Wrapper.hpp b/include/Nazara/OpenGLRenderer/Wrapper.hpp index 3c03da91b..dd2753244 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp b/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp index 7dc46042c..bc7c96bf0 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp @@ -34,6 +34,7 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G cb(glBlitFramebuffer, PFNGLBLITFRAMEBUFFERPROC) \ cb(glBufferData, PFNGLBUFFERDATAPROC) \ cb(glBufferSubData, PFNGLBUFFERSUBDATAPROC) \ + cb(glCheckFramebufferStatus, PFNGLCHECKFRAMEBUFFERSTATUSPROC) \ cb(glClear, PFNGLCLEARPROC) \ cb(glClearBufferfi, PFNGLCLEARBUFFERFIPROC) \ cb(glClearBufferfv, PFNGLCLEARBUFFERFVPROC) \ @@ -41,15 +42,14 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G cb(glClearColor, PFNGLCLEARCOLORPROC) \ cb(glClearDepthf, PFNGLCLEARDEPTHFPROC) \ cb(glClearStencil, PFNGLCLEARSTENCILPROC) \ - cb(glCreateProgram, PFNGLCREATEPROGRAMPROC) \ - cb(glCreateShader, PFNGLCREATESHADERPROC) \ - cb(glCheckFramebufferStatus, PFNGLCHECKFRAMEBUFFERSTATUSPROC) \ cb(glColorMask, PFNGLCOLORMASKPROC) \ + cb(glCompileShader, PFNGLCOMPILESHADERPROC) \ cb(glCompressedTexSubImage2D, PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) \ cb(glCompressedTexSubImage3D, PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) \ - cb(glCompileShader, PFNGLCOMPILESHADERPROC) \ cb(glCopyBufferSubData, PFNGLCOPYBUFFERSUBDATAPROC) \ cb(glCopyTexSubImage2D, PFNGLCOPYTEXSUBIMAGE2DPROC) \ + cb(glCreateProgram, PFNGLCREATEPROGRAMPROC) \ + cb(glCreateShader, PFNGLCREATESHADERPROC) \ cb(glCullFace, PFNGLCULLFACEPROC) \ cb(glDeleteBuffers, PFNGLDELETEBUFFERSPROC) \ cb(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC) \ @@ -76,14 +76,14 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G cb(glFramebufferRenderbuffer, PFNGLFRAMEBUFFERRENDERBUFFERPROC) \ cb(glFramebufferTexture2D, PFNGLFRAMEBUFFERTEXTURE2DPROC) \ cb(glFramebufferTextureLayer, PFNGLFRAMEBUFFERTEXTURELAYERPROC) \ - cb(glGenerateMipmap, PFNGLGENERATEMIPMAPPROC) \ cb(glGenBuffers, PFNGLGENBUFFERSPROC) \ cb(glGenFramebuffers, PFNGLGENFRAMEBUFFERSPROC) \ - cb(glGenRenderbuffers, PFNGLGENRENDERBUFFERSPROC) \ cb(glGenQueries, PFNGLGENQUERIESPROC) \ + cb(glGenRenderbuffers, PFNGLGENRENDERBUFFERSPROC) \ cb(glGenSamplers, PFNGLGENSAMPLERSPROC) \ cb(glGenTextures, PFNGLGENTEXTURESPROC) \ cb(glGenVertexArrays, PFNGLGENVERTEXARRAYSPROC) \ + cb(glGenerateMipmap, PFNGLGENERATEMIPMAPPROC) \ cb(glGetActiveUniform, PFNGLGETACTIVEUNIFORMPROC) \ cb(glGetBooleanv, PFNGLGETBOOLEANVPROC) \ cb(glGetBufferParameteriv, PFNGLGETBUFFERPARAMETERIVPROC) \ @@ -91,20 +91,20 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G cb(glGetFloatv, PFNGLGETFLOATVPROC) \ cb(glGetIntegerv, PFNGLGETINTEGERVPROC) \ cb(glGetProgramBinary, PFNGLGETPROGRAMBINARYPROC) \ - cb(glGetProgramiv, PFNGLGETPROGRAMIVPROC) \ cb(glGetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC) \ - cb(glGetQueryiv, PFNGLGETQUERYIVPROC) \ + cb(glGetProgramiv, PFNGLGETPROGRAMIVPROC) \ cb(glGetQueryObjectuiv, PFNGLGETQUERYOBJECTUIVPROC) \ + cb(glGetQueryiv, PFNGLGETQUERYIVPROC) \ cb(glGetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC) \ - cb(glGetShaderiv, PFNGLGETSHADERIVPROC) \ cb(glGetShaderSource, PFNGLGETSHADERSOURCEPROC) \ + cb(glGetShaderiv, PFNGLGETSHADERIVPROC) \ cb(glGetString, PFNGLGETSTRINGPROC) \ cb(glGetStringi, PFNGLGETSTRINGIPROC) \ cb(glGetTexParameterfv, PFNGLGETTEXPARAMETERFVPROC) \ cb(glGetTexParameteriv, PFNGLGETTEXPARAMETERIVPROC) \ + cb(glGetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC) \ cb(glGetUniformfv, PFNGLGETUNIFORMFVPROC) \ cb(glGetUniformiv, PFNGLGETUNIFORMIVPROC) \ - cb(glGetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC) \ cb(glIsEnabled, PFNGLISENABLEDPROC) \ cb(glLineWidth, PFNGLLINEWIDTHPROC) \ cb(glLinkProgram, PFNGLLINKPROGRAMPROC) \ @@ -136,8 +136,8 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G cb(glTexSubImage2D, PFNGLTEXSUBIMAGE2DPROC) \ cb(glTexSubImage3D, PFNGLTEXSUBIMAGE3DPROC) \ cb(glUniform1f, PFNGLUNIFORM1FPROC) \ - cb(glUniform1i, PFNGLUNIFORM1IPROC) \ cb(glUniform1fv, PFNGLUNIFORM1FVPROC) \ + cb(glUniform1i, PFNGLUNIFORM1IPROC) \ cb(glUniform1iv, PFNGLUNIFORM1IVPROC) \ cb(glUniform2fv, PFNGLUNIFORM2FVPROC) \ cb(glUniform2iv, PFNGLUNIFORM2IVPROC) \ @@ -151,8 +151,8 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G cb(glValidateProgram, PFNGLVALIDATEPROGRAMPROC) \ cb(glVertexAttrib4f, PFNGLVERTEXATTRIB4FPROC) \ cb(glVertexAttribDivisor, PFNGLVERTEXATTRIBDIVISORPROC) \ - cb(glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \ cb(glVertexAttribIPointer, PFNGLVERTEXATTRIBIPOINTERPROC) \ + cb(glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \ cb(glViewport, PFNGLVIEWPORTPROC) \ \ extCb(glDebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC) \ diff --git a/include/Nazara/OpenGLRenderer/Wrapper/RenderBuffer.hpp b/include/Nazara/OpenGLRenderer/Wrapper/RenderBuffer.hpp deleted file mode 100644 index 1dfbd2b62..000000000 --- a/include/Nazara/OpenGLRenderer/Wrapper/RenderBuffer.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - OpenGL Renderer" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_OPENGLRENDERER_VKFENCE_HPP -#define NAZARA_OPENGLRENDERER_VKFENCE_HPP - -#include -#include - -namespace Nz -{ - namespace Vk - { - class Fence : public DeviceObject - { - friend DeviceObject; - - public: - Fence() = default; - Fence(const Fence&) = delete; - Fence(Fence&&) = default; - ~Fence() = default; - - using DeviceObject::Create; - inline bool Create(Device& device, VkFenceCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); - - inline bool Reset(); - - inline bool Wait(); - inline bool Wait(UInt64 timeout, bool* didTimeout = nullptr); - - Fence& operator=(const Fence&) = delete; - Fence& operator=(Fence&&) = delete; - - private: - static inline VkResult CreateHelper(Device& device, const VkFenceCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFence* handle); - static inline void DestroyHelper(Device& device, VkFence handle, const VkAllocationCallbacks* allocator); - }; - } -} - -#include - -#endif // NAZARA_OPENGLRENDERER_VKFENCE_HPP diff --git a/include/Nazara/OpenGLRenderer/Wrapper/RenderBuffer.inl b/include/Nazara/OpenGLRenderer/Wrapper/RenderBuffer.inl deleted file mode 100644 index 855472b58..000000000 --- a/include/Nazara/OpenGLRenderer/Wrapper/RenderBuffer.inl +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - OpenGL Renderer" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - namespace Vk - { - inline bool Fence::Create(Device& device, VkFenceCreateFlags flags, const VkAllocationCallbacks* allocator) - { - VkFenceCreateInfo createInfo = - { - VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, - nullptr, - flags - }; - - return Create(device, createInfo, allocator); - } - - inline bool Fence::Reset() - { - m_lastErrorCode = m_device->vkResetFences(*m_device, 1U, &m_handle); - if (m_lastErrorCode != VK_SUCCESS) - { - NazaraError("Failed to reset fence: " + TranslateOpenGLError(m_lastErrorCode)); - return false; - } - - return true; - } - - inline bool Fence::Wait() - { - return Wait(std::numeric_limits::max()); - } - - inline bool Fence::Wait(UInt64 timeout, bool* didTimeout) - { - m_lastErrorCode = m_device->vkWaitForFences(*m_device, 1U, &m_handle, VK_TRUE, timeout); - if (m_lastErrorCode != VK_SUCCESS && m_lastErrorCode != VK_TIMEOUT) - { - NazaraError("Failed to wait for fence: " + TranslateOpenGLError(m_lastErrorCode)); - return false; - } - - if (didTimeout) - *didTimeout = (m_lastErrorCode == VK_TIMEOUT); - - return true; - } - - inline VkResult Fence::CreateHelper(Device& device, const VkFenceCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFence* handle) - { - return device.vkCreateFence(device, createInfo, allocator, handle); - } - - inline void Fence::DestroyHelper(Device& device, VkFence handle, const VkAllocationCallbacks* allocator) - { - return device.vkDestroyFence(device, handle, allocator); - } - } -} - -#include diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp index 4717f234f..c94b07ac0 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp @@ -71,7 +71,7 @@ namespace Nz if constexpr (std::is_same_v) { if (context->glPushDebugGroup) - context->glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, command.regionName.size(), command.regionName.data()); + context->glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, GLsizei(command.regionName.size()), command.regionName.data()); } else if constexpr (std::is_same_v) { @@ -143,11 +143,12 @@ namespace Nz void OpenGLCommandBuffer::ApplyStates(const GL::Context& context, const DrawStates& states) { - states.shaderBindings->Apply(context); states.pipeline->Apply(context); states.pipeline->FlipY(states.shouldFlipY); + states.shaderBindings->Apply(context); + if (states.scissorRegion) context.SetScissorBox(states.scissorRegion->x, states.scissorRegion->y, states.scissorRegion->width, states.scissorRegion->height); diff --git a/src/Nazara/OpenGLRenderer/OpenGLShaderBinding.cpp b/src/Nazara/OpenGLRenderer/OpenGLShaderBinding.cpp index f1287462c..cf0c031d1 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLShaderBinding.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLShaderBinding.cpp @@ -51,10 +51,10 @@ namespace Nz const auto& bindingDesc = layoutInfo.bindings[binding.bindingIndex]; std::size_t resourceIndex = 0; - for (std::size_t i = binding.bindingIndex; i > 0; --i) + for (std::size_t j = binding.bindingIndex; j > 0; --j) { - // Use i-1 to prevent underflow in for loop - if (layoutInfo.bindings[i - 1].type == bindingDesc.type) + // Use j-1 to prevent underflow in for loop + if (layoutInfo.bindings[j - 1].type == bindingDesc.type) resourceIndex++; } @@ -99,7 +99,7 @@ namespace Nz const UniformBufferBinding& uboBinding = std::get(binding.content); auto& uboDescriptor = m_owner.GetUniformBufferDescriptor(m_poolIndex, m_bindingIndex, resourceIndex); - uboDescriptor.bindingIndex = binding.bindingIndex; + uboDescriptor.bindingIndex = static_cast(binding.bindingIndex); uboDescriptor.offset = uboBinding.offset; uboDescriptor.size = uboBinding.range; diff --git a/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp b/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp index b284c4a98..ccf311edd 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp @@ -125,7 +125,7 @@ namespace Nz std::string code = writer.Generate(shaderStage, shaderAst, states); - shader.SetSource(code.data(), code.size()); + shader.SetSource(code.data(), GLint(code.size())); shader.Compile(); CheckCompilationStatus(shader); diff --git a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp index 5410b8253..ea512dad2 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp @@ -214,6 +214,9 @@ namespace Nz::GL unit.buffer = buffer; unit.offset = offset; unit.size = size; + + // glBindBufferRange does replace the currently bound buffer + m_state.bufferTargets[UnderlyingCast(BufferTarget::Uniform)] = buffer; } }