mirror of https://github.com/AxioDL/boo.git
Updates for HECL support
This commit is contained in:
parent
ddcbc102ba
commit
d75c675f7a
|
@ -15,12 +15,13 @@ class GLDataFactory : public IGraphicsDataFactory
|
||||||
IGraphicsContext* m_parent;
|
IGraphicsContext* m_parent;
|
||||||
IGraphicsData* m_deferredData = nullptr;
|
IGraphicsData* m_deferredData = nullptr;
|
||||||
std::unordered_set<IGraphicsData*> m_committedData;
|
std::unordered_set<IGraphicsData*> m_committedData;
|
||||||
|
std::vector<int> m_texUnis;
|
||||||
public:
|
public:
|
||||||
GLDataFactory(IGraphicsContext* parent);
|
GLDataFactory(IGraphicsContext* parent);
|
||||||
~GLDataFactory() {}
|
~GLDataFactory() {}
|
||||||
|
|
||||||
Platform platform() const {return PlatformOGL;}
|
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, const void* data, size_t stride, size_t count);
|
||||||
IGraphicsBufferS* newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count);
|
IGraphicsBufferS* newStaticBuffer(BufferUse use, std::unique_ptr<uint8_t[]>&& data, size_t stride, size_t count);
|
||||||
|
@ -36,14 +37,15 @@ public:
|
||||||
IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements);
|
IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements);
|
||||||
|
|
||||||
IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource,
|
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,
|
BlendFactor srcFac, BlendFactor dstFac,
|
||||||
bool depthTest, bool depthWrite, bool backfaceCulling);
|
bool depthTest, bool depthWrite, bool backfaceCulling);
|
||||||
|
|
||||||
IShaderDataBinding*
|
IShaderDataBinding*
|
||||||
newShaderDataBinding(IShaderPipeline* pipeline,
|
newShaderDataBinding(IShaderPipeline* pipeline,
|
||||||
IVertexFormat* vtxFormat,
|
IVertexFormat* vtxFormat,
|
||||||
IGraphicsBuffer* vbo, IGraphicsBuffer* ebo,
|
IGraphicsBuffer* vbo, IGraphicsBuffer* ibo,
|
||||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||||
size_t texCount, ITexture** texs);
|
size_t texCount, ITexture** texs);
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ struct IGraphicsDataFactory
|
||||||
virtual IShaderDataBinding*
|
virtual IShaderDataBinding*
|
||||||
newShaderDataBinding(IShaderPipeline* pipeline,
|
newShaderDataBinding(IShaderPipeline* pipeline,
|
||||||
IVertexFormat* vtxFormat,
|
IVertexFormat* vtxFormat,
|
||||||
IGraphicsBuffer* vbo, IGraphicsBuffer* ebo,
|
IGraphicsBuffer* vbo, IGraphicsBuffer* ibo,
|
||||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||||
size_t texCount, ITexture** texs)=0;
|
size_t texCount, ITexture** texs)=0;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
IShaderDataBinding*
|
IShaderDataBinding*
|
||||||
newShaderDataBinding(IShaderPipeline* pipeline,
|
newShaderDataBinding(IShaderPipeline* pipeline,
|
||||||
IVertexFormat* vtxFormat,
|
IVertexFormat* vtxFormat,
|
||||||
IGraphicsBuffer* vbo, IGraphicsBuffer* ebo,
|
IGraphicsBuffer* vbo, IGraphicsBuffer* ibo,
|
||||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||||
size_t texCount, ITexture** texs);
|
size_t texCount, ITexture** texs);
|
||||||
|
|
||||||
|
|
|
@ -439,7 +439,7 @@ struct D3D11ShaderDataBinding : IShaderDataBinding
|
||||||
struct D3D11CommandQueue : IGraphicsCommandQueue
|
struct D3D11CommandQueue : IGraphicsCommandQueue
|
||||||
{
|
{
|
||||||
Platform platform() const {return IGraphicsDataFactory::PlatformD3D11;}
|
Platform platform() const {return IGraphicsDataFactory::PlatformD3D11;}
|
||||||
const char* platformName() const {return "Direct3D 11";}
|
const char* platformName() const {return "D3D11";}
|
||||||
D3D11Context* m_ctx;
|
D3D11Context* m_ctx;
|
||||||
D3D11Context::Window* m_windowCtx;
|
D3D11Context::Window* m_windowCtx;
|
||||||
IGraphicsContext* m_parent;
|
IGraphicsContext* m_parent;
|
||||||
|
@ -712,7 +712,7 @@ public:
|
||||||
~D3D11DataFactory() = default;
|
~D3D11DataFactory() = default;
|
||||||
|
|
||||||
Platform platform() const {return PlatformD3D11;}
|
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)
|
IGraphicsBufferS* newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)
|
||||||
{
|
{
|
||||||
|
|
|
@ -636,7 +636,7 @@ static ID3D12GraphicsCommandList* WaitForLoadList(D3D12Context* ctx)
|
||||||
struct D3D12CommandQueue : IGraphicsCommandQueue
|
struct D3D12CommandQueue : IGraphicsCommandQueue
|
||||||
{
|
{
|
||||||
Platform platform() const {return IGraphicsDataFactory::PlatformD3D12;}
|
Platform platform() const {return IGraphicsDataFactory::PlatformD3D12;}
|
||||||
const char* platformName() const {return "Direct 3D 12";}
|
const char* platformName() const {return "D3D12";}
|
||||||
D3D12Context* m_ctx;
|
D3D12Context* m_ctx;
|
||||||
D3D12Context::Window* m_windowCtx;
|
D3D12Context::Window* m_windowCtx;
|
||||||
IGraphicsContext* m_parent;
|
IGraphicsContext* m_parent;
|
||||||
|
@ -959,7 +959,7 @@ public:
|
||||||
~D3D12DataFactory() = default;
|
~D3D12DataFactory() = default;
|
||||||
|
|
||||||
Platform platform() const {return PlatformD3D12;}
|
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)
|
IGraphicsBufferS* newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)
|
||||||
{
|
{
|
||||||
|
|
|
@ -210,6 +210,7 @@ GLDataFactory::newStaticTexture(size_t width, size_t height, size_t mips, Textur
|
||||||
class GLShaderPipeline : public IShaderPipeline
|
class GLShaderPipeline : public IShaderPipeline
|
||||||
{
|
{
|
||||||
friend class GLDataFactory;
|
friend class GLDataFactory;
|
||||||
|
friend struct GLShaderDataBinding;
|
||||||
GLuint m_vert = 0;
|
GLuint m_vert = 0;
|
||||||
GLuint m_frag = 0;
|
GLuint m_frag = 0;
|
||||||
GLuint m_prog = 0;
|
GLuint m_prog = 0;
|
||||||
|
@ -218,6 +219,7 @@ class GLShaderPipeline : public IShaderPipeline
|
||||||
bool m_depthTest = true;
|
bool m_depthTest = true;
|
||||||
bool m_depthWrite = true;
|
bool m_depthWrite = true;
|
||||||
bool m_backfaceCulling = true;
|
bool m_backfaceCulling = true;
|
||||||
|
std::vector<GLint> m_uniLocs;
|
||||||
bool initObjects()
|
bool initObjects()
|
||||||
{
|
{
|
||||||
m_vert = glCreateShader(GL_VERTEX_SHADER);
|
m_vert = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
@ -307,7 +309,8 @@ static const GLenum BLEND_FACTOR_TABLE[] =
|
||||||
|
|
||||||
IShaderPipeline* GLDataFactory::newShaderPipeline
|
IShaderPipeline* GLDataFactory::newShaderPipeline
|
||||||
(const char* vertSource, const char* fragSource,
|
(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,
|
BlendFactor srcFac, BlendFactor dstFac,
|
||||||
bool depthTest, bool depthWrite, bool backfaceCulling)
|
bool depthTest, bool depthWrite, bool backfaceCulling)
|
||||||
{
|
{
|
||||||
|
@ -366,13 +369,28 @@ IShaderPipeline* GLDataFactory::newShaderPipeline
|
||||||
}
|
}
|
||||||
|
|
||||||
glUseProgram(shader.m_prog);
|
glUseProgram(shader.m_prog);
|
||||||
for (size_t i=0 ; i<texCount ; ++i)
|
|
||||||
|
if (uniformBlockCount)
|
||||||
{
|
{
|
||||||
GLint loc;
|
shader.m_uniLocs.reserve(uniformBlockCount);
|
||||||
if ((loc = glGetUniformLocation(shader.m_prog, texNames[i])) >= 0)
|
for (size_t i=0 ; i<uniformBlockCount ; ++i)
|
||||||
glUniform1i(loc, i);
|
{
|
||||||
else
|
GLint uniLoc = glGetUniformBlockIndex(shader.m_prog, uniformBlockNames[i]);
|
||||||
Log.report(LogVisor::FatalError, "unable to find sampler variable '%s'", texNames[i]);
|
if (uniLoc < 0)
|
||||||
|
Log.report(LogVisor::FatalError, "unable to find uniform block '%s'", uniformBlockNames[i]);
|
||||||
|
shader.m_uniLocs.push_back(uniLoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texCount && texArrayName)
|
||||||
|
{
|
||||||
|
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<texCount ; ++i)
|
||||||
|
m_texUnis.push_back(i);
|
||||||
|
glUniform1iv(texLoc, m_texUnis.size(), m_texUnis.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
GLShaderPipeline* retval = new GLShaderPipeline(std::move(shader));
|
GLShaderPipeline* retval = new GLShaderPipeline(std::move(shader));
|
||||||
|
@ -401,9 +419,9 @@ struct GLShaderDataBinding : IShaderDataBinding
|
||||||
size_t m_texCount;
|
size_t m_texCount;
|
||||||
std::unique_ptr<ITexture*[]> m_texs;
|
std::unique_ptr<ITexture*[]> m_texs;
|
||||||
GLShaderDataBinding(IShaderPipeline* pipeline,
|
GLShaderDataBinding(IShaderPipeline* pipeline,
|
||||||
IVertexFormat* vtxFormat,
|
IVertexFormat* vtxFormat,
|
||||||
size_t ubufCount, IGraphicsBuffer** ubufs,
|
size_t ubufCount, IGraphicsBuffer** ubufs,
|
||||||
size_t texCount, ITexture** texs)
|
size_t texCount, ITexture** texs)
|
||||||
: m_pipeline(static_cast<GLShaderPipeline*>(pipeline)),
|
: m_pipeline(static_cast<GLShaderPipeline*>(pipeline)),
|
||||||
m_vtxFormat(static_cast<GLVertexFormat*>(vtxFormat)),
|
m_vtxFormat(static_cast<GLVertexFormat*>(vtxFormat)),
|
||||||
m_ubufCount(ubufCount),
|
m_ubufCount(ubufCount),
|
||||||
|
@ -425,8 +443,8 @@ struct GLShaderDataBinding : IShaderDataBinding
|
||||||
if (m_ubufs[i]->dynamic())
|
if (m_ubufs[i]->dynamic())
|
||||||
static_cast<GLGraphicsBufferD*>(m_ubufs[i])->bindUniform(i);
|
static_cast<GLGraphicsBufferD*>(m_ubufs[i])->bindUniform(i);
|
||||||
else
|
else
|
||||||
static_cast<GLGraphicsBufferD*>(m_ubufs[i])->bindUniform(i);
|
static_cast<GLGraphicsBufferS*>(m_ubufs[i])->bindUniform(i);
|
||||||
glUniformBlockBinding(prog, i, i);
|
glUniformBlockBinding(prog, m_pipeline->m_uniLocs.at(i), i);
|
||||||
}
|
}
|
||||||
for (size_t i=0 ; i<m_texCount ; ++i)
|
for (size_t i=0 ; i<m_texCount ; ++i)
|
||||||
{
|
{
|
||||||
|
@ -516,7 +534,7 @@ static const GLenum SEMANTIC_TYPE_TABLE[] =
|
||||||
struct GLCommandQueue : IGraphicsCommandQueue
|
struct GLCommandQueue : IGraphicsCommandQueue
|
||||||
{
|
{
|
||||||
Platform platform() const {return IGraphicsDataFactory::PlatformOGL;}
|
Platform platform() const {return IGraphicsDataFactory::PlatformOGL;}
|
||||||
const char* platformName() const {return "OpenGL ES 3.0";}
|
const char* platformName() const {return "OGL";}
|
||||||
IGraphicsContext* m_parent = nullptr;
|
IGraphicsContext* m_parent = nullptr;
|
||||||
|
|
||||||
struct Command
|
struct Command
|
||||||
|
|
|
@ -3949,6 +3949,7 @@ static GLboolean _glewInit_GL_VERSION_3_2 (GLEW_CONTEXT_ARG_DEF_INIT)
|
||||||
|
|
||||||
static GLboolean _glewInit_GL_ARB_vertex_array_object (GLEW_CONTEXT_ARG_DEF_INIT);
|
static GLboolean _glewInit_GL_ARB_vertex_array_object (GLEW_CONTEXT_ARG_DEF_INIT);
|
||||||
static GLboolean _glewInit_GL_ARB_framebuffer_object (GLEW_CONTEXT_ARG_DEF_INIT);
|
static GLboolean _glewInit_GL_ARB_framebuffer_object (GLEW_CONTEXT_ARG_DEF_INIT);
|
||||||
|
static GLboolean _glewInit_GL_ARB_uniform_buffer_object (GLEW_CONTEXT_ARG_DEF_INIT);
|
||||||
static GLboolean _glewInit_GL_VERSION_3_3 (GLEW_CONTEXT_ARG_DEF_INIT)
|
static GLboolean _glewInit_GL_VERSION_3_3 (GLEW_CONTEXT_ARG_DEF_INIT)
|
||||||
{
|
{
|
||||||
GLboolean r = GL_FALSE;
|
GLboolean r = GL_FALSE;
|
||||||
|
@ -3956,6 +3957,7 @@ static GLboolean _glewInit_GL_VERSION_3_3 (GLEW_CONTEXT_ARG_DEF_INIT)
|
||||||
r = ((glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC)glewGetProcAddress((const GLubyte*)"glVertexAttribDivisor")) == NULL) || r;
|
r = ((glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC)glewGetProcAddress((const GLubyte*)"glVertexAttribDivisor")) == NULL) || r;
|
||||||
_glewInit_GL_ARB_vertex_array_object();
|
_glewInit_GL_ARB_vertex_array_object();
|
||||||
_glewInit_GL_ARB_framebuffer_object();
|
_glewInit_GL_ARB_framebuffer_object();
|
||||||
|
_glewInit_GL_ARB_uniform_buffer_object();
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,17 +295,17 @@ struct TestApplicationCallback : IApplicationCallback
|
||||||
static const char* FS =
|
static const char* FS =
|
||||||
"#version 330\n"
|
"#version 330\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
"uniform sampler2D smplr;\n"
|
"uniform sampler2D texs[1];\n"
|
||||||
"layout(location=0) out vec4 out_frag;\n"
|
"layout(location=0) out vec4 out_frag;\n"
|
||||||
"in vec2 out_uv;\n"
|
"in vec2 out_uv;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" out_frag = texture(smplr, out_uv);\n"
|
" out_frag = texture(texs[0], out_uv);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
static const char* TexNames[] = {"smplr"};
|
pipeline = glF->newShaderPipeline(VS, FS, 1, "texs", 0, nullptr,
|
||||||
|
BlendFactorOne, BlendFactorZero,
|
||||||
pipeline = glF->newShaderPipeline(VS, FS, 1, TexNames, BlendFactorOne, BlendFactorZero, true, true, false);
|
true, true, false);
|
||||||
}
|
}
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
else if (factory->platform() == IGraphicsDataFactory::PlatformD3D12 ||
|
else if (factory->platform() == IGraphicsDataFactory::PlatformD3D12 ||
|
||||||
|
|
Loading…
Reference in New Issue