Skip to content

Commit

Permalink
Reworked texture copying in OpenGL (close #438)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 28, 2023
1 parent 221bfe5 commit a517455
Show file tree
Hide file tree
Showing 29 changed files with 321 additions and 470 deletions.
2 changes: 0 additions & 2 deletions Graphics/GraphicsEngineOpenGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ set(INCLUDE
include/ShaderResourcesGL.hpp
include/ShaderVariableManagerGL.hpp
include/SwapChainGLBase.hpp
include/TexRegionRender.hpp
include/Texture1D_GL.hpp
include/Texture1DArray_GL.hpp
include/Texture2D_GL.hpp
Expand Down Expand Up @@ -87,7 +86,6 @@ set(SOURCE
src/ShaderResourceCacheGL.cpp
src/ShaderResourcesGL.cpp
src/ShaderVariableManagerGL.cpp
src/TexRegionRender.cpp
src/Texture1D_GL.cpp
src/Texture1DArray_GL.cpp
src/Texture2D_GL.cpp
Expand Down
7 changes: 6 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/GLStubsAndroid.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -1287,6 +1287,11 @@ extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture;
typedef void (GL_APIENTRY* PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
extern PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;

// not supported
#define LOAD_GL_COPY_TEX_SUBIMAGE_1D
typedef void (GL_APIENTRY* PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
extern PFNGLCOPYTEXSUBIMAGE1DEXTPROC glCopyTexSubImage1D;

// GL_OES_texture_3D
#define LOAD_GL_FRAMEBUFFER_TEXTURE_3D
typedef void (GL_APIENTRY* PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer);
Expand Down
3 changes: 2 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/GLStubsEmscripten.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -684,6 +684,7 @@ static void (*glPolygonMode)(GLenum face, GLenum mode) = nullptr;
#define glColorMaski(...) UnsupportedGLFunctionStub("glColorMaski", __VA_ARGS__)
#define glFramebufferTexture(...) UnsupportedGLFunctionStub("glFramebufferTexture", __VA_ARGS__)
#define glFramebufferTexture1D(...) UnsupportedGLFunctionStub("glFramebufferTexture1D", __VA_ARGS__)
#define glCopyTexSubImage1D(...) UnsupportedGLFunctionStub("glCopyTexSubImage1D", __VA_ARGS__)
static void (*glGetQueryObjectui64v)(GLuint id, GLenum pname, GLuint64* params) = nullptr;
#define glGenProgramPipelines(...) UnsupportedGLFunctionStub("glGenProgramPipelines", __VA_ARGS__)
#define glBindProgramPipeline(...) UnsupportedGLFunctionStub("glBindProgramPipeline", __VA_ARGS__)
Expand Down
1 change: 1 addition & 0 deletions Graphics/GraphicsEngineOpenGL/include/GLStubsIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ static void (*glPolygonMode)(GLenum face, GLenum mode) = nullptr;
#define glColorMaski(...) UnsupportedGLFunctionStub("glColorMaski")
#define glFramebufferTexture(...) UnsupportedGLFunctionStub("glFramebufferTexture")
#define glFramebufferTexture1D(...) UnsupportedGLFunctionStub("glFramebufferTexture1D")
#define glCopyTexSubImage1D(...) UnsupportedGLFunctionStub("glCopyTexSubImage1D")
#define glClipControl(...) UnsupportedGLFunctionStub("glClipControl")
static void (*glGetQueryObjectui64v)(GLuint id, GLenum pname, GLuint64* params) = nullptr;

Expand Down
23 changes: 22 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -27,6 +27,8 @@

#pragma once

#include <array>

namespace Diligent
{

Expand Down Expand Up @@ -453,4 +455,23 @@ ShaderCodeVariableDesc GLDataTypeToShaderCodeVariableDesc(GLenum glDataType);

GLint TextureComponentSwizzleToGLTextureSwizzle(TEXTURE_COMPONENT_SWIZZLE Swizzle, GLint IdentitySwizzle);

const char* GetFramebufferStatusString(GLenum Status);

inline GLenum GetCubeMapFaceBindTarget(Uint32 Slice)
{
// clang-format off
static constexpr std::array<GLenum, 6> CubeMapFaceTargets =
{
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

return Slice < CubeMapFaceTargets.size() ? CubeMapFaceTargets[Slice] : 0;
}

} // namespace Diligent
5 changes: 0 additions & 5 deletions Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "VAOCache.hpp"
#include "BaseInterfacesGL.h"
#include "FBOCache.hpp"
#include "TexRegionRender.hpp"

namespace Diligent
{
Expand Down Expand Up @@ -200,8 +199,6 @@ class RenderDeviceGLImpl : public RenderDeviceBase<EngineGLImplTraits>
size_t GetCommandQueueCount() const { return 1; }
Uint64 GetCommandQueueMask() const { return Uint64{1}; }

void InitTexRegionRender();

struct GLDeviceLimits
{
GLint MaxUniformBlocks;
Expand Down Expand Up @@ -239,8 +236,6 @@ class RenderDeviceGLImpl : public RenderDeviceBase<EngineGLImplTraits>
Threading::SpinLock m_FBOCacheLock;
std::unordered_map<GLContext::NativeGLContextType, FBOCache> m_FBOCache;

std::unique_ptr<TexRegionRender> m_pTexRegionRender;

private:
virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final;
bool CheckExtension(const Char* ExtensionString) const;
Expand Down
68 changes: 0 additions & 68 deletions Graphics/GraphicsEngineOpenGL/include/TexRegionRender.hpp

This file was deleted.

5 changes: 4 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/Texture1DArray_GL.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -64,6 +64,9 @@ class Texture1DArray_GL final : public TextureBaseGL
/// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture array.
virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc,
GLenum AttachmentPoint) override final;

/// Implementation of TextureBaseGL::CopyTexSubimage() for 1D texture array.
virtual void CopyTexSubimage(GLContextState& GLState, const CopyTexSubimageAttribs& Attribs) override final;
};

} // namespace Diligent
5 changes: 4 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/Texture1D_GL.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -64,6 +64,9 @@ class Texture1D_GL final : public TextureBaseGL
/// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture.
virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc,
GLenum AttachmentPoint) override final;

/// Implementation of TextureBaseGL::CopyTexSubimage() for 1D texture.
virtual void CopyTexSubimage(GLContextState& GLState, const CopyTexSubimageAttribs& Attribs) override final;
};

} // namespace Diligent
5 changes: 4 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/Texture2DArray_GL.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -64,6 +64,9 @@ class Texture2DArray_GL final : public TextureBaseGL
/// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture array.
virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc,
GLenum AttachmentPoint) override final;

/// Implementation of TextureBaseGL::CopyTexSubimage() for 2D texture array.
virtual void CopyTexSubimage(GLContextState& GLState, const CopyTexSubimageAttribs& Attribs) override final;
};

} // namespace Diligent
5 changes: 4 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/Texture2D_GL.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -72,6 +72,9 @@ class Texture2D_GL final : public TextureBaseGL
/// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture.
virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc,
GLenum AttachmentPoint) override final;

/// Implementation of TextureBaseGL::CopyTexSubimage() for 2D texture.
virtual void CopyTexSubimage(GLContextState& GLState, const CopyTexSubimageAttribs& Attribs) override final;
};

} // namespace Diligent
5 changes: 4 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/Texture3D_GL.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -64,6 +64,9 @@ class Texture3D_GL final : public TextureBaseGL
/// Implementation of TextureBaseGL::AttachToFramebuffer() for 3D texture.
virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc,
GLenum AttachmentPoint) override final;

/// Implementation of TextureBaseGL::CopyTexSubimage() for 3D texture.
virtual void CopyTexSubimage(GLContextState& GLState, const CopyTexSubimageAttribs& Attribs) override final;
};

} // namespace Diligent
13 changes: 13 additions & 0 deletions Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ class TextureBaseGL : public TextureBase<EngineGLImplTraits>, public AsyncWritab

void SetDefaultGLParameters();

struct CopyTexSubimageAttribs
{
const Box& SrcBox;

GLint DstMip = 0;
GLint DstLayer = 0;
GLint DstX = 0;
GLint DstY = 0;
GLint DstZ = 0;
};
virtual void CopyTexSubimage(GLContextState& GLState, const CopyTexSubimageAttribs& Attribs) = 0;

protected:
GLObjectWrappers::GLTextureObj m_GlTexture;
RefCntAutoPtr<IBuffer> m_pPBO; // For staging textures
const GLenum m_BindTarget;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -64,6 +64,9 @@ class TextureCubeArray_GL final : public TextureBaseGL
/// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture array.
virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc,
GLenum AttachmentPoint) override final;

/// Implementation of TextureBaseGL::CopyTexSubimage() for cube texture array.
virtual void CopyTexSubimage(GLContextState& GLState, const CopyTexSubimageAttribs& Attribs) override final;
};

} // namespace Diligent
5 changes: 4 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/TextureCube_GL.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -64,6 +64,9 @@ class TextureCube_GL final : public TextureBaseGL
/// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture.
virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc,
GLenum AttachmentPoint) override final;

/// Implementation of TextureBaseGL::CopyTexSubimage() for cube texture.
virtual void CopyTexSubimage(GLContextState& GLState, const CopyTexSubimageAttribs& Attribs) override final;
};

} // namespace Diligent
5 changes: 1 addition & 4 deletions Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -228,9 +228,6 @@ void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineGLCreateInf
pDeviceContextOpenGL->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppImmediateContext));
pRenderDeviceOpenGL->SetImmediateContext(0, pDeviceContextOpenGL);

// Need to create immediate context first
pRenderDeviceOpenGL->InitTexRegionRender();

TSwapChain* pSwapChainGL = NEW_RC_OBJ(RawMemAllocator, "SwapChainGLImpl instance", TSwapChain)(EngineCI, SCDesc, pRenderDeviceOpenGL, pDeviceContextOpenGL);
pSwapChainGL->QueryInterface(IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain));

Expand Down
15 changes: 2 additions & 13 deletions Graphics/GraphicsEngineOpenGL/src/FBOCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "RenderDeviceGLImpl.hpp"
#include "TextureBaseGL.hpp"
#include "GLContextState.hpp"
#include "GLTypeConversions.hpp"

namespace Diligent
{
Expand Down Expand Up @@ -229,19 +230,7 @@ GLObjectWrappers::GLFrameBufferObj FBOCache::CreateFBO(GLContextState& Contex
GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (Status != GL_FRAMEBUFFER_COMPLETE)
{
const Char* StatusString = "Unknown";
switch (Status)
{
// clang-format off
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: StatusString = "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"; break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: StatusString = "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"; break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: StatusString = "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"; break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: StatusString = "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"; break;
case GL_FRAMEBUFFER_UNSUPPORTED: StatusString = "GL_FRAMEBUFFER_UNSUPPORTED"; break;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: StatusString = "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"; break;
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: StatusString = "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS"; break;
// clang-format on
}
const Char* StatusString = GetFramebufferStatusString(Status);
LOG_ERROR("Framebuffer is incomplete. FB status: ", StatusString);
UNEXPECTED("Framebuffer is incomplete");
}
Expand Down
Loading

0 comments on commit a517455

Please sign in to comment.