From e6cc18402d953f7272a1396cc0e985d53bba127a Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 9 Mar 2021 20:53:36 -0800 Subject: Renamed Texture*_OGL to Texture*_GL --- Graphics/GraphicsEngineOpenGL/CMakeLists.txt | 30 +-- .../include/Texture1DArray_GL.hpp | 69 +++++ .../include/Texture1DArray_OGL.hpp | 69 ----- .../GraphicsEngineOpenGL/include/Texture1D_GL.hpp | 69 +++++ .../GraphicsEngineOpenGL/include/Texture1D_OGL.hpp | 69 ----- .../include/Texture2DArray_GL.hpp | 69 +++++ .../include/Texture2DArray_OGL.hpp | 69 ----- .../GraphicsEngineOpenGL/include/Texture2D_GL.hpp | 77 ++++++ .../GraphicsEngineOpenGL/include/Texture2D_OGL.hpp | 77 ------ .../GraphicsEngineOpenGL/include/Texture3D_GL.hpp | 69 +++++ .../GraphicsEngineOpenGL/include/Texture3D_OGL.hpp | 69 ----- .../include/TextureCubeArray_GL.hpp | 69 +++++ .../include/TextureCubeArray_OGL.hpp | 69 ----- .../include/TextureCube_GL.hpp | 69 +++++ .../include/TextureCube_OGL.hpp | 69 ----- .../src/DeviceContextGLImpl.cpp | 10 +- .../src/RenderDeviceGLImpl.cpp | 44 +-- .../GraphicsEngineOpenGL/src/Texture1DArray_GL.cpp | 207 ++++++++++++++ .../src/Texture1DArray_OGL.cpp | 207 -------------- Graphics/GraphicsEngineOpenGL/src/Texture1D_GL.cpp | 186 +++++++++++++ .../GraphicsEngineOpenGL/src/Texture1D_OGL.cpp | 186 ------------- .../GraphicsEngineOpenGL/src/Texture2DArray_GL.cpp | 281 +++++++++++++++++++ .../src/Texture2DArray_OGL.cpp | 281 ------------------- Graphics/GraphicsEngineOpenGL/src/Texture2D_GL.cpp | 286 ++++++++++++++++++++ .../GraphicsEngineOpenGL/src/Texture2D_OGL.cpp | 286 -------------------- Graphics/GraphicsEngineOpenGL/src/Texture3D_GL.cpp | 224 ++++++++++++++++ .../GraphicsEngineOpenGL/src/Texture3D_OGL.cpp | 224 ---------------- .../src/TextureCubeArray_GL.cpp | 288 ++++++++++++++++++++ .../src/TextureCubeArray_OGL.cpp | 288 -------------------- .../GraphicsEngineOpenGL/src/TextureCube_GL.cpp | 296 +++++++++++++++++++++ .../GraphicsEngineOpenGL/src/TextureCube_OGL.cpp | 296 --------------------- 31 files changed, 2301 insertions(+), 2301 deletions(-) create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture1DArray_GL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.hpp create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture1D_GL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.hpp create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture2DArray_GL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.hpp create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture2D_GL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.hpp create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture3D_GL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.hpp create mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_GL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.hpp create mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureCube_GL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.hpp create mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture1DArray_GL.cpp delete mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp create mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture1D_GL.cpp delete mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp create mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture2DArray_GL.cpp delete mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp create mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture2D_GL.cpp delete mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp create mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture3D_GL.cpp delete mode 100644 Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp create mode 100644 Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_GL.cpp delete mode 100644 Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp create mode 100644 Graphics/GraphicsEngineOpenGL/src/TextureCube_GL.cpp delete mode 100644 Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index f9c10846..fb0e438b 100644 --- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt +++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt @@ -30,14 +30,14 @@ set(INCLUDE include/ShaderResourceBindingGLImpl.hpp include/SwapChainGLBase.hpp include/TexRegionRender.hpp - include/Texture1D_OGL.hpp - include/Texture1DArray_OGL.hpp - include/Texture2D_OGL.hpp - include/Texture2DArray_OGL.hpp - include/Texture3D_OGL.hpp + include/Texture1D_GL.hpp + include/Texture1DArray_GL.hpp + include/Texture2D_GL.hpp + include/Texture2DArray_GL.hpp + include/Texture3D_GL.hpp include/TextureBaseGL.hpp - include/TextureCube_OGL.hpp - include/TextureCubeArray_OGL.hpp + include/TextureCube_GL.hpp + include/TextureCubeArray_GL.hpp include/TextureViewGLImpl.hpp include/VAOCache.hpp ) @@ -83,14 +83,14 @@ set(SOURCE src/ShaderGLImpl.cpp src/ShaderResourceBindingGLImpl.cpp src/TexRegionRender.cpp - src/Texture1D_OGL.cpp - src/Texture1DArray_OGL.cpp - src/Texture2D_OGL.cpp - src/Texture2DArray_OGL.cpp - src/Texture3D_OGL.cpp + src/Texture1D_GL.cpp + src/Texture1DArray_GL.cpp + src/Texture2D_GL.cpp + src/Texture2DArray_GL.cpp + src/Texture3D_GL.cpp src/TextureBaseGL.cpp - src/TextureCube_OGL.cpp - src/TextureCubeArray_OGL.cpp + src/TextureCube_GL.cpp + src/TextureCubeArray_GL.cpp src/TextureViewGLImpl.cpp src/VAOCache.cpp ) @@ -219,7 +219,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") src/DeviceContextGLImpl.cpp src/GLContextState.cpp src/RenderDeviceGLImpl.cpp - src/Texture1D_OGL.cpp + src/Texture1D_GL.cpp PROPERTIES COMPILE_FLAGS -Wno-unused-variable ) diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_GL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_GL.hpp new file mode 100644 index 00000000..fd0a31b5 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_GL.hpp @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 1D texture array implementation in OpenGL backend. +class Texture1DArray_GL final : public TextureBaseGL +{ +public: + Texture1DArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture1DArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal = false); + ~Texture1DArray_GL(); + + /// Implementation of TextureBaseGL::UpdateData() for 1D texture array. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture array. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.hpp deleted file mode 100644 index a1dd412f..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "TextureBaseGL.hpp" - -namespace Diligent -{ - -/// 1D texture array implementation in OpenGL backend. -class Texture1DArray_OGL final : public TextureBaseGL -{ -public: - Texture1DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture1DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal = false); - ~Texture1DArray_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 1D texture array. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture array. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture1D_GL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture1D_GL.hpp new file mode 100644 index 00000000..472acc34 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture1D_GL.hpp @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 1D texture implementation in OpenGL backend. +class Texture1D_GL final : public TextureBaseGL +{ +public: + Texture1D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture1D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal = false); + ~Texture1D_GL(); + + /// Implementation of TextureBaseGL::UpdateData() for 1D texture. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.hpp deleted file mode 100644 index 6030561c..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "TextureBaseGL.hpp" - -namespace Diligent -{ - -/// 1D texture implementation in OpenGL backend. -class Texture1D_OGL final : public TextureBaseGL -{ -public: - Texture1D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture1D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal = false); - ~Texture1D_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 1D texture. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_GL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_GL.hpp new file mode 100644 index 00000000..ee75115b --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_GL.hpp @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 2D texture array implementation in OpenGL backend. +class Texture2DArray_GL final : public TextureBaseGL +{ +public: + Texture2DArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture2DArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal = false); + ~Texture2DArray_GL(); + + /// Implementation of TextureBaseGL::UpdateData() for 2D texture array. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture array. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.hpp deleted file mode 100644 index c5bc0624..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "TextureBaseGL.hpp" - -namespace Diligent -{ - -/// 2D texture array implementation in OpenGL backend. -class Texture2DArray_OGL final : public TextureBaseGL -{ -public: - Texture2DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture2DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal = false); - ~Texture2DArray_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 2D texture array. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture array. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture2D_GL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture2D_GL.hpp new file mode 100644 index 00000000..a2ced4ba --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture2D_GL.hpp @@ -0,0 +1,77 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 2D texture implementation in OpenGL backend. +class Texture2D_GL final : public TextureBaseGL +{ +public: + Texture2D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture2D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal = false); + + /// This constructor is used to create a dummy texture object for the default framebuffer. + Texture2D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + const TextureDesc& TexDesc, + bool bIsDeviceInternal = false); + + ~Texture2D_GL(); + + /// Implementation of TextureBaseGL::UpdateData() for 2D texture. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.hpp deleted file mode 100644 index cc5a2edb..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "TextureBaseGL.hpp" - -namespace Diligent -{ - -/// 2D texture implementation in OpenGL backend. -class Texture2D_OGL final : public TextureBaseGL -{ -public: - Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal = false); - - /// This constructor is used to create a dummy texture object for the default framebuffer. - Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - const TextureDesc& TexDesc, - bool bIsDeviceInternal = false); - - ~Texture2D_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 2D texture. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture3D_GL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture3D_GL.hpp new file mode 100644 index 00000000..f531c1e9 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture3D_GL.hpp @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 3D texture implementation in OpenGL backend. +class Texture3D_GL final : public TextureBaseGL +{ +public: + Texture3D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture3D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal = false); + ~Texture3D_GL(); + + /// Implementation of TextureBaseGL::UpdateData() for 3D texture. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 3D texture. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.hpp deleted file mode 100644 index 49581a93..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "TextureBaseGL.hpp" - -namespace Diligent -{ - -/// 3D texture implementation in OpenGL backend. -class Texture3D_OGL final : public TextureBaseGL -{ -public: - Texture3D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture3D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal = false); - ~Texture3D_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 3D texture. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 3D texture. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_GL.hpp b/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_GL.hpp new file mode 100644 index 00000000..03c95e09 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_GL.hpp @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// Cube array texture implementation in OpenGL backend. +class TextureCubeArray_GL final : public TextureBaseGL +{ +public: + TextureCubeArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + TextureCubeArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal = false); + ~TextureCubeArray_GL(); + + /// Implementation of TextureBaseGL::UpdateData() for cube texture array. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture array. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.hpp deleted file mode 100644 index 6fb6838e..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "TextureBaseGL.hpp" - -namespace Diligent -{ - -/// Cube array texture implementation in OpenGL backend. -class TextureCubeArray_OGL final : public TextureBaseGL -{ -public: - TextureCubeArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - TextureCubeArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal = false); - ~TextureCubeArray_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for cube texture array. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture array. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureCube_GL.hpp b/Graphics/GraphicsEngineOpenGL/include/TextureCube_GL.hpp new file mode 100644 index 00000000..f35d4066 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/TextureCube_GL.hpp @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// Cube texture implementation in OpenGL backend. +class TextureCube_GL final : public TextureBaseGL +{ +public: + TextureCube_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + TextureCube_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal = false); + ~TextureCube_GL(); + + /// Implementation of TextureBaseGL::UpdateData() for cube texture. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.hpp deleted file mode 100644 index 3e719878..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "TextureBaseGL.hpp" - -namespace Diligent -{ - -/// Cube texture implementation in OpenGL backend. -class TextureCube_OGL final : public TextureBaseGL -{ -public: - TextureCube_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - TextureCube_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal = false); - ~TextureCube_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for cube texture. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index e2c9bb0e..98f908b0 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -39,11 +39,11 @@ #include "RenderDeviceGLImpl.hpp" #include "BufferGLImpl.hpp" #include "ShaderGLImpl.hpp" -#include "Texture1D_OGL.hpp" -#include "Texture1DArray_OGL.hpp" -#include "Texture2D_OGL.hpp" -#include "Texture2DArray_OGL.hpp" -#include "Texture3D_OGL.hpp" +#include "Texture1D_GL.hpp" +#include "Texture1DArray_GL.hpp" +#include "Texture2D_GL.hpp" +#include "Texture2DArray_GL.hpp" +#include "Texture3D_GL.hpp" #include "SamplerGLImpl.hpp" #include "BufferViewGLImpl.hpp" #include "PipelineStateGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index 8cfdba7d..8cf07274 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp @@ -31,13 +31,13 @@ #include "BufferGLImpl.hpp" #include "ShaderGLImpl.hpp" -#include "Texture1D_OGL.hpp" -#include "Texture1DArray_OGL.hpp" -#include "Texture2D_OGL.hpp" -#include "Texture2DArray_OGL.hpp" -#include "Texture3D_OGL.hpp" -#include "TextureCube_OGL.hpp" -#include "TextureCubeArray_OGL.hpp" +#include "Texture1D_GL.hpp" +#include "Texture1DArray_GL.hpp" +#include "Texture2D_GL.hpp" +#include "Texture2DArray_GL.hpp" +#include "Texture3D_GL.hpp" +#include "TextureCube_GL.hpp" +#include "TextureCubeArray_GL.hpp" #include "SamplerGLImpl.hpp" #include "DeviceContextGLImpl.hpp" #include "PipelineStateGLImpl.hpp" @@ -547,31 +547,31 @@ void RenderDeviceGLImpl::CreateTexture(const TextureDesc& TexDesc, const Texture switch (TexDesc.Type) { case RESOURCE_DIM_TEX_1D: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture1D_OGL instance", Texture1D_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture1D_GL instance", Texture1D_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); break; case RESOURCE_DIM_TEX_1D_ARRAY: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture1DArray_OGL instance", Texture1DArray_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture1DArray_GL instance", Texture1DArray_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); break; case RESOURCE_DIM_TEX_2D: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture2D_OGL instance", Texture2D_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture2D_GL instance", Texture2D_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); break; case RESOURCE_DIM_TEX_2D_ARRAY: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture2DArray_OGL instance", Texture2DArray_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture2DArray_GL instance", Texture2DArray_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); break; case RESOURCE_DIM_TEX_3D: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture3D_OGL instance", Texture3D_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture3D_GL instance", Texture3D_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); break; case RESOURCE_DIM_TEX_CUBE: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "TextureCube_OGL instance", TextureCube_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "TextureCube_GL instance", TextureCube_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); break; case RESOURCE_DIM_TEX_CUBE_ARRAY: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "TextureCubeArray_OGL instance", TextureCubeArray_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "TextureCubeArray_GL instance", TextureCubeArray_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, pData, bIsDeviceInternal); break; default: LOG_ERROR_AND_THROW("Unknown texture type. (Did you forget to initialize the Type member of TextureDesc structure?)"); @@ -607,31 +607,31 @@ void RenderDeviceGLImpl::CreateTextureFromGLHandle(Uint32 GLHandle, switch (TexDesc.Type) { case RESOURCE_DIM_TEX_1D: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture1D_OGL instance", Texture1D_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture1D_GL instance", Texture1D_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); break; case RESOURCE_DIM_TEX_1D_ARRAY: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture1DArray_OGL instance", Texture1DArray_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture1DArray_GL instance", Texture1DArray_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); break; case RESOURCE_DIM_TEX_2D: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture2D_OGL instance", Texture2D_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture2D_GL instance", Texture2D_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); break; case RESOURCE_DIM_TEX_2D_ARRAY: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture2DArray_OGL instance", Texture2DArray_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture2DArray_GL instance", Texture2DArray_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); break; case RESOURCE_DIM_TEX_3D: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture3D_OGL instance", Texture3D_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Texture3D_GL instance", Texture3D_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); break; case RESOURCE_DIM_TEX_CUBE: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "TextureCube_OGL instance", TextureCube_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "TextureCube_GL instance", TextureCube_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); break; case RESOURCE_DIM_TEX_CUBE_ARRAY: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "TextureCubeArray_OGL instance", TextureCubeArray_OGL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "TextureCubeArray_GL instance", TextureCubeArray_GL)(m_TexViewObjAllocator, this, GLState, TexDesc, GLHandle, GLBindTarget); break; default: LOG_ERROR_AND_THROW("Unknown texture type. (Did you forget to initialize the Type member of TextureDesc structure?)"); @@ -653,7 +653,7 @@ void RenderDeviceGLImpl::CreateDummyTexture(const TextureDesc& TexDesc, RESOURCE switch (TexDesc.Type) { case RESOURCE_DIM_TEX_2D: - pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Dummy Texture2D_OGL instance", Texture2D_OGL)(m_TexViewObjAllocator, this, TexDesc); + pTextureOGL = NEW_RC_OBJ(m_TexObjAllocator, "Dummy Texture2D_GL instance", Texture2D_GL)(m_TexViewObjAllocator, this, TexDesc); break; default: LOG_ERROR_AND_THROW("Unsupported texture type."); diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_GL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_GL.cpp new file mode 100644 index 00000000..dcf32604 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_GL.cpp @@ -0,0 +1,207 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "Texture1DArray_GL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" +#include "BufferGLImpl.hpp" +#include "GLTypeConversions.hpp" + +namespace Diligent +{ + +Texture1DArray_GL::Texture1DArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/, + bool bIsDeviceInternal /*= false*/) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + TexDesc, + GL_TEXTURE_1D_ARRAY, + pInitData, + bIsDeviceInternal + } +// clang-format on +{ + if (TexDesc.Usage == USAGE_STAGING) + { + // We will use PBO initialized by TextureBaseGL + return; + } + + GLState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // levels format width height + glTexStorage2D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.ArraySize); + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 1D texture array"); + // When target is GL_TEXTURE_1D_ARRAY, calling glTexStorage2D() is equivalent to the following code: + //for (i = 0; i < levels; i++) + //{ + // glTexImage2D(target, i, internalformat, width, height, 0, format, type, NULL); + // width = max(1, (width / 2)); + //} + + SetDefaultGLParameters(); + + if (pInitData != nullptr && pInitData->pSubResources != nullptr) + { + if (m_Desc.MipLevels * m_Desc.ArraySize == pInitData->NumSubresources) + { + for (Uint32 Slice = 0; Slice < m_Desc.ArraySize; ++Slice) + { + for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) + { + Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), + 0, 1}; + // UpdateData() is a virtual function. If we try to call it through vtbl from here, + // we will get into TextureBaseGL::UpdateData(), because instance of Texture1DArray_GL + // is not fully constructed yet. + // To call the required function, we need to explicitly specify the class: + Texture1DArray_GL::UpdateData(GLState, Mip, Slice, DstBox, pInitData->pSubResources[Slice * m_Desc.MipLevels + Mip]); + } + } + } + else + { + UNEXPECTED("Incorrect number of subresources"); + } + } + + GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +Texture1DArray_GL::Texture1DArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + GLState, + TexDesc, + GLTextureHandle, + static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_1D_ARRAY), + bIsDeviceInternal + } +// clang-format on +{ +} + +Texture1DArray_GL::~Texture1DArray_GL() +{ +} + +void Texture1DArray_GL::UpdateData(GLContextState& ContextState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) +{ + TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); + + ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // Bind buffer if it is provided; copy from CPU memory otherwise + GLuint UnpackBuffer = 0; + if (SubresData.pSrcBuffer != nullptr) + { + auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); + UnpackBuffer = pBufferGL->GetGLHandle(); + } + + // Transfers to OpenGL memory are called unpack operations + // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer + // operations will be performed from this buffer. + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); + + const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + + glTexSubImage2D(m_BindTarget, MipLevel, + DstBox.MinX, + Slice, + DstBox.MaxX - DstBox.MinX, + 1, + TransferAttribs.PixelFormat, TransferAttribs.DataType, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage2D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + + CHECK_GL_ERROR("Failed to update subimage data"); + + if (UnpackBuffer != 0) + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + + ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +void Texture1DArray_GL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) +{ + if (ViewDesc.NumArraySlices == m_Desc.ArraySize) + { + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 1D array to draw framebuffer"); + glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 1D array to read framebuffer"); + } + else if (ViewDesc.NumArraySlices == 1) + { + // Texture name must either be zero or the name of an existing 3D texture, 1D or 2D array texture, + // cube map array texture, or multisample array texture. + glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); + CHECK_GL_ERROR("Failed to attach texture 1D array to draw framebuffer"); + glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); + CHECK_GL_ERROR("Failed to attach texture 1D array to read framebuffer"); + } + else + { + UNEXPECTED("Only one slice or the entire texture array can be attached to a framebuffer"); + } +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp deleted file mode 100644 index 8d49522b..00000000 --- a/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" - -#include "Texture1DArray_OGL.hpp" -#include "RenderDeviceGLImpl.hpp" -#include "DeviceContextGLImpl.hpp" -#include "BufferGLImpl.hpp" -#include "GLTypeConversions.hpp" - -namespace Diligent -{ - -Texture1DArray_OGL::Texture1DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/, - bool bIsDeviceInternal /*= false*/) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - TexDesc, - GL_TEXTURE_1D_ARRAY, - pInitData, - bIsDeviceInternal - } -// clang-format on -{ - if (TexDesc.Usage == USAGE_STAGING) - { - // We will use PBO initialized by TextureBaseGL - return; - } - - GLState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // levels format width height - glTexStorage2D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.ArraySize); - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 1D texture array"); - // When target is GL_TEXTURE_1D_ARRAY, calling glTexStorage2D() is equivalent to the following code: - //for (i = 0; i < levels; i++) - //{ - // glTexImage2D(target, i, internalformat, width, height, 0, format, type, NULL); - // width = max(1, (width / 2)); - //} - - SetDefaultGLParameters(); - - if (pInitData != nullptr && pInitData->pSubResources != nullptr) - { - if (m_Desc.MipLevels * m_Desc.ArraySize == pInitData->NumSubresources) - { - for (Uint32 Slice = 0; Slice < m_Desc.ArraySize; ++Slice) - { - for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) - { - Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), - 0, 1}; - // UpdateData() is a virtual function. If we try to call it through vtbl from here, - // we will get into TextureBaseGL::UpdateData(), because instance of Texture1DArray_OGL - // is not fully constructed yet. - // To call the required function, we need to explicitly specify the class: - Texture1DArray_OGL::UpdateData(GLState, Mip, Slice, DstBox, pInitData->pSubResources[Slice * m_Desc.MipLevels + Mip]); - } - } - } - else - { - UNEXPECTED("Incorrect number of subresources"); - } - } - - GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -Texture1DArray_OGL::Texture1DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - GLState, - TexDesc, - GLTextureHandle, - static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_1D_ARRAY), - bIsDeviceInternal - } -// clang-format on -{ -} - -Texture1DArray_OGL::~Texture1DArray_OGL() -{ -} - -void Texture1DArray_OGL::UpdateData(GLContextState& ContextState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) -{ - TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); - - ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // Bind buffer if it is provided; copy from CPU memory otherwise - GLuint UnpackBuffer = 0; - if (SubresData.pSrcBuffer != nullptr) - { - auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); - UnpackBuffer = pBufferGL->GetGLHandle(); - } - - // Transfers to OpenGL memory are called unpack operations - // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer - // operations will be performed from this buffer. - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); - - const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - - glTexSubImage2D(m_BindTarget, MipLevel, - DstBox.MinX, - Slice, - DstBox.MaxX - DstBox.MinX, - 1, - TransferAttribs.PixelFormat, TransferAttribs.DataType, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage2D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - - CHECK_GL_ERROR("Failed to update subimage data"); - - if (UnpackBuffer != 0) - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -void Texture1DArray_OGL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) -{ - if (ViewDesc.NumArraySlices == m_Desc.ArraySize) - { - glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 1D array to draw framebuffer"); - glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 1D array to read framebuffer"); - } - else if (ViewDesc.NumArraySlices == 1) - { - // Texture name must either be zero or the name of an existing 3D texture, 1D or 2D array texture, - // cube map array texture, or multisample array texture. - glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); - CHECK_GL_ERROR("Failed to attach texture 1D array to draw framebuffer"); - glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); - CHECK_GL_ERROR("Failed to attach texture 1D array to read framebuffer"); - } - else - { - UNEXPECTED("Only one slice or the entire texture array can be attached to a framebuffer"); - } -} - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture1D_GL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture1D_GL.cpp new file mode 100644 index 00000000..1fdd5135 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/src/Texture1D_GL.cpp @@ -0,0 +1,186 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "Texture1D_GL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" +#include "BufferGLImpl.hpp" +#include "GLTypeConversions.hpp" + +namespace Diligent +{ + +Texture1D_GL::Texture1D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/, + bool bIsDeviceInternal /*= false*/) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + TexDesc, + GL_TEXTURE_1D, + pInitData, + bIsDeviceInternal + } +// clang-format on +{ + if (TexDesc.Usage == USAGE_STAGING) + { + // We will use PBO initialized by TextureBaseGL + return; + } + + GLState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // levels format width + glTexStorage1D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width); + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 1D texture"); + // When target is GL_TEXTURE_1D, calling glTexStorage1D is equivalent to the following pseudo-code: + //for (i = 0; i < levels; i++) + //{ + // glTexImage1D(target, i, internalformat, width, 0, format, type, NULL); + // width = max(1, (width / 2)); + //} + + SetDefaultGLParameters(); + + if (pInitData != nullptr && pInitData->pSubResources != nullptr) + { + if (m_Desc.MipLevels == pInitData->NumSubresources) + { + for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) + { + Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), + 0, 1}; + // UpdateData() is a virtual function. If we try to call it through vtbl from here, + // we will get into TextureBaseGL::UpdateData(), because instance of Texture1D_GL + // is not fully constructed yet. + // To call the required function, we need to explicitly specify the class: + Texture1D_GL::UpdateData(GLState, Mip, 0, DstBox, pInitData->pSubResources[Mip]); + } + } + else + { + UNEXPECTED("Incorrect number of subresources"); + } + } + + GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +Texture1D_GL::Texture1D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + GLState, + TexDesc, + GLTextureHandle, + static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_1D), + bIsDeviceInternal + } +// clang-format on +{ +} + +Texture1D_GL::~Texture1D_GL() +{ +} + +void Texture1D_GL::UpdateData(GLContextState& ContextState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) +{ + TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); + + ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // Bind buffer if it is provided; copy from CPU memory otherwise + GLuint UnpackBuffer = 0; + if (SubresData.pSrcBuffer != nullptr) + { + auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); + UnpackBuffer = pBufferGL->GetGLHandle(); + } + + // Transfers to OpenGL memory are called unpack operations + // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer + // operations will be performed from this buffer. + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); + + const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + + glTexSubImage1D(m_BindTarget, MipLevel, + DstBox.MinX, + DstBox.MaxX - DstBox.MinX, + TransferAttribs.PixelFormat, TransferAttribs.DataType, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTexSubImage1D.xml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + CHECK_GL_ERROR("Failed to update subimage data"); + + if (UnpackBuffer != 0) + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + + ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +void Texture1D_GL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) +{ + // For glFramebufferTexture1D(), if texture name is not zero, then texture target must be GL_TEXTURE_1D + glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 1D to draw framebuffer"); + glFramebufferTexture1D(GL_READ_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 1D to read framebuffer"); +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp deleted file mode 100644 index 9ddd61bc..00000000 --- a/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" - -#include "Texture1D_OGL.hpp" -#include "RenderDeviceGLImpl.hpp" -#include "DeviceContextGLImpl.hpp" -#include "BufferGLImpl.hpp" -#include "GLTypeConversions.hpp" - -namespace Diligent -{ - -Texture1D_OGL::Texture1D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/, - bool bIsDeviceInternal /*= false*/) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - TexDesc, - GL_TEXTURE_1D, - pInitData, - bIsDeviceInternal - } -// clang-format on -{ - if (TexDesc.Usage == USAGE_STAGING) - { - // We will use PBO initialized by TextureBaseGL - return; - } - - GLState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // levels format width - glTexStorage1D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width); - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 1D texture"); - // When target is GL_TEXTURE_1D, calling glTexStorage1D is equivalent to the following pseudo-code: - //for (i = 0; i < levels; i++) - //{ - // glTexImage1D(target, i, internalformat, width, 0, format, type, NULL); - // width = max(1, (width / 2)); - //} - - SetDefaultGLParameters(); - - if (pInitData != nullptr && pInitData->pSubResources != nullptr) - { - if (m_Desc.MipLevels == pInitData->NumSubresources) - { - for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) - { - Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), - 0, 1}; - // UpdateData() is a virtual function. If we try to call it through vtbl from here, - // we will get into TextureBaseGL::UpdateData(), because instance of Texture1D_OGL - // is not fully constructed yet. - // To call the required function, we need to explicitly specify the class: - Texture1D_OGL::UpdateData(GLState, Mip, 0, DstBox, pInitData->pSubResources[Mip]); - } - } - else - { - UNEXPECTED("Incorrect number of subresources"); - } - } - - GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -Texture1D_OGL::Texture1D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - GLState, - TexDesc, - GLTextureHandle, - static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_1D), - bIsDeviceInternal - } -// clang-format on -{ -} - -Texture1D_OGL::~Texture1D_OGL() -{ -} - -void Texture1D_OGL::UpdateData(GLContextState& ContextState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) -{ - TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); - - ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // Bind buffer if it is provided; copy from CPU memory otherwise - GLuint UnpackBuffer = 0; - if (SubresData.pSrcBuffer != nullptr) - { - auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); - UnpackBuffer = pBufferGL->GetGLHandle(); - } - - // Transfers to OpenGL memory are called unpack operations - // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer - // operations will be performed from this buffer. - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); - - const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - - glTexSubImage1D(m_BindTarget, MipLevel, - DstBox.MinX, - DstBox.MaxX - DstBox.MinX, - TransferAttribs.PixelFormat, TransferAttribs.DataType, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTexSubImage1D.xml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - CHECK_GL_ERROR("Failed to update subimage data"); - - if (UnpackBuffer != 0) - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -void Texture1D_OGL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) -{ - // For glFramebufferTexture1D(), if texture name is not zero, then texture target must be GL_TEXTURE_1D - glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 1D to draw framebuffer"); - glFramebufferTexture1D(GL_READ_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 1D to read framebuffer"); -} - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_GL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_GL.cpp new file mode 100644 index 00000000..893c7e51 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_GL.cpp @@ -0,0 +1,281 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "Texture2DArray_GL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" +#include "BufferGLImpl.hpp" +#include "GLTypeConversions.hpp" +#include "GraphicsAccessories.hpp" + +namespace Diligent +{ + +Texture2DArray_GL::Texture2DArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/, + bool bIsDeviceInternal /*= false*/) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + TexDesc, + static_cast(TexDesc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE_ARRAY : GL_TEXTURE_2D_ARRAY), + pInitData, + bIsDeviceInternal + } +// clang-format on +{ + if (TexDesc.Usage == USAGE_STAGING) + { + // We will use PBO initialized by TextureBaseGL + return; + } + + GLState.BindTexture(-1, m_BindTarget, m_GlTexture); + + if (m_Desc.SampleCount > 1) + { + // format width height depth + glTexStorage3DMultisample(m_BindTarget, m_Desc.SampleCount, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.ArraySize, GL_TRUE); + // The last parameter specifies whether the image will use identical sample locations and the same number of + // samples for all texels in the image, and the sample locations will not depend on the internal format or size + // of the image. + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 2D multisample texture array"); + // * An INVALID_ENUM error is generated if sizedinternalformat is not colorrenderable, + // depth - renderable, or stencil - renderable + // * An INVALID_OPERATION error is generated if samples is greater than the maximum number of samples + // supported for this target and internalformat. The maximum number of samples supported can be + // determined by calling glGetInternalformativ with a pname of GL_SAMPLES + + SetDefaultGLParameters(); + } + else + { + // levels format width height depth + glTexStorage3D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.ArraySize); + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 2D texture array"); + // When target is GL_TEXTURE_2D_ARRAY, calling glTexStorage3D is equivalent to the following pseudo-code: + //for (i = 0; i < levels; i++) + //{ + // glTexImage3D(target, i, internalformat, width, height, depth, 0, format, type, NULL); + // width = max(1, (width / 2)); + // height = max(1, (height / 2)); + //} + + SetDefaultGLParameters(); + + if (pInitData != nullptr && pInitData->pSubResources != nullptr) + { + if (m_Desc.MipLevels * m_Desc.ArraySize == pInitData->NumSubresources) + { + for (Uint32 Slice = 0; Slice < m_Desc.ArraySize; ++Slice) + { + for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) + { + Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), + 0, std::max(m_Desc.Height >> Mip, 1U)}; + // UpdateData() is a virtual function. If we try to call it through vtbl from here, + // we will get into TextureBaseGL::UpdateData(), because instance of Texture2DArray_GL + // is not fully constructed yet. + // To call the required function, we need to explicitly specify the class: + Texture2DArray_GL::UpdateData(GLState, Mip, Slice, DstBox, pInitData->pSubResources[Slice * m_Desc.MipLevels + Mip]); + } + } + } + else + { + UNEXPECTED("Incorrect number of subresources"); + } + } + } + + GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +Texture2DArray_GL::Texture2DArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + GLState, + TexDesc, + GLTextureHandle, + GLBindTarget != 0 ? + static_cast(GLBindTarget) : + static_cast(TexDesc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE_ARRAY : GL_TEXTURE_2D_ARRAY), + bIsDeviceInternal + } +// clang-format on +{ +} + +Texture2DArray_GL::~Texture2DArray_GL() +{ +} + +void Texture2DArray_GL::UpdateData(GLContextState& ContextState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) +{ + TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); + + ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // Bind buffer if it is provided; copy from CPU memory otherwise + GLuint UnpackBuffer = 0; + if (SubresData.pSrcBuffer != nullptr) + { + auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); + UnpackBuffer = pBufferGL->GetGLHandle(); + } + + // Transfers to OpenGL memory are called unpack operations + // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer + // operations will be performed from this buffer. + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); + + const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + + if (TransferAttribs.IsCompressed) + { + auto MipWidth = std::max(m_Desc.Width >> MipLevel, 1U); + auto MipHeight = std::max(m_Desc.Height >> MipLevel, 1U); + VERIFY((DstBox.MinX % 4) == 0 && (DstBox.MinY % 4) == 0 && + ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) && + ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight), + "Compressed texture update region must be 4 pixel-aligned"); +#ifdef DILIGENT_DEBUG + { + const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format); + auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize}; + VERIFY(SubresData.Stride == BlockBytesInRow, + "Compressed data stride (", SubresData.Stride, " must match the size of a row of compressed blocks (", BlockBytesInRow, ")"); + } +#endif + //glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + //glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 0); + auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; + auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; + UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - DstBox.MinX); + UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - DstBox.MinY); + glCompressedTexSubImage3D(m_BindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + Slice, + UpdateRegionWidth, + UpdateRegionHeight, + 1, + // The format must be the same compressed-texture format previously + // specified by glTexStorage2D() (thank you OpenGL for another useless + // parameter that is nothing but the source of confusion), otherwise + // INVALID_OPERATION error is generated. + m_GLTexFormat, + // An INVALID_VALUE error is generated if imageSize is not consistent with + // the format, dimensions, and contents of the compressed image( too little or + // too much data ), + ((DstBox.MaxY - DstBox.MinY + 3) / 4) * SubresData.Stride, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage3D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + } + else + { + const auto TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); + const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; + VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); + glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + + glTexSubImage3D(m_BindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + Slice, + DstBox.MaxX - DstBox.MinX, + DstBox.MaxY - DstBox.MinY, + 1, + TransferAttribs.PixelFormat, TransferAttribs.DataType, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage3D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + } + CHECK_GL_ERROR("Failed to update subimage data"); + + if (UnpackBuffer != 0) + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + + ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +void Texture2DArray_GL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) +{ + if (ViewDesc.NumArraySlices == m_Desc.ArraySize) + { + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 2D array to draw framebuffer"); + glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 2D array to read framebuffer"); + } + else if (ViewDesc.NumArraySlices == 1) + { + // Texture name must either be zero or the name of an existing 3D texture, 1D or 2D array texture, + // cube map array texture, or multisample array texture. + glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); + CHECK_GL_ERROR("Failed to attach texture 2D array to draw framebuffer"); + glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); + CHECK_GL_ERROR("Failed to attach texture 2D array to read framebuffer"); + } + else + { + UNEXPECTED("Only one slice or the entire texture array can be attached to a framebuffer"); + } +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp deleted file mode 100644 index a544c080..00000000 --- a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" - -#include "Texture2DArray_OGL.hpp" -#include "RenderDeviceGLImpl.hpp" -#include "DeviceContextGLImpl.hpp" -#include "BufferGLImpl.hpp" -#include "GLTypeConversions.hpp" -#include "GraphicsAccessories.hpp" - -namespace Diligent -{ - -Texture2DArray_OGL::Texture2DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/, - bool bIsDeviceInternal /*= false*/) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - TexDesc, - static_cast(TexDesc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE_ARRAY : GL_TEXTURE_2D_ARRAY), - pInitData, - bIsDeviceInternal - } -// clang-format on -{ - if (TexDesc.Usage == USAGE_STAGING) - { - // We will use PBO initialized by TextureBaseGL - return; - } - - GLState.BindTexture(-1, m_BindTarget, m_GlTexture); - - if (m_Desc.SampleCount > 1) - { - // format width height depth - glTexStorage3DMultisample(m_BindTarget, m_Desc.SampleCount, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.ArraySize, GL_TRUE); - // The last parameter specifies whether the image will use identical sample locations and the same number of - // samples for all texels in the image, and the sample locations will not depend on the internal format or size - // of the image. - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 2D multisample texture array"); - // * An INVALID_ENUM error is generated if sizedinternalformat is not colorrenderable, - // depth - renderable, or stencil - renderable - // * An INVALID_OPERATION error is generated if samples is greater than the maximum number of samples - // supported for this target and internalformat. The maximum number of samples supported can be - // determined by calling glGetInternalformativ with a pname of GL_SAMPLES - - SetDefaultGLParameters(); - } - else - { - // levels format width height depth - glTexStorage3D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.ArraySize); - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 2D texture array"); - // When target is GL_TEXTURE_2D_ARRAY, calling glTexStorage3D is equivalent to the following pseudo-code: - //for (i = 0; i < levels; i++) - //{ - // glTexImage3D(target, i, internalformat, width, height, depth, 0, format, type, NULL); - // width = max(1, (width / 2)); - // height = max(1, (height / 2)); - //} - - SetDefaultGLParameters(); - - if (pInitData != nullptr && pInitData->pSubResources != nullptr) - { - if (m_Desc.MipLevels * m_Desc.ArraySize == pInitData->NumSubresources) - { - for (Uint32 Slice = 0; Slice < m_Desc.ArraySize; ++Slice) - { - for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) - { - Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), - 0, std::max(m_Desc.Height >> Mip, 1U)}; - // UpdateData() is a virtual function. If we try to call it through vtbl from here, - // we will get into TextureBaseGL::UpdateData(), because instance of Texture2DArray_OGL - // is not fully constructed yet. - // To call the required function, we need to explicitly specify the class: - Texture2DArray_OGL::UpdateData(GLState, Mip, Slice, DstBox, pInitData->pSubResources[Slice * m_Desc.MipLevels + Mip]); - } - } - } - else - { - UNEXPECTED("Incorrect number of subresources"); - } - } - } - - GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -Texture2DArray_OGL::Texture2DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - GLState, - TexDesc, - GLTextureHandle, - GLBindTarget != 0 ? - static_cast(GLBindTarget) : - static_cast(TexDesc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE_ARRAY : GL_TEXTURE_2D_ARRAY), - bIsDeviceInternal - } -// clang-format on -{ -} - -Texture2DArray_OGL::~Texture2DArray_OGL() -{ -} - -void Texture2DArray_OGL::UpdateData(GLContextState& ContextState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) -{ - TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); - - ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // Bind buffer if it is provided; copy from CPU memory otherwise - GLuint UnpackBuffer = 0; - if (SubresData.pSrcBuffer != nullptr) - { - auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); - UnpackBuffer = pBufferGL->GetGLHandle(); - } - - // Transfers to OpenGL memory are called unpack operations - // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer - // operations will be performed from this buffer. - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); - - const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - - if (TransferAttribs.IsCompressed) - { - auto MipWidth = std::max(m_Desc.Width >> MipLevel, 1U); - auto MipHeight = std::max(m_Desc.Height >> MipLevel, 1U); - VERIFY((DstBox.MinX % 4) == 0 && (DstBox.MinY % 4) == 0 && - ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) && - ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight), - "Compressed texture update region must be 4 pixel-aligned"); -#ifdef DILIGENT_DEBUG - { - const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format); - auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize}; - VERIFY(SubresData.Stride == BlockBytesInRow, - "Compressed data stride (", SubresData.Stride, " must match the size of a row of compressed blocks (", BlockBytesInRow, ")"); - } -#endif - //glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - //glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 0); - auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; - auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; - UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - DstBox.MinX); - UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - DstBox.MinY); - glCompressedTexSubImage3D(m_BindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - Slice, - UpdateRegionWidth, - UpdateRegionHeight, - 1, - // The format must be the same compressed-texture format previously - // specified by glTexStorage2D() (thank you OpenGL for another useless - // parameter that is nothing but the source of confusion), otherwise - // INVALID_OPERATION error is generated. - m_GLTexFormat, - // An INVALID_VALUE error is generated if imageSize is not consistent with - // the format, dimensions, and contents of the compressed image( too little or - // too much data ), - ((DstBox.MaxY - DstBox.MinY + 3) / 4) * SubresData.Stride, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage3D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - } - else - { - const auto TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); - const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; - VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); - glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - - glTexSubImage3D(m_BindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - Slice, - DstBox.MaxX - DstBox.MinX, - DstBox.MaxY - DstBox.MinY, - 1, - TransferAttribs.PixelFormat, TransferAttribs.DataType, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage3D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - } - CHECK_GL_ERROR("Failed to update subimage data"); - - if (UnpackBuffer != 0) - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -void Texture2DArray_OGL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) -{ - if (ViewDesc.NumArraySlices == m_Desc.ArraySize) - { - glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 2D array to draw framebuffer"); - glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 2D array to read framebuffer"); - } - else if (ViewDesc.NumArraySlices == 1) - { - // Texture name must either be zero or the name of an existing 3D texture, 1D or 2D array texture, - // cube map array texture, or multisample array texture. - glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); - CHECK_GL_ERROR("Failed to attach texture 2D array to draw framebuffer"); - glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); - CHECK_GL_ERROR("Failed to attach texture 2D array to read framebuffer"); - } - else - { - UNEXPECTED("Only one slice or the entire texture array can be attached to a framebuffer"); - } -} - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2D_GL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2D_GL.cpp new file mode 100644 index 00000000..e62876be --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/src/Texture2D_GL.cpp @@ -0,0 +1,286 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "Texture2D_GL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" +#include "BufferGLImpl.hpp" +#include "GLTypeConversions.hpp" +#include "GraphicsAccessories.hpp" + +namespace Diligent +{ + +Texture2D_GL::Texture2D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/, + bool bIsDeviceInternal /*= false*/) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + TexDesc, + static_cast(TexDesc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D), + pInitData, + bIsDeviceInternal + } +// clang-format on +{ + if (TexDesc.Usage == USAGE_STAGING) + { + // We will use PBO initialized by TextureBaseGL + return; + } + + GLState.BindTexture(-1, m_BindTarget, m_GlTexture); + + if (m_Desc.SampleCount > 1) + { +#if GL_ARB_texture_storage_multisample + // format width height depth + glTexStorage2DMultisample(m_BindTarget, m_Desc.SampleCount, m_GLTexFormat, m_Desc.Width, m_Desc.Height, GL_TRUE); + // The last parameter specifies whether the image will use identical sample locations and the same number of + // samples for all texels in the image, and the sample locations will not depend on the internal format or size + // of the image. + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 2D multisample texture"); + // * An INVALID_ENUM error is generated if sizedinternalformat is not colorrenderable, + // depth - renderable, or stencil - renderable + // * An INVALID_OPERATION error is generated if samples is greater than the maximum number of samples + // supported for this target and internalformat. The maximum number of samples supported can be + // determined by calling glGetInternalformativ with a pname of GL_SAMPLES + + SetDefaultGLParameters(); + + VERIFY(pInitData == nullptr || pInitData->pSubResources == nullptr, "Multisampled textures cannot be modified directly"); +#else + LOG_ERROR_AND_THROW("Multisampled textures are not supported"); +#endif + } + else + { + // levels format width height + glTexStorage2D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height); + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 2D texture"); + // When target is GL_TEXTURE_2D, calling glTexStorage2D is equivalent to the following pseudo-code: + //for (i = 0; i < levels; i++) + //{ + // glTexImage2D(target, i, internalformat, width, height, 0, format, type, NULL); + // width = max(1, (width / 2)); + // height = max(1, (height / 2)); + //} + + SetDefaultGLParameters(); + + if (pInitData != nullptr && pInitData->pSubResources != nullptr) + { + if (m_Desc.MipLevels == pInitData->NumSubresources) + { + for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) + { + Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), + 0, std::max(m_Desc.Height >> Mip, 1U)}; + // UpdateData() is a virtual function. If we try to call it through vtbl from here, + // we will get into TextureBaseGL::UpdateData(), because instance of Texture2D_GL + // is not fully constructed yet. + // To call the required function, we need to explicitly specify the class: + Texture2D_GL::UpdateData(GLState, Mip, 0, DstBox, pInitData->pSubResources[Mip]); + } + } + else + { + UNEXPECTED("Incorrect number of subresources"); + } + } + } + + GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +Texture2D_GL::Texture2D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + GLState, + TexDesc, + GLTextureHandle, + GLBindTarget != 0 ? + static_cast(GLBindTarget) : + static_cast(TexDesc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D), + bIsDeviceInternal + } +// clang-format on +{ +} + +Texture2D_GL::Texture2D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + const TextureDesc& TexDesc, + bool bIsDeviceInternal) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + TexDesc, + bIsDeviceInternal + } +// clang-format on +{ +} + + +Texture2D_GL::~Texture2D_GL() +{ +} + +void Texture2D_GL::UpdateData(GLContextState& ContextState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) +{ + TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); + + ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // Bind buffer if it is provided; copy from CPU memory otherwise + GLuint UnpackBuffer = 0; + if (SubresData.pSrcBuffer != nullptr) + { + auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); + UnpackBuffer = pBufferGL->GetGLHandle(); + } + + // Transfers to OpenGL memory are called unpack operations + // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer + // operations will be performed from this buffer. + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); + + const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + + if (TransferAttribs.IsCompressed) + { + auto MipWidth = std::max(m_Desc.Width >> MipLevel, 1U); + auto MipHeight = std::max(m_Desc.Height >> MipLevel, 1U); + VERIFY((DstBox.MinX % 4) == 0 && (DstBox.MinY % 4) == 0 && + ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) && + ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight), + "Compressed texture update region must be 4 pixel-aligned"); +#ifdef DILIGENT_DEBUG + { + const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format); + auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize}; + VERIFY(SubresData.Stride == BlockBytesInRow, + "Compressed data stride (", SubresData.Stride, " must match the size of a row of compressed blocks (", BlockBytesInRow, ")"); + } +#endif + + //glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + //glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 0); + auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; + auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; + UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - DstBox.MinX); + UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - DstBox.MinY); + glCompressedTexSubImage2D(m_BindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + UpdateRegionWidth, + UpdateRegionHeight, + // The format must be the same compressed-texture format previously + // specified by glTexStorage2D() (thank you OpenGL for another useless + // parameter that is nothing but the source of confusion), otherwise + // INVALID_OPERATION error is generated. + m_GLTexFormat, + // An INVALID_VALUE error is generated if imageSize is not consistent with + // the format, dimensions, and contents of the compressed image( too little or + // too much data ), + ((DstBox.MaxY - DstBox.MinY + 3) / 4) * SubresData.Stride, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage2D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + } + else + { + const auto& TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); + const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; + VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); + glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + + glTexSubImage2D(m_BindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + DstBox.MaxX - DstBox.MinX, + DstBox.MaxY - DstBox.MinY, + TransferAttribs.PixelFormat, TransferAttribs.DataType, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage2D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + } + CHECK_GL_ERROR("Failed to update subimage data"); + + if (UnpackBuffer != 0) + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + + ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +void Texture2D_GL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) +{ + // For glFramebufferTexture2D(), if texture name is not zero, then texture target must be GL_TEXTURE_2D, + // GL_TEXTURE_RECTANGLE or one of the 6 cubemap face targets GL_TEXTURE_CUBE_MAP_POSITIVE_X, ... + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 2D to draw framebuffer"); + glFramebufferTexture2D(GL_READ_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 2D to read framebuffer"); +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp deleted file mode 100644 index 7442bf5b..00000000 --- a/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" - -#include "Texture2D_OGL.hpp" -#include "RenderDeviceGLImpl.hpp" -#include "DeviceContextGLImpl.hpp" -#include "BufferGLImpl.hpp" -#include "GLTypeConversions.hpp" -#include "GraphicsAccessories.hpp" - -namespace Diligent -{ - -Texture2D_OGL::Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/, - bool bIsDeviceInternal /*= false*/) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - TexDesc, - static_cast(TexDesc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D), - pInitData, - bIsDeviceInternal - } -// clang-format on -{ - if (TexDesc.Usage == USAGE_STAGING) - { - // We will use PBO initialized by TextureBaseGL - return; - } - - GLState.BindTexture(-1, m_BindTarget, m_GlTexture); - - if (m_Desc.SampleCount > 1) - { -#if GL_ARB_texture_storage_multisample - // format width height depth - glTexStorage2DMultisample(m_BindTarget, m_Desc.SampleCount, m_GLTexFormat, m_Desc.Width, m_Desc.Height, GL_TRUE); - // The last parameter specifies whether the image will use identical sample locations and the same number of - // samples for all texels in the image, and the sample locations will not depend on the internal format or size - // of the image. - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 2D multisample texture"); - // * An INVALID_ENUM error is generated if sizedinternalformat is not colorrenderable, - // depth - renderable, or stencil - renderable - // * An INVALID_OPERATION error is generated if samples is greater than the maximum number of samples - // supported for this target and internalformat. The maximum number of samples supported can be - // determined by calling glGetInternalformativ with a pname of GL_SAMPLES - - SetDefaultGLParameters(); - - VERIFY(pInitData == nullptr || pInitData->pSubResources == nullptr, "Multisampled textures cannot be modified directly"); -#else - LOG_ERROR_AND_THROW("Multisampled textures are not supported"); -#endif - } - else - { - // levels format width height - glTexStorage2D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height); - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 2D texture"); - // When target is GL_TEXTURE_2D, calling glTexStorage2D is equivalent to the following pseudo-code: - //for (i = 0; i < levels; i++) - //{ - // glTexImage2D(target, i, internalformat, width, height, 0, format, type, NULL); - // width = max(1, (width / 2)); - // height = max(1, (height / 2)); - //} - - SetDefaultGLParameters(); - - if (pInitData != nullptr && pInitData->pSubResources != nullptr) - { - if (m_Desc.MipLevels == pInitData->NumSubresources) - { - for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) - { - Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), - 0, std::max(m_Desc.Height >> Mip, 1U)}; - // UpdateData() is a virtual function. If we try to call it through vtbl from here, - // we will get into TextureBaseGL::UpdateData(), because instance of Texture2D_OGL - // is not fully constructed yet. - // To call the required function, we need to explicitly specify the class: - Texture2D_OGL::UpdateData(GLState, Mip, 0, DstBox, pInitData->pSubResources[Mip]); - } - } - else - { - UNEXPECTED("Incorrect number of subresources"); - } - } - } - - GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -Texture2D_OGL::Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - GLState, - TexDesc, - GLTextureHandle, - GLBindTarget != 0 ? - static_cast(GLBindTarget) : - static_cast(TexDesc.SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D), - bIsDeviceInternal - } -// clang-format on -{ -} - -Texture2D_OGL::Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - const TextureDesc& TexDesc, - bool bIsDeviceInternal) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - TexDesc, - bIsDeviceInternal - } -// clang-format on -{ -} - - -Texture2D_OGL::~Texture2D_OGL() -{ -} - -void Texture2D_OGL::UpdateData(GLContextState& ContextState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) -{ - TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); - - ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // Bind buffer if it is provided; copy from CPU memory otherwise - GLuint UnpackBuffer = 0; - if (SubresData.pSrcBuffer != nullptr) - { - auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); - UnpackBuffer = pBufferGL->GetGLHandle(); - } - - // Transfers to OpenGL memory are called unpack operations - // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer - // operations will be performed from this buffer. - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); - - const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - - if (TransferAttribs.IsCompressed) - { - auto MipWidth = std::max(m_Desc.Width >> MipLevel, 1U); - auto MipHeight = std::max(m_Desc.Height >> MipLevel, 1U); - VERIFY((DstBox.MinX % 4) == 0 && (DstBox.MinY % 4) == 0 && - ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) && - ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight), - "Compressed texture update region must be 4 pixel-aligned"); -#ifdef DILIGENT_DEBUG - { - const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format); - auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize}; - VERIFY(SubresData.Stride == BlockBytesInRow, - "Compressed data stride (", SubresData.Stride, " must match the size of a row of compressed blocks (", BlockBytesInRow, ")"); - } -#endif - - //glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - //glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 0); - auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; - auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; - UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - DstBox.MinX); - UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - DstBox.MinY); - glCompressedTexSubImage2D(m_BindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - UpdateRegionWidth, - UpdateRegionHeight, - // The format must be the same compressed-texture format previously - // specified by glTexStorage2D() (thank you OpenGL for another useless - // parameter that is nothing but the source of confusion), otherwise - // INVALID_OPERATION error is generated. - m_GLTexFormat, - // An INVALID_VALUE error is generated if imageSize is not consistent with - // the format, dimensions, and contents of the compressed image( too little or - // too much data ), - ((DstBox.MaxY - DstBox.MinY + 3) / 4) * SubresData.Stride, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage2D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - } - else - { - const auto& TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); - const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; - VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); - glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - - glTexSubImage2D(m_BindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - DstBox.MaxX - DstBox.MinX, - DstBox.MaxY - DstBox.MinY, - TransferAttribs.PixelFormat, TransferAttribs.DataType, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage2D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - } - CHECK_GL_ERROR("Failed to update subimage data"); - - if (UnpackBuffer != 0) - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -void Texture2D_OGL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) -{ - // For glFramebufferTexture2D(), if texture name is not zero, then texture target must be GL_TEXTURE_2D, - // GL_TEXTURE_RECTANGLE or one of the 6 cubemap face targets GL_TEXTURE_CUBE_MAP_POSITIVE_X, ... - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 2D to draw framebuffer"); - glFramebufferTexture2D(GL_READ_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 2D to read framebuffer"); -} - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture3D_GL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture3D_GL.cpp new file mode 100644 index 00000000..e62932c0 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/src/Texture3D_GL.cpp @@ -0,0 +1,224 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "Texture3D_GL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" +#include "BufferGLImpl.hpp" +#include "GLTypeConversions.hpp" +#include "GraphicsAccessories.hpp" + +namespace Diligent +{ + +Texture3D_GL::Texture3D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= TextureData()*/, + bool bIsDeviceInternal /*= false*/) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + TexDesc, + GL_TEXTURE_3D, + pInitData, + bIsDeviceInternal + } +// clang-format on +{ + if (TexDesc.Usage == USAGE_STAGING) + { + // We will use PBO initialized by TextureBaseGL + return; + } + + GLState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // levels format width height depth + glTexStorage3D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.Depth); + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 3D texture"); + // When target is GL_TEXTURE_3D, calling glTexStorage3D is equivalent to the following pseudo-code: + //for (i = 0; i < levels; i++) + //{ + // glTexImage3D(target, i, internalformat, width, height, depth, 0, format, type, NULL); + // width = max(1, (width / 2)); + // height = max(1, (height / 2)); + // depth = max(1, (depth / 2)); + // + + SetDefaultGLParameters(); + + if (pInitData != nullptr && pInitData->pSubResources != nullptr) + { + if (m_Desc.MipLevels == pInitData->NumSubresources) + { + for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) + { + Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), + 0, std::max(m_Desc.Height >> Mip, 1U), + 0, std::max(m_Desc.Depth >> Mip, 1U)}; + // UpdateData() is a virtual function. If we try to call it through vtbl from here, + // we will get into TextureBaseGL::UpdateData(), because instance of Texture3D_GL + // is not fully constructed yet. + // To call the required function, we need to explicitly specify the class: + Texture3D_GL::UpdateData(GLState, Mip, 0, DstBox, pInitData->pSubResources[Mip]); + } + } + else + { + UNEXPECTED("Incorrect number of subresources"); + } + } + + GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +Texture3D_GL::Texture3D_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + GLState, + TexDesc, + GLTextureHandle, + static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_3D), + bIsDeviceInternal + } +// clang-format on +{ +} + +Texture3D_GL::~Texture3D_GL() +{ +} + + +void Texture3D_GL::UpdateData(GLContextState& ContextState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) +{ + TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); + + ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // Bind buffer if it is provided; copy from CPU memory otherwise + GLuint UnpackBuffer = 0; + if (SubresData.pSrcBuffer != nullptr) + { + auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); + UnpackBuffer = pBufferGL->GetGLHandle(); + } + + // Transfers to OpenGL memory are called unpack operations + // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer + // operations will be performed from this buffer. + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); + + const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0); + + const auto TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); + const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; + VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); + glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); + + VERIFY((SubresData.DepthStride % SubresData.Stride) == 0, "Depth stride is not multiple of stride"); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, SubresData.DepthStride / SubresData.Stride); + + glTexSubImage3D(m_BindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + DstBox.MinZ, + DstBox.MaxX - DstBox.MinX, + DstBox.MaxY - DstBox.MinY, + DstBox.MaxZ - DstBox.MinZ, + TransferAttribs.PixelFormat, TransferAttribs.DataType, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage3D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + + CHECK_GL_ERROR("Failed to update subimage data"); + + if (UnpackBuffer != 0) + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + + ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +void Texture3D_GL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) +{ + auto NumDepthSlicesInMip = m_Desc.Depth >> ViewDesc.MostDetailedMip; + if (ViewDesc.NumDepthSlices == NumDepthSlicesInMip) + { + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 3D to draw framebuffer"); + glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture 3D to read framebuffer"); + } + else if (ViewDesc.NumDepthSlices == 1) + { + // For glFramebufferTexture3D(), if texture name is not zero, then texture target must be GL_TEXTURE_3D + //glFramebufferTexture3D( GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstDepthSlice ); + //glFramebufferTexture3D( GL_READ_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstDepthSlice ); + + // On Android (at least on Intel HW), glFramebufferTexture3D() runs without errors, but the + // FBO turns out to be incomplete. glFramebufferTextureLayer() seems to work fine. + glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstDepthSlice); + CHECK_GL_ERROR("Failed to attach texture 3D to draw framebuffer"); + glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstDepthSlice); + CHECK_GL_ERROR("Failed to attach texture 3D to read framebuffer"); + } + else + { + UNEXPECTED("Only one slice or the entire 3D texture can be attached to a framebuffer"); + } +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp deleted file mode 100644 index 52717652..00000000 --- a/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" - -#include "Texture3D_OGL.hpp" -#include "RenderDeviceGLImpl.hpp" -#include "DeviceContextGLImpl.hpp" -#include "BufferGLImpl.hpp" -#include "GLTypeConversions.hpp" -#include "GraphicsAccessories.hpp" - -namespace Diligent -{ - -Texture3D_OGL::Texture3D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= TextureData()*/, - bool bIsDeviceInternal /*= false*/) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - TexDesc, - GL_TEXTURE_3D, - pInitData, - bIsDeviceInternal - } -// clang-format on -{ - if (TexDesc.Usage == USAGE_STAGING) - { - // We will use PBO initialized by TextureBaseGL - return; - } - - GLState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // levels format width height depth - glTexStorage3D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.Depth); - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the 3D texture"); - // When target is GL_TEXTURE_3D, calling glTexStorage3D is equivalent to the following pseudo-code: - //for (i = 0; i < levels; i++) - //{ - // glTexImage3D(target, i, internalformat, width, height, depth, 0, format, type, NULL); - // width = max(1, (width / 2)); - // height = max(1, (height / 2)); - // depth = max(1, (depth / 2)); - // - - SetDefaultGLParameters(); - - if (pInitData != nullptr && pInitData->pSubResources != nullptr) - { - if (m_Desc.MipLevels == pInitData->NumSubresources) - { - for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) - { - Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), - 0, std::max(m_Desc.Height >> Mip, 1U), - 0, std::max(m_Desc.Depth >> Mip, 1U)}; - // UpdateData() is a virtual function. If we try to call it through vtbl from here, - // we will get into TextureBaseGL::UpdateData(), because instance of Texture3D_OGL - // is not fully constructed yet. - // To call the required function, we need to explicitly specify the class: - Texture3D_OGL::UpdateData(GLState, Mip, 0, DstBox, pInitData->pSubResources[Mip]); - } - } - else - { - UNEXPECTED("Incorrect number of subresources"); - } - } - - GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -Texture3D_OGL::Texture3D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - GLState, - TexDesc, - GLTextureHandle, - static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_3D), - bIsDeviceInternal - } -// clang-format on -{ -} - -Texture3D_OGL::~Texture3D_OGL() -{ -} - - -void Texture3D_OGL::UpdateData(GLContextState& ContextState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) -{ - TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); - - ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // Bind buffer if it is provided; copy from CPU memory otherwise - GLuint UnpackBuffer = 0; - if (SubresData.pSrcBuffer != nullptr) - { - auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); - UnpackBuffer = pBufferGL->GetGLHandle(); - } - - // Transfers to OpenGL memory are called unpack operations - // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer - // operations will be performed from this buffer. - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); - - const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0); - - const auto TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); - const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; - VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); - glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); - - VERIFY((SubresData.DepthStride % SubresData.Stride) == 0, "Depth stride is not multiple of stride"); - glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, SubresData.DepthStride / SubresData.Stride); - - glTexSubImage3D(m_BindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - DstBox.MinZ, - DstBox.MaxX - DstBox.MinX, - DstBox.MaxY - DstBox.MinY, - DstBox.MaxZ - DstBox.MinZ, - TransferAttribs.PixelFormat, TransferAttribs.DataType, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage3D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - - CHECK_GL_ERROR("Failed to update subimage data"); - - if (UnpackBuffer != 0) - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -void Texture3D_OGL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) -{ - auto NumDepthSlicesInMip = m_Desc.Depth >> ViewDesc.MostDetailedMip; - if (ViewDesc.NumDepthSlices == NumDepthSlicesInMip) - { - glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 3D to draw framebuffer"); - glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture 3D to read framebuffer"); - } - else if (ViewDesc.NumDepthSlices == 1) - { - // For glFramebufferTexture3D(), if texture name is not zero, then texture target must be GL_TEXTURE_3D - //glFramebufferTexture3D( GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstDepthSlice ); - //glFramebufferTexture3D( GL_READ_FRAMEBUFFER, AttachmentPoint, m_BindTarget, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstDepthSlice ); - - // On Android (at least on Intel HW), glFramebufferTexture3D() runs without errors, but the - // FBO turns out to be incomplete. glFramebufferTextureLayer() seems to work fine. - glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstDepthSlice); - CHECK_GL_ERROR("Failed to attach texture 3D to draw framebuffer"); - glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstDepthSlice); - CHECK_GL_ERROR("Failed to attach texture 3D to read framebuffer"); - } - else - { - UNEXPECTED("Only one slice or the entire 3D texture can be attached to a framebuffer"); - } -} - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_GL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_GL.cpp new file mode 100644 index 00000000..840d1ab5 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_GL.cpp @@ -0,0 +1,288 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "TextureCubeArray_GL.hpp" + +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" +#include "BufferGLImpl.hpp" + +#include "GLTypeConversions.hpp" +#include "GraphicsAccessories.hpp" + + +namespace Diligent +{ + +TextureCubeArray_GL::TextureCubeArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/, + bool bIsDeviceInternal /*= false*/) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + TexDesc, + GL_TEXTURE_CUBE_MAP_ARRAY, + pInitData, + bIsDeviceInternal + } +// clang-format on +{ + if (TexDesc.Usage == USAGE_STAGING) + { + // We will use PBO initialized by TextureBaseGL + return; + } + + VERIFY(m_Desc.SampleCount == 1, "Multisampled texture cube arrays are not supported"); + + GLState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. + // For example, when you allocate storage for the texture, you would use glTexStorage3D? or glTexImage3D? or similar. + // The depth? parameter will be the number of layer-faces, not layers. So it must be divisible by 6. + VERIFY((m_Desc.ArraySize % 6) == 0, "Array size must be multiple of 6"); + // levels format width height depth + glTexStorage3D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.ArraySize); + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the Cubemap texture array"); + //When target is GL_TEXTURE_CUBE_MAP_ARRAY glTexStorage3D is equivalent to: + // + //for (i = 0; i < levels; i++) { + // glTexImage3D(target, i, internalformat, width, height, depth, 0, format, type, NULL); + // width = max(1, (width / 2)); + // height = max(1, (height / 2)); + //} + + SetDefaultGLParameters(); + + if (pInitData != nullptr && pInitData->pSubResources != nullptr) + { + VERIFY((m_Desc.ArraySize % 6) == 0, "Array size must be multiple of 6"); + if (m_Desc.MipLevels * m_Desc.ArraySize == pInitData->NumSubresources) + { + for (Uint32 Slice = 0; Slice < m_Desc.ArraySize; ++Slice) + { + for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) + { + Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), + 0, std::max(m_Desc.Height >> Mip, 1U)}; + // UpdateData() is a virtual function. If we try to call it through vtbl from here, + // we will get into TextureBaseGL::UpdateData(), because instance of TextureCubeArray_GL + // is not fully constructed yet. + // To call the required function, we need to explicitly specify the class: + TextureCubeArray_GL::UpdateData(GLState, Mip, Slice, DstBox, pInitData->pSubResources[Slice * m_Desc.MipLevels + Mip]); + } + } + } + else + { + UNEXPECTED("Incorrect number of subresources"); + } + } + + GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +TextureCubeArray_GL::TextureCubeArray_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + GLState, + TexDesc, + GLTextureHandle, + static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_CUBE_MAP_ARRAY), + bIsDeviceInternal + } +// clang-format on +{ +} + +TextureCubeArray_GL::~TextureCubeArray_GL() +{ +} + +void TextureCubeArray_GL::UpdateData(GLContextState& ContextState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) +{ + TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); + + ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); + + // Bind buffer if it is provided; copy from CPU memory otherwise + GLuint UnpackBuffer = 0; + if (SubresData.pSrcBuffer != nullptr) + { + auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); + UnpackBuffer = pBufferGL->GetGLHandle(); + } + + // Transfers to OpenGL memory are called unpack operations + // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer + // operations will be performed from this buffer. + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); + + const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + + if (TransferAttribs.IsCompressed) + { + auto MipWidth = std::max(m_Desc.Width >> MipLevel, 1U); + auto MipHeight = std::max(m_Desc.Height >> MipLevel, 1U); + // clang-format off + VERIFY((DstBox.MinX % 4) == 0 && (DstBox.MinY % 4) == 0 && + ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) && + ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight), + "Compressed texture update region must be 4 pixel-aligned"); + // clang-format on +#ifdef DILIGENT_DEBUG + { + const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format); + auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize}; + VERIFY(SubresData.Stride == BlockBytesInRow, + "Compressed data stride (", SubresData.Stride, " must match the size of a row of compressed blocks (", BlockBytesInRow, ")"); + } +#endif + + // Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. + + //glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + //glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 0); + auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; + auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; + UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - DstBox.MinX); + UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - DstBox.MinY); + glCompressedTexSubImage3D(m_BindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + Slice, + UpdateRegionWidth, + UpdateRegionHeight, + 1, + // The format must be the same compressed-texture format previously + // specified by glTexStorage2D() (thank you OpenGL for another useless + // parameter that is nothing but the source of confusion), otherwise + // INVALID_OPERATION error is generated. + m_GLTexFormat, + // An INVALID_VALUE error is generated if imageSize is not consistent with + // the format, dimensions, and contents of the compressed image( too little or + // too much data ), + ((DstBox.MaxY - DstBox.MinY + 3) / 4) * SubresData.Stride, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage3D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + } + else + { + const auto TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); + const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; + VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); + glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + + // Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. + // When uploading texel data to the cubemap array, the parameters that represent the Z component + // are layer-faces. So if you want to upload to just the positive Z face of the second layer in the array, + // you would use call glTexSubImage3D?, with the zoffset?? parameter set to 10 (layer 1 * 6 faces per layer + face index 4), + // and the depth? set to 1 (because you're only uploading one layer-face). + + // Target must be GL_TEXTURE_3D, GL_TEXTURE_2D_ARRAY, or GL_TEXTURE_CUBE_MAP_ARRAY. + // (NO individual cubemap faces GL_TEXTURE_CUBE_MAP_POSITIVE_X .. GL_TEXTURE_CUBE_MAP_NEGATIVE_Z!!!) + glTexSubImage3D(m_BindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + Slice, + DstBox.MaxX - DstBox.MinX, + DstBox.MaxY - DstBox.MinY, + 1, + TransferAttribs.PixelFormat, TransferAttribs.DataType, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage3D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + } + CHECK_GL_ERROR("Failed to update subimage data"); + + if (UnpackBuffer != 0) + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + + ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +void TextureCubeArray_GL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) +{ + // Same as for 2D array textures + + // Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. + // So the parameters that represent the Z component are layer-faces. + if (ViewDesc.NumArraySlices == m_Desc.ArraySize) + { + // glFramebufferTexture() attaches the given mipmap levelas a layered image with the number of layers that the given texture has. + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture cubemap array to draw framebuffer"); + glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture cubemap array to read framebuffer"); + } + else if (ViewDesc.NumArraySlices == 1) + { + // Texture name must either be zero or the name of an existing 3D texture, 1D or 2D array texture, + // cube map array texture, or multisample array texture. + glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); + CHECK_GL_ERROR("Failed to attach texture cubemap array to draw framebuffer"); + glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); + CHECK_GL_ERROR("Failed to attach texture cubemap array to read framebuffer"); + } + else + { + UNEXPECTED("Only one slice or the entire cubemap array can be attached to a framebuffer"); + } +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp deleted file mode 100644 index 443cb792..00000000 --- a/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" - -#include "TextureCubeArray_OGL.hpp" - -#include "RenderDeviceGLImpl.hpp" -#include "DeviceContextGLImpl.hpp" -#include "BufferGLImpl.hpp" - -#include "GLTypeConversions.hpp" -#include "GraphicsAccessories.hpp" - - -namespace Diligent -{ - -TextureCubeArray_OGL::TextureCubeArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/, - bool bIsDeviceInternal /*= false*/) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - TexDesc, - GL_TEXTURE_CUBE_MAP_ARRAY, - pInitData, - bIsDeviceInternal - } -// clang-format on -{ - if (TexDesc.Usage == USAGE_STAGING) - { - // We will use PBO initialized by TextureBaseGL - return; - } - - VERIFY(m_Desc.SampleCount == 1, "Multisampled texture cube arrays are not supported"); - - GLState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. - // For example, when you allocate storage for the texture, you would use glTexStorage3D? or glTexImage3D? or similar. - // The depth? parameter will be the number of layer-faces, not layers. So it must be divisible by 6. - VERIFY((m_Desc.ArraySize % 6) == 0, "Array size must be multiple of 6"); - // levels format width height depth - glTexStorage3D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.ArraySize); - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the Cubemap texture array"); - //When target is GL_TEXTURE_CUBE_MAP_ARRAY glTexStorage3D is equivalent to: - // - //for (i = 0; i < levels; i++) { - // glTexImage3D(target, i, internalformat, width, height, depth, 0, format, type, NULL); - // width = max(1, (width / 2)); - // height = max(1, (height / 2)); - //} - - SetDefaultGLParameters(); - - if (pInitData != nullptr && pInitData->pSubResources != nullptr) - { - VERIFY((m_Desc.ArraySize % 6) == 0, "Array size must be multiple of 6"); - if (m_Desc.MipLevels * m_Desc.ArraySize == pInitData->NumSubresources) - { - for (Uint32 Slice = 0; Slice < m_Desc.ArraySize; ++Slice) - { - for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) - { - Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), - 0, std::max(m_Desc.Height >> Mip, 1U)}; - // UpdateData() is a virtual function. If we try to call it through vtbl from here, - // we will get into TextureBaseGL::UpdateData(), because instance of TextureCubeArray_OGL - // is not fully constructed yet. - // To call the required function, we need to explicitly specify the class: - TextureCubeArray_OGL::UpdateData(GLState, Mip, Slice, DstBox, pInitData->pSubResources[Slice * m_Desc.MipLevels + Mip]); - } - } - } - else - { - UNEXPECTED("Incorrect number of subresources"); - } - } - - GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -TextureCubeArray_OGL::TextureCubeArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - GLState, - TexDesc, - GLTextureHandle, - static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_CUBE_MAP_ARRAY), - bIsDeviceInternal - } -// clang-format on -{ -} - -TextureCubeArray_OGL::~TextureCubeArray_OGL() -{ -} - -void TextureCubeArray_OGL::UpdateData(GLContextState& ContextState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) -{ - TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); - - ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); - - // Bind buffer if it is provided; copy from CPU memory otherwise - GLuint UnpackBuffer = 0; - if (SubresData.pSrcBuffer != nullptr) - { - auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); - UnpackBuffer = pBufferGL->GetGLHandle(); - } - - // Transfers to OpenGL memory are called unpack operations - // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer - // operations will be performed from this buffer. - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); - - const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - - if (TransferAttribs.IsCompressed) - { - auto MipWidth = std::max(m_Desc.Width >> MipLevel, 1U); - auto MipHeight = std::max(m_Desc.Height >> MipLevel, 1U); - // clang-format off - VERIFY((DstBox.MinX % 4) == 0 && (DstBox.MinY % 4) == 0 && - ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) && - ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight), - "Compressed texture update region must be 4 pixel-aligned"); - // clang-format on -#ifdef DILIGENT_DEBUG - { - const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format); - auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize}; - VERIFY(SubresData.Stride == BlockBytesInRow, - "Compressed data stride (", SubresData.Stride, " must match the size of a row of compressed blocks (", BlockBytesInRow, ")"); - } -#endif - - // Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. - - //glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - //glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 0); - auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; - auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; - UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - DstBox.MinX); - UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - DstBox.MinY); - glCompressedTexSubImage3D(m_BindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - Slice, - UpdateRegionWidth, - UpdateRegionHeight, - 1, - // The format must be the same compressed-texture format previously - // specified by glTexStorage2D() (thank you OpenGL for another useless - // parameter that is nothing but the source of confusion), otherwise - // INVALID_OPERATION error is generated. - m_GLTexFormat, - // An INVALID_VALUE error is generated if imageSize is not consistent with - // the format, dimensions, and contents of the compressed image( too little or - // too much data ), - ((DstBox.MaxY - DstBox.MinY + 3) / 4) * SubresData.Stride, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage3D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - } - else - { - const auto TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); - const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; - VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); - glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - - // Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. - // When uploading texel data to the cubemap array, the parameters that represent the Z component - // are layer-faces. So if you want to upload to just the positive Z face of the second layer in the array, - // you would use call glTexSubImage3D?, with the zoffset?? parameter set to 10 (layer 1 * 6 faces per layer + face index 4), - // and the depth? set to 1 (because you're only uploading one layer-face). - - // Target must be GL_TEXTURE_3D, GL_TEXTURE_2D_ARRAY, or GL_TEXTURE_CUBE_MAP_ARRAY. - // (NO individual cubemap faces GL_TEXTURE_CUBE_MAP_POSITIVE_X .. GL_TEXTURE_CUBE_MAP_NEGATIVE_Z!!!) - glTexSubImage3D(m_BindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - Slice, - DstBox.MaxX - DstBox.MinX, - DstBox.MaxY - DstBox.MinY, - 1, - TransferAttribs.PixelFormat, TransferAttribs.DataType, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage3D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - } - CHECK_GL_ERROR("Failed to update subimage data"); - - if (UnpackBuffer != 0) - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -void TextureCubeArray_OGL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) -{ - // Same as for 2D array textures - - // Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. - // So the parameters that represent the Z component are layer-faces. - if (ViewDesc.NumArraySlices == m_Desc.ArraySize) - { - // glFramebufferTexture() attaches the given mipmap levelas a layered image with the number of layers that the given texture has. - glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture cubemap array to draw framebuffer"); - glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture cubemap array to read framebuffer"); - } - else if (ViewDesc.NumArraySlices == 1) - { - // Texture name must either be zero or the name of an existing 3D texture, 1D or 2D array texture, - // cube map array texture, or multisample array texture. - glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); - CHECK_GL_ERROR("Failed to attach texture cubemap array to draw framebuffer"); - glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip, ViewDesc.FirstArraySlice); - CHECK_GL_ERROR("Failed to attach texture cubemap array to read framebuffer"); - } - else - { - UNEXPECTED("Only one slice or the entire cubemap array can be attached to a framebuffer"); - } -} - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureCube_GL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureCube_GL.cpp new file mode 100644 index 00000000..0f542b56 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/src/TextureCube_GL.cpp @@ -0,0 +1,296 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "TextureCube_GL.hpp" + +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" +#include "BufferGLImpl.hpp" + +#include "GLTypeConversions.hpp" +#include "GraphicsAccessories.hpp" + +namespace Diligent +{ + +TextureCube_GL::TextureCube_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/, + bool bIsDeviceInternal /*= false*/) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + TexDesc, + GL_TEXTURE_CUBE_MAP, + pInitData, + bIsDeviceInternal + } +// clang-format on +{ + if (TexDesc.Usage == USAGE_STAGING) + { + // We will use PBO initialized by TextureBaseGL + return; + } + + VERIFY(m_Desc.SampleCount == 1, "Multisampled cubemap textures are not supported"); + + GLState.BindTexture(-1, m_BindTarget, m_GlTexture); + + VERIFY(m_Desc.ArraySize == 6, "Cubemap texture is expected to have 6 slices"); + // levels format width height + glTexStorage2D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height); + CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the Cubemap texture"); + //When target is GL_TEXTURE_CUBE_MAP, glTexStorage2D is equivalent to: + // + //for (i = 0; i < levels; i++) { + // for (face in (+X, -X, +Y, -Y, +Z, -Z)) { + // glTexImage2D(face, i, internalformat, width, height, 0, format, type, NULL); + // } + // width = max(1, (width / 2)); + // height = max(1, (height / 2)); + //} + SetDefaultGLParameters(); + + if (pInitData != nullptr && pInitData->pSubResources != nullptr) + { + const auto ExpectedSubresources = m_Desc.MipLevels * 6; + if (m_Desc.MipLevels * 6 == pInitData->NumSubresources) + { + for (Uint32 Face = 0; Face < 6; ++Face) + { + for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) + { + Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), + 0, std::max(m_Desc.Height >> Mip, 1U)}; + // UpdateData() is a virtual function. If we try to call it through vtbl from here, + // we will get into TextureBaseGL::UpdateData(), because instance of TextureCube_GL + // is not fully constructed yet. + // To call the required function, we need to explicitly specify the class: + TextureCube_GL::UpdateData(GLState, Mip, Face, DstBox, pInitData->pSubResources[Face * m_Desc.MipLevels + Mip]); + } + } + } + else + { + UNEXPECTED("Incorrect number of subresources. ", pInitData->NumSubresources, " while ", ExpectedSubresources, " is expected"); + (void)ExpectedSubresources; + } + } + + GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +TextureCube_GL::TextureCube_GL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLuint GLBindTarget, + bool bIsDeviceInternal) : + // clang-format off + TextureBaseGL + { + pRefCounters, + TexViewObjAllocator, + pDeviceGL, + GLState, + TexDesc, + GLTextureHandle, + static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_CUBE_MAP), + bIsDeviceInternal + } +// clang-format on +{ +} + +TextureCube_GL::~TextureCube_GL() +{ +} + +// Move static member initialization out of function to avoid +// potential issues in multithreaded code +// clang-format off +static constexpr GLenum CubeMapFaces[6] = +{ + GL_TEXTURE_CUBE_MAP_POSITIVE_X, + GL_TEXTURE_CUBE_MAP_NEGATIVE_X, + GL_TEXTURE_CUBE_MAP_POSITIVE_Y, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, + GL_TEXTURE_CUBE_MAP_POSITIVE_Z, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z +}; +// clang-format on + +void TextureCube_GL::UpdateData(GLContextState& ContextState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) +{ + TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); + + // Texture must be bound as GL_TEXTURE_CUBE_MAP, but glTexSubImage2D() + // then takes one of GL_TEXTURE_CUBE_MAP_POSITIVE_X ... GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); + + auto CubeMapFaceBindTarget = CubeMapFaces[Slice]; + + // Bind buffer if it is provided; copy from CPU memory otherwise + GLuint UnpackBuffer = 0; + if (SubresData.pSrcBuffer != nullptr) + { + auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); + UnpackBuffer = pBufferGL->GetGLHandle(); + } + + // Transfers to OpenGL memory are called unpack operations + // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer + // operations will be performed from this buffer. + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); + + const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + + if (TransferAttribs.IsCompressed) + { + auto MipWidth = std::max(m_Desc.Width >> MipLevel, 1U); + auto MipHeight = std::max(m_Desc.Height >> MipLevel, 1U); + // clang-format off + VERIFY((DstBox.MinX % 4) == 0 && (DstBox.MinY % 4) == 0 && + ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) && + ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight), + "Compressed texture update region must be 4 pixel-aligned" ); + // clang-format on +#ifdef DILIGENT_DEBUG + { + const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format); + auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize}; + VERIFY(SubresData.Stride == BlockBytesInRow, + "Compressed data stride (", SubresData.Stride, " must match the size of a row of compressed blocks (", BlockBytesInRow, ")"); + } +#endif + + //glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + //glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 0); + + // Texture must be bound as GL_TEXTURE_CUBE_MAP, but glCompressedTexSubImage2D() + // takes one of GL_TEXTURE_CUBE_MAP_POSITIVE_X ... GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; + auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; + UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - DstBox.MinX); + UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - DstBox.MinY); + glCompressedTexSubImage2D(CubeMapFaceBindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + UpdateRegionWidth, + UpdateRegionHeight, + // The format must be the same compressed-texture format previously + // specified by glTexStorage2D() (thank you OpenGL for another useless + // parameter that is nothing but the source of confusion), otherwise + // INVALID_OPERATION error is generated. + m_GLTexFormat, + // An INVALID_VALUE error is generated if imageSize is not consistent with + // the format, dimensions, and contents of the compressed image( too little or + // too much data ), + ((DstBox.MaxY - DstBox.MinY + 3) / 4) * SubresData.Stride, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage2D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + } + else + { + const auto& TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); + const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; + VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); + glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + + // Texture must be bound as GL_TEXTURE_CUBE_MAP, but glTexSubImage2D() + // takes one of GL_TEXTURE_CUBE_MAP_POSITIVE_X ... GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + glTexSubImage2D(CubeMapFaceBindTarget, MipLevel, + DstBox.MinX, + DstBox.MinY, + DstBox.MaxX - DstBox.MinX, + DstBox.MaxY - DstBox.MinY, + TransferAttribs.PixelFormat, TransferAttribs.DataType, + // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated + // as a byte offset into the buffer object's data store. + // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage2D.xhtml + SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); + } + CHECK_GL_ERROR("Failed to update subimage data"); + + if (UnpackBuffer != 0) + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + + ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); +} + +void TextureCube_GL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) +{ + if (ViewDesc.NumArraySlices == m_Desc.ArraySize) + { + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture cube to draw framebuffer"); + glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture cube to read framebuffer"); + } + else if (ViewDesc.NumArraySlices == 1) + { + // Texture name must either be zero or the name of an existing 3D texture, 1D or 2D array texture, + // cube map array texture, or multisample array texture. + + auto CubeMapFaceBindTarget = CubeMapFaces[ViewDesc.FirstArraySlice]; + // For glFramebufferTexture2D, if texture is not zero, textarget must be one of GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, + // GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, + // GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, + // or GL_TEXTURE_2D_MULTISAMPLE. + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, AttachmentPoint, CubeMapFaceBindTarget, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture cube face to draw framebuffer"); + glFramebufferTexture2D(GL_READ_FRAMEBUFFER, AttachmentPoint, CubeMapFaceBindTarget, m_GlTexture, ViewDesc.MostDetailedMip); + CHECK_GL_ERROR("Failed to attach texture cube face to read framebuffer"); + } + else + { + UNEXPECTED("Only one slice or the entire cubemap can be attached to a framebuffer"); + } +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp deleted file mode 100644 index 4caafac2..00000000 --- a/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" - -#include "TextureCube_OGL.hpp" - -#include "RenderDeviceGLImpl.hpp" -#include "DeviceContextGLImpl.hpp" -#include "BufferGLImpl.hpp" - -#include "GLTypeConversions.hpp" -#include "GraphicsAccessories.hpp" - -namespace Diligent -{ - -TextureCube_OGL::TextureCube_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/, - bool bIsDeviceInternal /*= false*/) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - TexDesc, - GL_TEXTURE_CUBE_MAP, - pInitData, - bIsDeviceInternal - } -// clang-format on -{ - if (TexDesc.Usage == USAGE_STAGING) - { - // We will use PBO initialized by TextureBaseGL - return; - } - - VERIFY(m_Desc.SampleCount == 1, "Multisampled cubemap textures are not supported"); - - GLState.BindTexture(-1, m_BindTarget, m_GlTexture); - - VERIFY(m_Desc.ArraySize == 6, "Cubemap texture is expected to have 6 slices"); - // levels format width height - glTexStorage2D(m_BindTarget, m_Desc.MipLevels, m_GLTexFormat, m_Desc.Width, m_Desc.Height); - CHECK_GL_ERROR_AND_THROW("Failed to allocate storage for the Cubemap texture"); - //When target is GL_TEXTURE_CUBE_MAP, glTexStorage2D is equivalent to: - // - //for (i = 0; i < levels; i++) { - // for (face in (+X, -X, +Y, -Y, +Z, -Z)) { - // glTexImage2D(face, i, internalformat, width, height, 0, format, type, NULL); - // } - // width = max(1, (width / 2)); - // height = max(1, (height / 2)); - //} - SetDefaultGLParameters(); - - if (pInitData != nullptr && pInitData->pSubResources != nullptr) - { - const auto ExpectedSubresources = m_Desc.MipLevels * 6; - if (m_Desc.MipLevels * 6 == pInitData->NumSubresources) - { - for (Uint32 Face = 0; Face < 6; ++Face) - { - for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip) - { - Box DstBox{0, std::max(m_Desc.Width >> Mip, 1U), - 0, std::max(m_Desc.Height >> Mip, 1U)}; - // UpdateData() is a virtual function. If we try to call it through vtbl from here, - // we will get into TextureBaseGL::UpdateData(), because instance of TextureCube_OGL - // is not fully constructed yet. - // To call the required function, we need to explicitly specify the class: - TextureCube_OGL::UpdateData(GLState, Mip, Face, DstBox, pInitData->pSubResources[Face * m_Desc.MipLevels + Mip]); - } - } - } - else - { - UNEXPECTED("Incorrect number of subresources. ", pInitData->NumSubresources, " while ", ExpectedSubresources, " is expected"); - (void)ExpectedSubresources; - } - } - - GLState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -TextureCube_OGL::TextureCube_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLuint GLBindTarget, - bool bIsDeviceInternal) : - // clang-format off - TextureBaseGL - { - pRefCounters, - TexViewObjAllocator, - pDeviceGL, - GLState, - TexDesc, - GLTextureHandle, - static_cast(GLBindTarget != 0 ? GLBindTarget : GL_TEXTURE_CUBE_MAP), - bIsDeviceInternal - } -// clang-format on -{ -} - -TextureCube_OGL::~TextureCube_OGL() -{ -} - -// Move static member initialization out of function to avoid -// potential issues in multithreaded code -// clang-format off -static constexpr GLenum CubeMapFaces[6] = -{ - GL_TEXTURE_CUBE_MAP_POSITIVE_X, - GL_TEXTURE_CUBE_MAP_NEGATIVE_X, - GL_TEXTURE_CUBE_MAP_POSITIVE_Y, - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, - GL_TEXTURE_CUBE_MAP_POSITIVE_Z, - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z -}; -// clang-format on - -void TextureCube_OGL::UpdateData(GLContextState& ContextState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) -{ - TextureBaseGL::UpdateData(ContextState, MipLevel, Slice, DstBox, SubresData); - - // Texture must be bound as GL_TEXTURE_CUBE_MAP, but glTexSubImage2D() - // then takes one of GL_TEXTURE_CUBE_MAP_POSITIVE_X ... GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - ContextState.BindTexture(-1, m_BindTarget, m_GlTexture); - - auto CubeMapFaceBindTarget = CubeMapFaces[Slice]; - - // Bind buffer if it is provided; copy from CPU memory otherwise - GLuint UnpackBuffer = 0; - if (SubresData.pSrcBuffer != nullptr) - { - auto* pBufferGL = ValidatedCast(SubresData.pSrcBuffer); - UnpackBuffer = pBufferGL->GetGLHandle(); - } - - // Transfers to OpenGL memory are called unpack operations - // If there is a buffer bound to GL_PIXEL_UNPACK_BUFFER target, then all the pixel transfer - // operations will be performed from this buffer. - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, UnpackBuffer); - - const auto& TransferAttribs = GetNativePixelTransferAttribs(m_Desc.Format); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - - if (TransferAttribs.IsCompressed) - { - auto MipWidth = std::max(m_Desc.Width >> MipLevel, 1U); - auto MipHeight = std::max(m_Desc.Height >> MipLevel, 1U); - // clang-format off - VERIFY((DstBox.MinX % 4) == 0 && (DstBox.MinY % 4) == 0 && - ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) && - ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight), - "Compressed texture update region must be 4 pixel-aligned" ); - // clang-format on -#ifdef DILIGENT_DEBUG - { - const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format); - auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize}; - VERIFY(SubresData.Stride == BlockBytesInRow, - "Compressed data stride (", SubresData.Stride, " must match the size of a row of compressed blocks (", BlockBytesInRow, ")"); - } -#endif - - //glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - //glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 0); - - // Texture must be bound as GL_TEXTURE_CUBE_MAP, but glCompressedTexSubImage2D() - // takes one of GL_TEXTURE_CUBE_MAP_POSITIVE_X ... GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - auto UpdateRegionWidth = DstBox.MaxX - DstBox.MinX; - auto UpdateRegionHeight = DstBox.MaxY - DstBox.MinY; - UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - DstBox.MinX); - UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - DstBox.MinY); - glCompressedTexSubImage2D(CubeMapFaceBindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - UpdateRegionWidth, - UpdateRegionHeight, - // The format must be the same compressed-texture format previously - // specified by glTexStorage2D() (thank you OpenGL for another useless - // parameter that is nothing but the source of confusion), otherwise - // INVALID_OPERATION error is generated. - m_GLTexFormat, - // An INVALID_VALUE error is generated if imageSize is not consistent with - // the format, dimensions, and contents of the compressed image( too little or - // too much data ), - ((DstBox.MaxY - DstBox.MinY + 3) / 4) * SubresData.Stride, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage2D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - } - else - { - const auto& TexFmtInfo = GetTextureFormatAttribs(m_Desc.Format); - const auto PixelSize = Uint32{TexFmtInfo.NumComponents} * Uint32{TexFmtInfo.ComponentSize}; - VERIFY((SubresData.Stride % PixelSize) == 0, "Data stride is not multiple of pixel size"); - glPixelStorei(GL_UNPACK_ROW_LENGTH, SubresData.Stride / PixelSize); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - - // Texture must be bound as GL_TEXTURE_CUBE_MAP, but glTexSubImage2D() - // takes one of GL_TEXTURE_CUBE_MAP_POSITIVE_X ... GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - glTexSubImage2D(CubeMapFaceBindTarget, MipLevel, - DstBox.MinX, - DstBox.MinY, - DstBox.MaxX - DstBox.MinX, - DstBox.MaxY - DstBox.MinY, - TransferAttribs.PixelFormat, TransferAttribs.DataType, - // If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, 'data' is treated - // as a byte offset into the buffer object's data store. - // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexSubImage2D.xhtml - SubresData.pSrcBuffer != nullptr ? reinterpret_cast(static_cast(SubresData.SrcOffset)) : SubresData.pData); - } - CHECK_GL_ERROR("Failed to update subimage data"); - - if (UnpackBuffer != 0) - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - - ContextState.BindTexture(-1, m_BindTarget, GLObjectWrappers::GLTextureObj::Null()); -} - -void TextureCube_OGL::AttachToFramebuffer(const TextureViewDesc& ViewDesc, GLenum AttachmentPoint) -{ - if (ViewDesc.NumArraySlices == m_Desc.ArraySize) - { - glFramebufferTexture(GL_DRAW_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture cube to draw framebuffer"); - glFramebufferTexture(GL_READ_FRAMEBUFFER, AttachmentPoint, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture cube to read framebuffer"); - } - else if (ViewDesc.NumArraySlices == 1) - { - // Texture name must either be zero or the name of an existing 3D texture, 1D or 2D array texture, - // cube map array texture, or multisample array texture. - - auto CubeMapFaceBindTarget = CubeMapFaces[ViewDesc.FirstArraySlice]; - // For glFramebufferTexture2D, if texture is not zero, textarget must be one of GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, - // GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, - // GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, - // or GL_TEXTURE_2D_MULTISAMPLE. - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, AttachmentPoint, CubeMapFaceBindTarget, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture cube face to draw framebuffer"); - glFramebufferTexture2D(GL_READ_FRAMEBUFFER, AttachmentPoint, CubeMapFaceBindTarget, m_GlTexture, ViewDesc.MostDetailedMip); - CHECK_GL_ERROR("Failed to attach texture cube face to read framebuffer"); - } - else - { - UNEXPECTED("Only one slice or the entire cubemap can be attached to a framebuffer"); - } -} - -} // namespace Diligent -- cgit v1.2.3