Renderer/Texture: Add Copy method (wip)

This commit is contained in:
Jérôme Leclercq
2021-09-13 23:34:51 +02:00
parent 72f2a5b531
commit db85372778
9 changed files with 101 additions and 13 deletions

View File

@@ -53,6 +53,32 @@ namespace Nz
m_texture.SetParameteri(GL_TEXTURE_SWIZZLE_A, format->swizzleA);
}
bool OpenGLTexture::Copy(const Texture& source, const Boxui& srcBox, const Vector3ui& dstPos)
{
const OpenGLTexture& glTexture = static_cast<const OpenGLTexture&>(source);
const GL::Context& context = m_texture.EnsureDeviceContext();
// Use glCopyImageSubData if available
if (context.glCopyImageSubData)
{
GLuint srcImage = glTexture.GetTexture().GetObjectId();
GLenum srcTarget = ToOpenGL(ToTextureTarget(glTexture.GetType()));
GLuint dstImage = m_texture.GetObjectId();
GLenum dstTarget = ToOpenGL(ToTextureTarget(m_params.type));
context.glCopyImageSubData(srcImage, srcTarget, 0, GLint(srcBox.x), GLint(srcBox.y), GLint(srcBox.z), dstImage, dstTarget, 0, GLint(dstPos.x), GLint(dstPos.y), GLint(dstPos.z), GLsizei(srcBox.width), GLsizei(srcBox.height), GLsizei(srcBox.depth));
return true;
}
else
{
//TODO: Blit using framebuffers
}
return false;
}
PixelFormat OpenGLTexture::GetFormat() const
{
return m_params.pixelFormat;