Array texture fix

This commit is contained in:
Jack Andersen 2015-11-26 13:03:01 -10:00
parent e106b0bac7
commit c5de075c0d
4 changed files with 32 additions and 12 deletions

View File

@ -31,8 +31,8 @@ public:
const void* data, size_t sz); const void* data, size_t sz);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
std::unique_ptr<uint8_t[]>&& data, size_t sz); std::unique_ptr<uint8_t[]>&& data, size_t sz);
ITextureS* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt, ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
const void* data, size_t sz); const void* data, size_t sz);
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt); ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt);
ITextureR* newRenderTexture(size_t width, size_t height, size_t samples); ITextureR* newRenderTexture(size_t width, size_t height, size_t samples);

View File

@ -46,6 +46,7 @@ enum class BufferUse
enum class TextureType enum class TextureType
{ {
Static, Static,
StaticArray,
Dynamic, Dynamic,
Render Render
}; };
@ -66,6 +67,13 @@ protected:
ITextureS() : ITexture(TextureType::Static) {} ITextureS() : ITexture(TextureType::Static) {}
}; };
/** Static-array resource buffer for array textures */
struct ITextureSA : ITexture
{
protected:
ITextureSA() : ITexture(TextureType::StaticArray) {}
};
/** Dynamic resource buffer for textures */ /** Dynamic resource buffer for textures */
struct ITextureD : ITexture struct ITextureD : ITexture
{ {
@ -192,7 +200,7 @@ struct IGraphicsDataFactory
virtual ITextureS* virtual ITextureS*
newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
std::unique_ptr<uint8_t[]>&& data, size_t sz)=0; std::unique_ptr<uint8_t[]>&& data, size_t sz)=0;
virtual ITextureS* virtual ITextureSA*
newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt, newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
const void* data, size_t sz)=0; const void* data, size_t sz)=0;
virtual ITextureD* virtual ITextureD*

View File

@ -19,7 +19,7 @@ struct GLData : IGraphicsData
std::vector<std::unique_ptr<class GLGraphicsBufferS>> m_SBufs; std::vector<std::unique_ptr<class GLGraphicsBufferS>> m_SBufs;
std::vector<std::unique_ptr<class GLGraphicsBufferD>> m_DBufs; std::vector<std::unique_ptr<class GLGraphicsBufferD>> m_DBufs;
std::vector<std::unique_ptr<class GLTextureS>> m_STexs; std::vector<std::unique_ptr<class GLTextureS>> m_STexs;
std::vector<std::unique_ptr<class GLArrayTextureS>> m_SATexs; std::vector<std::unique_ptr<class GLTextureSA>> m_SATexs;
std::vector<std::unique_ptr<class GLTextureD>> m_DTexs; std::vector<std::unique_ptr<class GLTextureD>> m_DTexs;
std::vector<std::unique_ptr<class GLTextureR>> m_RTexs; std::vector<std::unique_ptr<class GLTextureR>> m_RTexs;
std::vector<std::unique_ptr<struct GLVertexFormat>> m_VFmts; std::vector<std::unique_ptr<struct GLVertexFormat>> m_VFmts;
@ -137,12 +137,12 @@ public:
} }
}; };
class GLArrayTextureS : public ITextureS class GLTextureSA : public ITextureSA
{ {
friend class GLDataFactory; friend class GLDataFactory;
GLuint m_tex; GLuint m_tex;
GLArrayTextureS(size_t width, size_t height, size_t layers, GLTextureSA(size_t width, size_t height, size_t layers,
TextureFormat fmt, const void* data, size_t sz) TextureFormat fmt, const void* data, size_t sz)
{ {
glGenTextures(1, &m_tex); glGenTextures(1, &m_tex);
glBindTexture(GL_TEXTURE_2D_ARRAY, m_tex); glBindTexture(GL_TEXTURE_2D_ARRAY, m_tex);
@ -154,7 +154,7 @@ class GLArrayTextureS : public ITextureS
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, width, height, layers, 0, GL_RED, GL_UNSIGNED_BYTE, data); glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, width, height, layers, 0, GL_RED, GL_UNSIGNED_BYTE, data);
} }
public: public:
~GLArrayTextureS() {glDeleteTextures(1, &m_tex);} ~GLTextureSA() {glDeleteTextures(1, &m_tex);}
void bind(size_t idx) const void bind(size_t idx) const
{ {
@ -234,11 +234,11 @@ GLDataFactory::newStaticTexture(size_t width, size_t height, size_t mips, Textur
return retval; return retval;
} }
ITextureS* ITextureSA*
GLDataFactory::newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt, GLDataFactory::newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
const void *data, size_t sz) const void *data, size_t sz)
{ {
GLArrayTextureS* retval = new GLArrayTextureS(width, height, layers, fmt, data, sz); GLTextureSA* retval = new GLTextureSA(width, height, layers, fmt, data, sz);
static_cast<GLData*>(m_deferredData)->m_SATexs.emplace_back(retval); static_cast<GLData*>(m_deferredData)->m_SATexs.emplace_back(retval);
return retval; return retval;
} }
@ -494,10 +494,19 @@ struct GLShaderDataBinding : IShaderDataBinding
for (size_t i=0 ; i<m_texCount ; ++i) for (size_t i=0 ; i<m_texCount ; ++i)
{ {
ITexture* tex = m_texs[i]; ITexture* tex = m_texs[i];
if (tex->type() == TextureType::Dynamic) switch (tex->type())
{
case TextureType::Dynamic:
static_cast<GLTextureD*>(tex)->bind(i); static_cast<GLTextureD*>(tex)->bind(i);
else if (tex->type() == TextureType::Static) break;
case TextureType::Static:
static_cast<GLTextureS*>(tex)->bind(i); static_cast<GLTextureS*>(tex)->bind(i);
break;
case TextureType::StaticArray:
static_cast<GLTextureSA*>(tex)->bind(i);
break;
default: break;
}
} }
} }
}; };

View File

@ -838,7 +838,10 @@ public:
case ClientMessage: case ClientMessage:
{ {
if (event->xclient.data.l[0] == S_ATOMS->m_wmDeleteWindow && m_callback) if (event->xclient.data.l[0] == S_ATOMS->m_wmDeleteWindow && m_callback)
{
m_callback->destroyed(); m_callback->destroyed();
m_callback = nullptr;
}
return; return;
} }
case Expose: case Expose: