mirror of https://github.com/AxioDL/boo.git
Added array texture factory method (OGL only right now)
This commit is contained in:
parent
99b4f155e3
commit
8682485dea
|
@ -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<uint8_t[]>&& 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);
|
||||
|
||||
|
|
|
@ -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<uint8_t[]>&& 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*
|
||||
|
|
|
@ -19,6 +19,7 @@ struct GLData : IGraphicsData
|
|||
std::vector<std::unique_ptr<class GLGraphicsBufferS>> m_SBufs;
|
||||
std::vector<std::unique_ptr<class GLGraphicsBufferD>> m_DBufs;
|
||||
std::vector<std::unique_ptr<class GLTextureS>> m_STexs;
|
||||
std::vector<std::unique_ptr<class GLArrayTextureS>> m_SATexs;
|
||||
std::vector<std::unique_ptr<class GLTextureD>> m_DTexs;
|
||||
std::vector<std::unique_ptr<class GLTextureR>> m_RTexs;
|
||||
std::vector<std::unique_ptr<struct GLVertexFormat>> 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<GLData*>(m_deferredData)->m_SATexs.emplace_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
class GLShaderPipeline : public IShaderPipeline
|
||||
{
|
||||
friend class GLDataFactory;
|
||||
|
|
Loading…
Reference in New Issue