This commit is contained in:
Бранимир Караџић 2020-04-07 23:59:16 -07:00
parent 9c5a236230
commit 5555c73b3a

View File

@ -3442,13 +3442,13 @@ namespace bgfx { namespace gl
GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) ); GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) );
ProgramGL& program = m_program[_blitter.m_program.idx]; ProgramGL& program = m_program[_blitter.m_program.idx];
GlUseProgram(program.m_id); setProgram(program.m_id);
GlUniform1i(program.m_sampler[0].loc, 0); setUnifom1i(program.m_sampler[0].loc, 0);
float proj[16]; float proj[16];
bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, g_caps.homogeneousDepth); bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, g_caps.homogeneousDepth);
GlUniformMatrix4fv(program.m_predefined[0].m_loc setUnifomMatrix4fv(program.m_predefined[0].m_loc
, 1 , 1
, GL_FALSE , GL_FALSE
, proj , proj
@ -3553,7 +3553,7 @@ namespace bgfx { namespace gl
void setShaderUniform4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs) void setShaderUniform4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{ {
GlUniform4fv(_regIndex setUnifom4fv(_regIndex
, _numRegs , _numRegs
, (const GLfloat*)_val , (const GLfloat*)_val
); );
@ -3561,7 +3561,7 @@ namespace bgfx { namespace gl
void setShaderUniform4x4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs) void setShaderUniform4x4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
{ {
GlUniformMatrix4fv(_regIndex setUnifomMatrix4fv(_regIndex
, _numRegs , _numRegs
, GL_FALSE , GL_FALSE
, (const GLfloat*)_val , (const GLfloat*)_val
@ -4029,7 +4029,7 @@ namespace bgfx { namespace gl
case UniformType::_uniform: \ case UniformType::_uniform: \
{ \ { \
_type* value = (_type*)data; \ _type* value = (_type*)data; \
GlUniform##_glsuffix(loc, num, value); \ setUnifom##_glsuffix(loc, num, value); \
} \ } \
break; break;
@ -4037,7 +4037,7 @@ namespace bgfx { namespace gl
case UniformType::_uniform: \ case UniformType::_uniform: \
{ \ { \
_type* value = (_type*)data; \ _type* value = (_type*)data; \
GlUniform##_glsuffix(loc, num, GL_FALSE, value); \ setUnifom##_glsuffix(loc, num, GL_FALSE, value); \
} \ } \
break; break;
@ -4048,12 +4048,12 @@ namespace bgfx { namespace gl
// since they need to marshal an array over from Wasm to JS, so optimize the case when there is exactly one // since they need to marshal an array over from Wasm to JS, so optimize the case when there is exactly one
// uniform to upload. // uniform to upload.
case UniformType::Sampler: case UniformType::Sampler:
if (num > 1) GlUniform1iv(loc, num, (int*)data); if (num > 1) setUnifom1iv(loc, num, (int*)data);
else GlUniform1i(loc, *(int*)data); else setUnifom1i(loc, *(int*)data);
break; break;
case UniformType::Vec4: case UniformType::Vec4:
if (num > 1) GlUniform4fv(loc, num, (float*)data); if (num > 1) setUnifom4fv(loc, num, (float*)data);
else GlUniform4f(loc, ((float*)data)[0], ((float*)data)[1], ((float*)data)[2], ((float*)data)[3]); else setUnifom4f(loc, ((float*)data)[0], ((float*)data)[1], ((float*)data)[2], ((float*)data)[3]);
break; break;
#else #else
CASE_IMPLEMENT_UNIFORM(Sampler, 1iv, I, int); CASE_IMPLEMENT_UNIFORM(Sampler, 1iv, I, int);
@ -4178,7 +4178,7 @@ namespace bgfx { namespace gl
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) );
ProgramGL& program = m_program[_clearQuad.m_program[numMrt-1].idx]; ProgramGL& program = m_program[_clearQuad.m_program[numMrt-1].idx];
GlUseProgram(program.m_id); setProgram(program.m_id);
program.bindAttributesBegin(); program.bindAttributesBegin();
program.bindAttributes(layout, 0); program.bindAttributes(layout, 0);
program.bindAttributesEnd(); program.bindAttributesEnd();
@ -4237,7 +4237,7 @@ namespace bgfx { namespace gl
} }
} }
void GlUseProgram(GLuint program) void setProgram(GLuint program)
{ {
m_uniformStateCache.saveCurrentProgram(program); m_uniformStateCache.saveCurrentProgram(program);
GL_CHECK(glUseProgram(program) ); GL_CHECK(glUseProgram(program) );
@ -4245,7 +4245,7 @@ namespace bgfx { namespace gl
// Cache uniform uploads to avoid redundant uploading of state that is // Cache uniform uploads to avoid redundant uploading of state that is
// already set to a shader program // already set to a shader program
void GlUniform1i(uint32_t loc, int value) void setUnifom1i(uint32_t loc, int value)
{ {
if (m_uniformStateCache.updateUniformCache(loc, value)) if (m_uniformStateCache.updateUniformCache(loc, value))
{ {
@ -4253,7 +4253,7 @@ namespace bgfx { namespace gl
} }
} }
void GlUniform1iv(uint32_t loc, int num, const int *data) void setUnifom1iv(uint32_t loc, int num, const int *data)
{ {
bool changed = false; bool changed = false;
for(int i = 0; i < num; ++i) for(int i = 0; i < num; ++i)
@ -4269,7 +4269,7 @@ namespace bgfx { namespace gl
} }
} }
void GlUniform4f(uint32_t loc, float x, float y, float z, float w) void setUnifom4f(uint32_t loc, float x, float y, float z, float w)
{ {
UniformStateCache::f4 f; f.val[0] = x; f.val[1] = y; f.val[2] = z; f.val[3] = w; UniformStateCache::f4 f; f.val[0] = x; f.val[1] = y; f.val[2] = z; f.val[3] = w;
if (m_uniformStateCache.updateUniformCache(loc, f)) if (m_uniformStateCache.updateUniformCache(loc, f))
@ -4278,7 +4278,7 @@ namespace bgfx { namespace gl
} }
} }
void GlUniform4fv(uint32_t loc, int num, const float *data) void setUnifom4fv(uint32_t loc, int num, const float *data)
{ {
bool changed = false; bool changed = false;
for(int i = 0; i < num; ++i) for(int i = 0; i < num; ++i)
@ -4294,7 +4294,7 @@ namespace bgfx { namespace gl
} }
} }
void GlUniformMatrix3fv(uint32_t loc, int num, GLboolean transpose, const float *data) void setUnifomMatrix3fv(uint32_t loc, int num, GLboolean transpose, const float *data)
{ {
bool changed = false; bool changed = false;
for(int i = 0; i < num; ++i) for(int i = 0; i < num; ++i)
@ -4310,7 +4310,7 @@ namespace bgfx { namespace gl
} }
} }
void GlUniformMatrix4fv(uint32_t loc, int num, GLboolean transpose, const float *data) void setUnifomMatrix4fv(uint32_t loc, int num, GLboolean transpose, const float *data)
{ {
bool changed = false; bool changed = false;
for(int i = 0; i < num; ++i) for(int i = 0; i < num; ++i)
@ -4754,7 +4754,7 @@ namespace bgfx { namespace gl
if (0 != m_id) if (0 != m_id)
{ {
s_renderGL->GlUseProgram(0); s_renderGL->setProgram(0);
GL_CHECK(glDeleteProgram(m_id) ); GL_CHECK(glDeleteProgram(m_id) );
m_id = 0; m_id = 0;
} }
@ -7245,7 +7245,7 @@ namespace bgfx { namespace gl
const RenderCompute& compute = renderItem.compute; const RenderCompute& compute = renderItem.compute;
ProgramGL& program = m_program[key.m_program.idx]; ProgramGL& program = m_program[key.m_program.idx];
GlUseProgram(program.m_id); setProgram(program.m_id);
GLbitfield barrier = 0; GLbitfield barrier = 0;
for (uint32_t ii = 0; ii < maxComputeBindings; ++ii) for (uint32_t ii = 0; ii < maxComputeBindings; ++ii)
@ -7743,7 +7743,7 @@ namespace bgfx { namespace gl
// Skip rendering if program index is valid, but program is invalid. // Skip rendering if program index is valid, but program is invalid.
currentProgram = 0 == id ? ProgramHandle{kInvalidHandle} : currentProgram; currentProgram = 0 == id ? ProgramHandle{kInvalidHandle} : currentProgram;
GlUseProgram(id); setProgram(id);
programChanged = programChanged =
constantsChanged = constantsChanged =
bindAttribs = true; bindAttribs = true;