50 mILMap = std::make_unique<GL4InputLayoutManager>();
94 std::shared_ptr<GLSLProgramFactory> factory = std::make_shared<GLSLProgramFactory>();
95 mDefaultFont = std::make_shared<FontArialW400H18>(factory, 256);
133 + std::to_string(requiredMinor) +
" is required.";
134 std::cout << message << std::endl;
162 LogWarning(
"Bridge map is nonempty on destruction.");
172 LogWarning(
"Draw target map nonempty on destruction.");
178 if (
mILMap->HasElements())
182 LogWarning(
"Input layout map nonempty on destruction.");
193 unsigned int vertexOffset = vbuffer->
GetOffset();
231 LogError(
"Unknown primitive topology = " + std::to_string(type));
238 void const*
data = (
char*)0 + indexSize * offset;
240 static_cast<GLsizei>(numActiveIndices), indexType, data);
250 glDrawArrays(topology, static_cast<GLint>(vertexOffset),
251 static_cast<GLint>(numActiveVertices));
258 VertexShader* vshader = effect->GetVertexShader().get();
261 LogError(
"Effect does not have a vertex shader.");
265 PixelShader* pshader = effect->GetPixelShader().get();
268 LogError(
"Effect does not have a pixel shader.");
287 VertexShader* vshader = effect->GetVertexShader().get();
288 PixelShader* pshader = effect->GetPixelShader().get();
324 for (
auto const& cb : shader->
GetData(index))
331 auto const blockIndex = cb.bindPoint;
336 gl4CB->AttachToUnit(unit);
341 LogError(
"Failed to bind constant buffer.");
346 LogError(cb.name +
" is null constant buffer.");
354 for (
auto const& cb : shader->
GetData(index))
356 auto const blockIndex = cb.bindPoint;
379 auto const& atomicCounters = shader->
GetData(Shader::AtomicCounterShaderDataLookup);
380 auto const& atomicCounterBuffers = shader->
GetData(Shader::AtomicCounterBufferShaderDataLookup);
381 for (
unsigned acbIndex = 0; acbIndex < atomicCounterBuffers.size(); ++acbIndex)
383 auto const& acb = atomicCounterBuffers[acbIndex];
397 if (rawBuffer && (acb.numBytes > static_cast<int>(rawBuffer->GetNumBytes())))
415 rawBuffer = std::make_shared<RawBuffer>((acb.numBytes + 3) / 4,
false);
421 mGOMap.Insert(rawBuffer.get(), temp);
435 for (
auto const& sb : shader->
GetData(indexSB))
442 auto const blockIndex = sb.bindPoint;
450 gl4SB->AttachToUnit(unit);
455 if (sb.isGpuWritable)
458 gl4SB->SetNumActiveElements();
462 auto const acIndex = sb.extra;
465 auto const acbIndex = atomicCounters[acIndex].bindPoint;
466 auto const acbOffset = atomicCounters[acIndex].extra;
473 gl4SB->CopyCounterValueToBuffer(gl4ACB, acbOffset);
479 LogError(
"Failed to bind structured buffer.");
484 LogError(sb.name +
" is null structured buffer.");
492 auto const& atomicCounters = shader->
GetData(Shader::AtomicCounterShaderDataLookup);
493 auto const& atomicCounterBuffers = shader->
GetData(Shader::AtomicCounterBufferShaderDataLookup);
494 for (
unsigned acbIndex = 0; acbIndex < atomicCounterBuffers.size(); ++acbIndex)
496 auto const& acb = atomicCounterBuffers[acbIndex];
501 for (
auto const& sb : shader->
GetData(index))
509 auto const blockIndex = sb.bindPoint;
519 if (sb.isGpuWritable)
523 auto const acIndex = sb.extra;
526 auto const acbIndex = atomicCounters[acIndex].bindPoint;
527 auto const acbOffset = atomicCounters[acIndex].extra;
535 gl4SB->CopyCounterValueFromBuffer(gl4ACB, acbOffset);
556 for (
auto const& ts : shader->
GetData(index))
560 LogError(ts.name +
" is null texture.");
567 LogError(
"Failed to bind texture.");
574 if (ts.isGpuWritable)
599 for (
auto const& ts : shader->
GetData(index))
603 LogError(ts.name +
" is null texture.");
616 if (ts.isGpuWritable)
640 for (
auto const& ta : shader->
GetData(index))
644 LogError(ta.name +
" is null texture array.");
651 LogError(
"Failed to bind texture array.");
658 if (ta.isGpuWritable)
683 for (
auto const& ta : shader->
GetData(index))
687 LogError(ta.name +
" is null texture array.");
694 LogError(
"Failed to get texture array.");
700 if (ta.isGpuWritable)
724 for (
auto const& ts : shader->
GetData(index))
737 LogError(
"Failed to bind sampler.");
742 LogError(ts.name +
" is null sampler.");
750 for (
auto const& ts : shader->
GetData(index))
770 LogError(ts.name +
" is null sampler.");
786 for (
int unit = 0; unit < static_cast<int>(mLinkMap.size()); ++unit)
788 auto& item = mLinkMap[unit];
791 if (program == item.program && index == item.index)
798 if (0 == item.linkCount)
812 availUnit =
static_cast<int>(mLinkMap.size());
813 mLinkMap.push_back({ 0, 0, 0 });
816 auto& item = mLinkMap[availUnit];
825 for (
int unit = 0; unit < static_cast<int>(mLinkMap.size()); ++unit)
827 auto& item = mLinkMap[unit];
828 if (program == item.program && index == item.index)
838 if (index < mLinkMap.size())
840 auto& item = mLinkMap[
index];
841 if (item.linkCount > 0)
850 if (unit < mLinkMap.size())
852 return mLinkMap[unit].linkCount;
859 if (unit < mLinkMap.size())
861 auto& item = mLinkMap[
index];
862 if (item.linkCount > 0)
864 program = item.program;
892 glDepthRange(static_cast<GLdouble>(zmin), static_cast<GLdouble>(zmax));
899 zmin =
static_cast<float>(param[0]);
900 zmax =
static_cast<float>(param[1]);
909 glViewport(param[0], param[1], static_cast<GLint>(w), static_cast<GLint>(h));
953 LogError(
"Failed to bind blend state.");
977 LogError(
"Failed to bind depth-stencil state.");
1001 LogError(
"Failed to bind rasterizer state.");
1028 if (!buffer->GetData())
1030 LogWarning(
"Buffer does not have system memory, creating it.");
1031 buffer->CreateStorage();
1035 return glBuffer->
Update();
1040 if (!texture->GetData())
1042 LogWarning(
"Texture does not have system memory, creating it.");
1043 texture->CreateStorage();
1047 return glTexture->
Update();
1052 if (!texture->GetData())
1054 LogWarning(
"Texture does not have system memory, creating it.");
1055 texture->CreateStorage();
1059 return glTexture->
Update(level);
1064 if (!textureArray->GetData())
1066 LogWarning(
"Texture array does not have system memory, creating it.");
1067 textureArray->CreateStorage();
1071 return glTextureArray->
Update();
1076 if (!textureArray->GetData())
1078 LogWarning(
"Texture array does not have system memory, creating it.");
1079 textureArray->CreateStorage();
1083 return glTextureArray->
Update(item, level);
1088 if (!buffer->GetData())
1090 LogWarning(
"Buffer does not have system memory, creating it.");
1091 buffer->CreateStorage();
1100 if (!texture->GetData())
1102 LogWarning(
"Texture does not have system memory, creating it.");
1103 texture->CreateStorage();
1112 if (!texture->GetData())
1114 LogWarning(
"Texture does not have system memory, creating it.");
1115 texture->CreateStorage();
1124 if (!textureArray->GetData())
1126 LogWarning(
"Texture array does not have system memory, creating it.");
1127 textureArray->CreateStorage();
1136 if (!textureArray->GetData())
1138 LogWarning(
"Texture array does not have system memory, creating it.");
1139 textureArray->CreateStorage();
1148 if (!buffer->GetData())
1150 LogWarning(
"Buffer does not have system memory, creating it.");
1151 buffer->CreateStorage();
1160 if (!texture->GetData())
1162 LogWarning(
"Texture does not have system memory, creating it.");
1163 texture->CreateStorage();
1172 if (!texture->GetData())
1174 LogWarning(
"Texture does not have system memory, creating it.");
1175 texture->CreateStorage();
1184 if (!textureArray->GetData())
1186 LogWarning(
"Texture array does not have system memory, creating it.");
1187 textureArray->CreateStorage();
1196 if (!textureArray->GetData())
1198 LogWarning(
"Texture array does not have system memory, creating it.");
1199 textureArray->CreateStorage();
1207 std::shared_ptr<Buffer>
const& buffer0,
1208 std::shared_ptr<Buffer>
const& buffer1)
1216 std::shared_ptr<TextureSingle>
const& texture0,
1217 std::shared_ptr<TextureSingle>
const& texture1)
1225 std::shared_ptr<TextureSingle>
const& texture0,
1226 std::shared_ptr<TextureSingle>
const& texture1,
1236 std::shared_ptr<TextureArray>
const& textureArray0,
1237 std::shared_ptr<TextureArray>
const& textureArray1)
1239 (
void)textureArray0;
1240 (
void)textureArray1;
1245 std::shared_ptr<TextureArray>
const& textureArray0,
1246 std::shared_ptr<TextureArray>
const& textureArray1,
1247 unsigned int item,
unsigned int level)
1249 (
void)textureArray0;
1250 (
void)textureArray1;
1258 auto gl4Object =
Get(buffer);
1274 unsigned int numXGroups,
unsigned int numYGroups,
unsigned int numZGroups)
1277 if (glslProgram && numXGroups > 0 && numYGroups > 0 && numZGroups > 0)
1280 auto programHandle = glslProgram->GetProgramHandle();
1281 if (cshader && programHandle > 0)
1284 Enable(cshader.get(), programHandle);
1286 Disable(cshader.get(), programHandle);
1292 LogError(
"Invalid input parameter.");
1307 std::shared_ptr<IndexBuffer>
const& ibuffer, std::shared_ptr<VisualEffect>
const& effect)
1312 LogError(
"HLSL effect passed to GLSL engine.");
1316 uint64_t numPixelsDrawn = 0;
1325 if (vbuffer->StandardUsage())
1329 gl4Layout = manager->
Bind(programHandle, gl4VBuffer->
GetGLHandle(), vbuffer.get());
1335 if (ibuffer->IsIndexed())
1341 numPixelsDrawn =
DrawPrimitive(vbuffer.get(), ibuffer.get());
1344 if (vbuffer->StandardUsage())
1360 return numPixelsDrawn;
virtual bool Update(std::shared_ptr< Buffer > const &buffer) override
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
ThreadSafeMap< GraphicsObject const *, std::shared_ptr< GEObject > > mGOMap
std::shared_ptr< Font > mActiveFont
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
static int const shaderDataLookup
virtual void GetViewport(int &x, int &y, int &w, int &h) const override
ProgramIndexUnitMap mUniformUnitMap
std::array< CreateGEObject, GT_NUM_TYPES > mCreateGEObject
virtual void ClearColorBuffer() override
#define GL_LINE_STRIP_ADJACENCY
std::shared_ptr< RasterizerState > mActiveRasterizerState
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void ReleaseUnit(unsigned index)
void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count)
virtual bool Resize(unsigned int w, unsigned int h) override
std::shared_ptr< BlendState > mActiveBlendState
void EnableTextures(Shader const *shader, GLuint program)
#define GL_TRIANGLE_STRIP
void EnableCBuffers(Shader const *shader, GLuint program)
void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
CreateGEDrawTarget mCreateGEDrawTarget
void EnableSBuffers(Shader const *shader, GLuint program)
void DisableShaders(std::shared_ptr< VisualEffect > const &effect, GLuint program)
virtual bool CopyCpuToGpu() override
void APIENTRY glDepthRange(GLdouble near, GLdouble far)
static int const shaderDataLookup
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
#define GL_UNIFORM_BUFFER
unsigned int GetOffset() const
static std::shared_ptr< GEDrawTarget > Create(DrawTarget const *target, std::vector< GEObject * > &rtTextures, GEObject *dsTexture)
#define GL_SHADER_STORAGE_BUFFER
virtual void ClearDepthBuffer() override
virtual void SetDepthStencilState(std::shared_ptr< DepthStencilState > const &state) override
void DisableTextures(Shader const *shader, GLuint program)
virtual void CopyGpuToGpu(std::shared_ptr< Buffer > const &buffer0, std::shared_ptr< Buffer > const &buffer1) override
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
ProgramIndexUnitMap mShaderStorageUnitMap
void Disable(Shader const *shader, GLuint program)
#define GL_COLOR_BUFFER_BIT
GEObject * Get(std::shared_ptr< GraphicsObject > const &object) const
GLbitfield GLuint program
std::unique_ptr< GEInputLayoutManager > mILMap
virtual void WaitForFinish() override
void APIENTRY glShaderStorageBlockBinding(GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding)
void APIENTRY glDispatchCompute(GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z)
ProgramIndexUnitMap mTextureImageUnitMap
static int const shaderDataLookup
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
static int const shaderDataLookup
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
std::shared_ptr< GOListener > mGOListener
bool Unbind(std::shared_ptr< GraphicsObject > const &object)
void DisableRBuffers(Shader const *shader, GLuint program)
void APIENTRY glBindSampler(GLuint unit, GLuint sampler)
GLubyte GLubyte GLubyte GLubyte w
void Enable(Shader const *shader, GLuint program)
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void APIENTRY glBindTexture(GLenum target, GLuint texture)
void DisableTBuffers(Shader const *shader, GLuint program)
void DestroyDefaultFont()
virtual void DestroyDefaultGlobalState()
virtual bool GetNumActiveElements(std::shared_ptr< StructuredBuffer > const &buffer) override
std::array< float, 4 > mClearColor
virtual void Flush() override
unsigned int mClearStencil
bool GetNumActiveElements()
void EnableSamplers(Shader const *shader, GLuint program)
virtual bool CopyCpuToGpu(std::shared_ptr< Buffer > const &buffer) override
virtual bool CopyGpuToCpu() override
unsigned int GetElementSize() const
virtual void Execute(std::shared_ptr< ComputeProgram > const &program, unsigned int numXGroups, unsigned int numYGroups, unsigned int numZGroups) override
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
virtual bool CopyGpuToCpu(std::shared_ptr< Buffer > const &buffer) override
virtual bool CopyCpuToGpu()
void APIENTRY glUniform1i(GLint location, GLint v0)
virtual bool CopyGpuToCpu() override
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void APIENTRY glUseProgram(GLuint program)
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
virtual bool BindProgram(std::shared_ptr< ComputeProgram > const &program) override
void CreateDefaultGlobalState()
GLsizei const GLchar *const * string
bool GetUnitProgramIndex(unsigned unit, GLint &program, GLint &index) const
GLuint GetProgramHandle() const
#define LogError(message)
ProgramIndexUnitMap mTextureSamplerUnitMap
void EnableRBuffers(Shader const *shader, GLuint program)
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
virtual bool Initialize(int requiredMajor, int requiredMinor, bool saveDriverInfo)
#define GL_TRIANGLES_ADJACENCY
static void UnsubscribeForDestruction(std::shared_ptr< ListenerForDestruction > const &listener)
ThreadSafeMap< DrawTarget const *, std::shared_ptr< GEDrawTarget > > mDTMap
GLuint GLsizei const GLchar * message
virtual bool Update() override
std::shared_ptr< DepthStencilState > mActiveDepthStencilState
#define LogWarning(message)
void InitializeOpenGL(int &major, int &minor, char const *infofile)
void APIENTRY glActiveTexture(GLenum texture)
IPType GetPrimitiveType() const
#define GL_TRIANGLE_STRIP_ADJACENCY
GLint GLint GLsizei GLint GLenum format
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
unsigned int GetNumActiveElements() const
std::shared_ptr< Font > mDefaultFont
GEObject * Bind(std::shared_ptr< GraphicsObject > const &object)
GLfloat GLfloat GLfloat GLfloat h
void APIENTRY glClearDepth(GLdouble depth)
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
virtual void SetBlendState(std::shared_ptr< BlendState > const &state) override
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void APIENTRY glGetIntegerv(GLenum pname, GLint *data)
int AcquireUnit(GLint program, GLint index)
void APIENTRY glBindImageTexture(GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format)
virtual void SetViewport(int x, int y, int w, int h) override
int GetUnit(GLint program, GLint index) const
void APIENTRY glClear(GLbitfield mask)
#define GL_UNSIGNED_SHORT
virtual bool Update() override
#define GL_STENCIL_BUFFER_BIT
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void APIENTRY glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
void DisableTextureArrays(Shader const *shader, GLuint program)
void APIENTRY glGetDoublev(GLenum pname, GLdouble *data)
void APIENTRY glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
void APIENTRY glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
#define GL_ATOMIC_COUNTER_BUFFER
uint64_t DrawPrimitive(VertexBuffer const *vbuffer, IndexBuffer const *ibuffer)
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void APIENTRY glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices)
void EnableTextureArrays(Shader const *shader, GLuint program)
bool EnableShaders(std::shared_ptr< VisualEffect > const &effect, GLuint program)
static int const shaderDataLookup
virtual void ClearStencilBuffer() override
static void UnsubscribeForDestruction(std::shared_ptr< ListenerForDestruction > const &listener)
void APIENTRY glClearStencil(GLint s)
void AttachToUnit(GLint atomicCounterBufferUnit)
#define GL_LINES_ADJACENCY
virtual void SetRasterizerState(std::shared_ptr< RasterizerState > const &state) override
unsigned GetUnitLinkCount(unsigned unit) const
void EnableTBuffers(Shader const *shader, GLuint program)
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void DisableSBuffers(Shader const *shader, GLuint program)
bool mWarnOnNonemptyBridges
std::shared_ptr< DTListener > mDTListener
void DisableCBuffers(Shader const *shader, GLuint program)
#define GL_DEPTH_BUFFER_BIT
virtual void SetDepthRange(float zmin, float zmax) override
std::vector< std::shared_ptr< RawBuffer > > mAtomicCounterRawBuffers
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void DisableSamplers(Shader const *shader, GLuint program)
virtual void ClearBuffers() override
GLint GLint GLsizei GLint GLenum GLenum type
virtual bool CopyCpuToGpu() override
virtual void GetDepthRange(float &zmin, float &zmax) const override
virtual bool CopyGpuToCpu()
uint32_t GetNumActiveIndices() const
std::vector< Data > const & GetData(int lookup) const
GLuint GetGLHandle() const
std::shared_ptr< ComputeShader > const & GetCShader() const