From 2771c71fad9cc4311c287ad119d078662ef52c29 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 22 Aug 2020 20:26:49 -0700 Subject: Added USAGE_UNIFIED usage type (API 240066) --- Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp | 3 +++ Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp b/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp index 332fc304..a93528ec 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp @@ -71,6 +71,8 @@ inline GLenum TypeToGLType(VALUE_TYPE Value) inline GLenum UsageToGLUsage(const BufferDesc& Desc) { + static_assert(USAGE_NUM_USAGES == 5, "Please update this function to handle the new usage type"); + // http://www.informit.com/articles/article.aspx?p=2033340&seqNum=2 // https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glBufferData.xml switch (Desc.Usage) @@ -82,6 +84,7 @@ inline GLenum UsageToGLUsage(const BufferDesc& Desc) // clang-format off case USAGE_STATIC: return GL_STATIC_DRAW; case USAGE_DEFAULT: return GL_STATIC_DRAW; + case USAGE_UNIFIED: return GL_STATIC_DRAW; case USAGE_DYNAMIC: return GL_DYNAMIC_DRAW; case USAGE_STAGING: if(Desc.CPUAccessFlags & CPU_ACCESS_READ) diff --git a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp index 70df3725..e05d72ff 100644 --- a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp @@ -89,8 +89,15 @@ BufferGLImpl::BufferGLImpl(IReferenceCounters* pRefCounters, m_GLUsageHint {UsageToGLUsage(BuffDesc)} // clang-format on { - if (BuffDesc.Usage == USAGE_STATIC && (pBuffData == nullptr || pBuffData->pData == nullptr)) - LOG_ERROR_AND_THROW("Static buffer must be initialized with data at creation time"); + ValidateBufferInitData(BuffDesc, pBuffData); + + if (m_Desc.Usage == USAGE_UNIFIED) + { + DecayUnifiedBuffer(); + } + + if (m_Desc.Usage == USAGE_STATIC) + VERIFY(pBuffData != nullptr && pBuffData->pData != nullptr, "Initial data must not be null for static buffers"); // TODO: find out if it affects performance if the buffer is originally bound to one target // and then bound to another (such as first to GL_ARRAY_BUFFER and then to GL_UNIFORM_BUFFER) -- cgit v1.2.3