From 8682485dea3768595416f0a580d0d1216a997db5 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 22 Nov 2015 22:49:53 -1000 Subject: [PATCH] Added array texture factory method (OGL only right now) --- include/boo/graphicsdev/GL.hpp | 2 ++ .../boo/graphicsdev/IGraphicsDataFactory.hpp | 4 +++ lib/graphicsdev/GL.cpp | 36 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/boo/graphicsdev/GL.hpp b/include/boo/graphicsdev/GL.hpp index a94af9d..a5a3203 100644 --- a/include/boo/graphicsdev/GL.hpp +++ b/include/boo/graphicsdev/GL.hpp @@ -31,6 +31,8 @@ public: const void* data, size_t sz); ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, std::unique_ptr&& data, size_t sz); + ITextureS* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt, + const void* data, size_t sz); ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt); ITextureR* newRenderTexture(size_t width, size_t height, size_t samples); diff --git a/include/boo/graphicsdev/IGraphicsDataFactory.hpp b/include/boo/graphicsdev/IGraphicsDataFactory.hpp index 88d6501..2483b00 100644 --- a/include/boo/graphicsdev/IGraphicsDataFactory.hpp +++ b/include/boo/graphicsdev/IGraphicsDataFactory.hpp @@ -87,6 +87,7 @@ protected: enum class TextureFormat { RGBA8, + I8, DXT1, PVRTC4 }; @@ -180,6 +181,9 @@ struct IGraphicsDataFactory virtual ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, std::unique_ptr&& data, size_t sz)=0; + virtual ITextureS* + newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt, + const void* data, size_t sz)=0; virtual ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt)=0; virtual ITextureR* diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 483e9f8..067890e 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -19,6 +19,7 @@ struct GLData : IGraphicsData std::vector> m_SBufs; std::vector> m_DBufs; std::vector> m_STexs; + std::vector> m_SATexs; std::vector> m_DTexs; std::vector> m_RTexs; std::vector> m_VFmts; @@ -136,6 +137,32 @@ public: } }; +class GLArrayTextureS : public ITextureS +{ + friend class GLDataFactory; + GLuint m_tex; + GLArrayTextureS(size_t width, size_t height, size_t layers, + TextureFormat fmt, const void* data, size_t sz) + { + glGenTextures(1, &m_tex); + glBindTexture(GL_TEXTURE_2D_ARRAY, m_tex); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (fmt == TextureFormat::RGBA8) + glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, width, height, layers, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + else if (fmt == TextureFormat::I8) + glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, width, height, layers, 0, GL_RED, GL_UNSIGNED_BYTE, data); + } +public: + ~GLArrayTextureS() {glDeleteTextures(1, &m_tex);} + + void bind(size_t idx) const + { + glActiveTexture(GL_TEXTURE0 + idx); + glBindTexture(GL_TEXTURE_2D_ARRAY, m_tex); + } +}; + class GLTextureD : public ITextureD { friend class GLDataFactory; @@ -207,6 +234,15 @@ GLDataFactory::newStaticTexture(size_t width, size_t height, size_t mips, Textur return retval; } +ITextureS* +GLDataFactory::newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt, + const void *data, size_t sz) +{ + GLArrayTextureS* retval = new GLArrayTextureS(width, height, layers, fmt, data, sz); + static_cast(m_deferredData)->m_SATexs.emplace_back(retval); + return retval; +} + class GLShaderPipeline : public IShaderPipeline { friend class GLDataFactory;