From 1ab63cfb185f6058c16b979b3c12d1152de382fd Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 15 Feb 2016 19:47:09 -1000 Subject: [PATCH] No-context texture constructor (OpenGL only for now) --- include/boo/graphicsdev/GL.hpp | 5 +- .../boo/graphicsdev/IGraphicsDataFactory.hpp | 6 +- lib/graphicsdev/GL.cpp | 70 +++++++++++++------ 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/include/boo/graphicsdev/GL.hpp b/include/boo/graphicsdev/GL.hpp index db53875..7961e52 100644 --- a/include/boo/graphicsdev/GL.hpp +++ b/include/boo/graphicsdev/GL.hpp @@ -34,8 +34,9 @@ public: ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, 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); + GraphicsDataToken + newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt, + const void* data, size_t sz, ITextureS** texOut); ITextureSA* 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); diff --git a/include/boo/graphicsdev/IGraphicsDataFactory.hpp b/include/boo/graphicsdev/IGraphicsDataFactory.hpp index 5d6eb9a..c0e746d 100644 --- a/include/boo/graphicsdev/IGraphicsDataFactory.hpp +++ b/include/boo/graphicsdev/IGraphicsDataFactory.hpp @@ -201,9 +201,9 @@ struct IGraphicsDataFactory virtual ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, const void* data, size_t sz)=0; - virtual ITextureS* - newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, - std::unique_ptr&& data, size_t sz)=0; + virtual GraphicsDataToken + newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt, + const void* data, size_t sz, ITextureS** texOut)=0; virtual ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt, const void* data, size_t sz)=0; diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 8d8de7f..98a7547 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -133,6 +133,7 @@ class GLTextureS : public ITextureS GLenum intFormat, format; int pxPitch; + bool compressed = false; switch (fmt) { case TextureFormat::RGBA8: @@ -145,16 +146,34 @@ class GLTextureS : public ITextureS format = GL_RED; pxPitch = 1; break; + case TextureFormat::DXT1: + intFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + compressed = true; + break; default: Log.report(LogVisor::FatalError, "unsupported tex format"); } - for (size_t i=0 ; i&& data, size_t sz) +GraphicsDataToken +GLDataFactory::newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt, + const void* data, size_t sz, ITextureS** texOut) { - std::unique_ptr d = std::move(data); - GLTextureS* retval = new GLTextureS(width, height, mips, fmt, d.get(), sz); - if (!m_deferredData.get()) - m_deferredData.reset(new struct GLData()); - m_deferredData->m_STexs.emplace_back(retval); - return retval; + GLTextureS* retval = new GLTextureS(width, height, mips, fmt, data, sz); + GLData* tokData = new struct GLData(); + tokData->m_STexs.emplace_back(retval); + *texOut = retval; + + std::unique_lock lk(m_committedMutex); + m_committedData.insert(tokData); + lk.unlock(); + /* Let's go ahead and flush to ensure our data gets to the GPU + While this isn't strictly required, some drivers might behave + differently */ + glFlush(); + return GraphicsDataToken(this, tokData); } ITextureSA* @@ -471,7 +497,7 @@ IShaderPipeline* GLDataFactory::newShaderPipeline { GLint uniLoc = glGetUniformBlockIndex(shader.m_prog, uniformBlockNames[i]); if (uniLoc < 0) - Log.report(LogVisor::FatalError, "unable to find uniform block '%s'", uniformBlockNames[i]); + Log.report(LogVisor::Error, "unable to find uniform block '%s'", uniformBlockNames[i]); shader.m_uniLocs.push_back(uniLoc); } } @@ -480,11 +506,14 @@ IShaderPipeline* GLDataFactory::newShaderPipeline { GLint texLoc = glGetUniformLocation(shader.m_prog, texArrayName); if (texLoc < 0) - Log.report(LogVisor::FatalError, "unable to find sampler variable '%s'", texArrayName); - if (texCount > m_texUnis.size()) - for (size_t i=m_texUnis.size() ; i m_texUnis.size()) + for (size_t i=m_texUnis.size() ; i