From d75c675f7a98c0eb40a3b216211328c1728aa479 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 15 Nov 2015 18:29:31 -1000 Subject: [PATCH] Updates for HECL support --- include/boo/graphicsdev/GL.hpp | 8 ++-- .../boo/graphicsdev/IGraphicsDataFactory.hpp | 2 +- include/boo/graphicsdev/Metal.hpp | 2 +- lib/graphicsdev/D3D11.cpp | 4 +- lib/graphicsdev/D3D12.cpp | 4 +- lib/graphicsdev/GL.cpp | 44 +++++++++++++------ lib/graphicsdev/glew.c | 2 + test/main.cpp | 10 ++--- 8 files changed, 49 insertions(+), 27 deletions(-) diff --git a/include/boo/graphicsdev/GL.hpp b/include/boo/graphicsdev/GL.hpp index f9ef618..771e540 100644 --- a/include/boo/graphicsdev/GL.hpp +++ b/include/boo/graphicsdev/GL.hpp @@ -15,12 +15,13 @@ class GLDataFactory : public IGraphicsDataFactory IGraphicsContext* m_parent; IGraphicsData* m_deferredData = nullptr; std::unordered_set m_committedData; + std::vector m_texUnis; public: GLDataFactory(IGraphicsContext* parent); ~GLDataFactory() {} Platform platform() const {return PlatformOGL;} - const char* platformName() const {return "OpenGL";} + const char* platformName() const {return "OGL";} IGraphicsBufferS* newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count); IGraphicsBufferS* newStaticBuffer(BufferUse use, std::unique_ptr&& data, size_t stride, size_t count); @@ -36,14 +37,15 @@ public: IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements); IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource, - size_t texCount, const char** texNames, + size_t texCount, const char* texArrayName, + size_t uniformBlockCount, const char** uniformBlockNames, BlendFactor srcFac, BlendFactor dstFac, bool depthTest, bool depthWrite, bool backfaceCulling); IShaderDataBinding* newShaderDataBinding(IShaderPipeline* pipeline, IVertexFormat* vtxFormat, - IGraphicsBuffer* vbo, IGraphicsBuffer* ebo, + IGraphicsBuffer* vbo, IGraphicsBuffer* ibo, size_t ubufCount, IGraphicsBuffer** ubufs, size_t texCount, ITexture** texs); diff --git a/include/boo/graphicsdev/IGraphicsDataFactory.hpp b/include/boo/graphicsdev/IGraphicsDataFactory.hpp index 2f0e1ae..a8967ce 100644 --- a/include/boo/graphicsdev/IGraphicsDataFactory.hpp +++ b/include/boo/graphicsdev/IGraphicsDataFactory.hpp @@ -193,7 +193,7 @@ struct IGraphicsDataFactory virtual IShaderDataBinding* newShaderDataBinding(IShaderPipeline* pipeline, IVertexFormat* vtxFormat, - IGraphicsBuffer* vbo, IGraphicsBuffer* ebo, + IGraphicsBuffer* vbo, IGraphicsBuffer* ibo, size_t ubufCount, IGraphicsBuffer** ubufs, size_t texCount, ITexture** texs)=0; diff --git a/include/boo/graphicsdev/Metal.hpp b/include/boo/graphicsdev/Metal.hpp index 3842895..c0139ad 100644 --- a/include/boo/graphicsdev/Metal.hpp +++ b/include/boo/graphicsdev/Metal.hpp @@ -46,7 +46,7 @@ public: IShaderDataBinding* newShaderDataBinding(IShaderPipeline* pipeline, IVertexFormat* vtxFormat, - IGraphicsBuffer* vbo, IGraphicsBuffer* ebo, + IGraphicsBuffer* vbo, IGraphicsBuffer* ibo, size_t ubufCount, IGraphicsBuffer** ubufs, size_t texCount, ITexture** texs); diff --git a/lib/graphicsdev/D3D11.cpp b/lib/graphicsdev/D3D11.cpp index e3196d2..b6a1a10 100644 --- a/lib/graphicsdev/D3D11.cpp +++ b/lib/graphicsdev/D3D11.cpp @@ -439,7 +439,7 @@ struct D3D11ShaderDataBinding : IShaderDataBinding struct D3D11CommandQueue : IGraphicsCommandQueue { Platform platform() const {return IGraphicsDataFactory::PlatformD3D11;} - const char* platformName() const {return "Direct3D 11";} + const char* platformName() const {return "D3D11";} D3D11Context* m_ctx; D3D11Context::Window* m_windowCtx; IGraphicsContext* m_parent; @@ -712,7 +712,7 @@ public: ~D3D11DataFactory() = default; Platform platform() const {return PlatformD3D11;} - const char* platformName() const {return "Direct3D 11";} + const char* platformName() const {return "D3D11";} IGraphicsBufferS* newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count) { diff --git a/lib/graphicsdev/D3D12.cpp b/lib/graphicsdev/D3D12.cpp index 9600033..d5adde1 100644 --- a/lib/graphicsdev/D3D12.cpp +++ b/lib/graphicsdev/D3D12.cpp @@ -636,7 +636,7 @@ static ID3D12GraphicsCommandList* WaitForLoadList(D3D12Context* ctx) struct D3D12CommandQueue : IGraphicsCommandQueue { Platform platform() const {return IGraphicsDataFactory::PlatformD3D12;} - const char* platformName() const {return "Direct 3D 12";} + const char* platformName() const {return "D3D12";} D3D12Context* m_ctx; D3D12Context::Window* m_windowCtx; IGraphicsContext* m_parent; @@ -959,7 +959,7 @@ public: ~D3D12DataFactory() = default; Platform platform() const {return PlatformD3D12;} - const char* platformName() const {return "Direct3D 12";} + const char* platformName() const {return "D3D12";} IGraphicsBufferS* newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count) { diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 639eb76..59df46d 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -210,6 +210,7 @@ GLDataFactory::newStaticTexture(size_t width, size_t height, size_t mips, Textur class GLShaderPipeline : public IShaderPipeline { friend class GLDataFactory; + friend struct GLShaderDataBinding; GLuint m_vert = 0; GLuint m_frag = 0; GLuint m_prog = 0; @@ -218,6 +219,7 @@ class GLShaderPipeline : public IShaderPipeline bool m_depthTest = true; bool m_depthWrite = true; bool m_backfaceCulling = true; + std::vector m_uniLocs; bool initObjects() { m_vert = glCreateShader(GL_VERTEX_SHADER); @@ -307,7 +309,8 @@ static const GLenum BLEND_FACTOR_TABLE[] = IShaderPipeline* GLDataFactory::newShaderPipeline (const char* vertSource, const char* fragSource, - size_t texCount, const char** texNames, + size_t texCount, const char* texArrayName, + size_t uniformBlockCount, const char** uniformBlockNames, BlendFactor srcFac, BlendFactor dstFac, bool depthTest, bool depthWrite, bool backfaceCulling) { @@ -366,13 +369,28 @@ IShaderPipeline* GLDataFactory::newShaderPipeline } glUseProgram(shader.m_prog); - for (size_t i=0 ; i= 0) - glUniform1i(loc, i); - else - Log.report(LogVisor::FatalError, "unable to find sampler variable '%s'", texNames[i]); + shader.m_uniLocs.reserve(uniformBlockCount); + for (size_t i=0 ; i m_texUnis.size()) + for (size_t i=m_texUnis.size() ; i m_texs; GLShaderDataBinding(IShaderPipeline* pipeline, - IVertexFormat* vtxFormat, - size_t ubufCount, IGraphicsBuffer** ubufs, - size_t texCount, ITexture** texs) + IVertexFormat* vtxFormat, + size_t ubufCount, IGraphicsBuffer** ubufs, + size_t texCount, ITexture** texs) : m_pipeline(static_cast(pipeline)), m_vtxFormat(static_cast(vtxFormat)), m_ubufCount(ubufCount), @@ -425,8 +443,8 @@ struct GLShaderDataBinding : IShaderDataBinding if (m_ubufs[i]->dynamic()) static_cast(m_ubufs[i])->bindUniform(i); else - static_cast(m_ubufs[i])->bindUniform(i); - glUniformBlockBinding(prog, i, i); + static_cast(m_ubufs[i])->bindUniform(i); + glUniformBlockBinding(prog, m_pipeline->m_uniLocs.at(i), i); } for (size_t i=0 ; inewShaderPipeline(VS, FS, 1, TexNames, BlendFactorOne, BlendFactorZero, true, true, false); + pipeline = glF->newShaderPipeline(VS, FS, 1, "texs", 0, nullptr, + BlendFactorOne, BlendFactorZero, + true, true, false); } #if _WIN32 else if (factory->platform() == IGraphicsDataFactory::PlatformD3D12 ||