mirror of
https://github.com/blawar/GLideN64.git
synced 2024-06-25 05:49:34 +00:00
GLES2: Replace UniformBlocks by separate uniforms.
This commit is contained in:
parent
d4a9899110
commit
9779399306
|
@ -293,3 +293,9 @@ void CombinerInfo::updateLightParameters()
|
|||
m_pUniformBlock->updateLightParameters();
|
||||
gSP.changed &= ~CHANGED_LIGHT;
|
||||
}
|
||||
|
||||
void CombinerInfo::updateParameters()
|
||||
{
|
||||
if (m_pUniformBlock != NULL)
|
||||
m_pUniformBlock->updateUniforms(m_pCurrent);
|
||||
}
|
||||
|
|
|
@ -137,6 +137,8 @@ public:
|
|||
|
||||
void updateTextureParameters();
|
||||
void updateLightParameters();
|
||||
// Update uniforms for GL without UniformBlock support
|
||||
void updateParameters();
|
||||
|
||||
private:
|
||||
CombinerInfo() : m_bChanged(false), m_pCurrent(NULL) {}
|
||||
|
|
|
@ -1003,6 +1003,7 @@ void SetMonochromeCombiner() {
|
|||
}
|
||||
|
||||
/*======================UniformBlock==========================*/
|
||||
#ifdef GL_UNIFORMBLOCK_SUPPORT
|
||||
|
||||
static
|
||||
const char * strTextureUniforms[UniformBlock::tuTotal] = {
|
||||
|
@ -1241,3 +1242,135 @@ void UniformBlock::updateLightParameters()
|
|||
}
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, m_lightBlock.m_offsets[luLightDirection], m_lightBlockData.size(), pData);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
#define LocateUniform2(A) \
|
||||
location.A.loc = glGetUniformLocation(program, #A);
|
||||
|
||||
void UniformBlock::bindWithShaderCombiner(ShaderCombiner * _pCombiner)
|
||||
{
|
||||
const u64 mux = _pCombiner->getMux();
|
||||
const GLuint program = _pCombiner->m_program;
|
||||
m_uniforms.emplace(mux, program);
|
||||
UniformBlockLocation & location = m_uniforms.at(mux);
|
||||
|
||||
// Texture parameters
|
||||
if (_pCombiner->usesTexture()) {
|
||||
LocateUniform2(uTexScale);
|
||||
LocateUniform2(uTexMask[0]);
|
||||
LocateUniform2(uTexMask[1]);
|
||||
LocateUniform2(uTexOffset[0]);
|
||||
LocateUniform2(uTexOffset[1]);
|
||||
LocateUniform2(uCacheScale[0]);
|
||||
LocateUniform2(uCacheScale[1]);
|
||||
LocateUniform2(uCacheOffset[0]);
|
||||
LocateUniform2(uCacheOffset[1]);
|
||||
LocateUniform2(uCacheShiftScale[0]);
|
||||
LocateUniform2(uCacheShiftScale[1]);
|
||||
LocateUniform2(uCacheFrameBuffer);
|
||||
_updateTextureUniforms(location, _pCombiner->usesTile(0), _pCombiner->usesTile(1), true);
|
||||
}
|
||||
|
||||
// Colors
|
||||
LocateUniform2(uFogColor);
|
||||
LocateUniform2(uCenterColor);
|
||||
LocateUniform2(uScaleColor);
|
||||
LocateUniform2(uBlendColor);
|
||||
LocateUniform2(uEnvColor);
|
||||
LocateUniform2(uPrimColor);
|
||||
LocateUniform2(uPrimLod);
|
||||
LocateUniform2(uK4);
|
||||
LocateUniform2(uK5);
|
||||
_updateColorUniforms(location, true);
|
||||
|
||||
// Lights
|
||||
if (config.generalEmulation.enableHWLighting != 0 && GBI.isHWLSupported() && _pCombiner->usesShadeColor()) {
|
||||
// locate lights uniforms
|
||||
char buf[32];
|
||||
for (s32 i = 0; i < 8; ++i) {
|
||||
sprintf(buf, "uLightDirection[%d]", i);
|
||||
location.uLightDirection[i].loc = glGetUniformLocation(program, buf);
|
||||
sprintf(buf, "uLightColor[%d]", i);
|
||||
location.uLightColor[i].loc = glGetUniformLocation(program, buf);
|
||||
}
|
||||
_updateLightUniforms(location, true);
|
||||
}
|
||||
}
|
||||
|
||||
void UniformBlock::_updateColorUniforms(UniformBlockLocation & _location, bool _bForce)
|
||||
{
|
||||
_location.uFogColor.set(&gDP.fogColor.r, _bForce);
|
||||
_location.uCenterColor.set(&gDP.key.center.r, _bForce);
|
||||
_location.uScaleColor.set(&gDP.key.scale.r, _bForce);
|
||||
_location.uBlendColor.set(&gDP.blendColor.r, _bForce);
|
||||
_location.uEnvColor.set(&gDP.envColor.r, _bForce);
|
||||
_location.uPrimColor.set(&gDP.primColor.r, _bForce);
|
||||
_location.uPrimLod.set(gDP.primColor.l, _bForce);
|
||||
_location.uK4.set(gDP.convert.k4*0.0039215689f, _bForce);
|
||||
_location.uK5.set(gDP.convert.k5*0.0039215689f, _bForce);
|
||||
}
|
||||
|
||||
|
||||
void UniformBlock::_updateTextureUniforms(UniformBlockLocation & _location, bool _bUsesT0, bool _bUsesT1, bool _bForce)
|
||||
{
|
||||
int nFB[2] = { 0, 0 };
|
||||
const bool bUsesTile[2] = { _bUsesT0, _bUsesT1 };
|
||||
TextureCache & cache = textureCache();
|
||||
for (u32 t = 0; t < 2; ++t) {
|
||||
if (!bUsesTile[t])
|
||||
continue;
|
||||
|
||||
if (gSP.textureTile[t] != NULL) {
|
||||
if (gSP.textureTile[t]->textureMode == TEXTUREMODE_BGIMAGE || gSP.textureTile[t]->textureMode == TEXTUREMODE_FRAMEBUFFER_BG) {
|
||||
_location.uTexOffset[t].set(0.0f, 0.0f, _bForce);
|
||||
_location.uTexMask[t].set(0.0f, 0.0f, _bForce);
|
||||
}
|
||||
else {
|
||||
_location.uTexOffset[t].set(gSP.textureTile[t]->fuls, gSP.textureTile[t]->fult, _bForce);
|
||||
_location.uTexMask[t].set(
|
||||
gSP.textureTile[t]->masks > 0 ? (float)(1 << gSP.textureTile[t]->masks) : 0.0f,
|
||||
gSP.textureTile[t]->maskt > 0 ? (float)(1 << gSP.textureTile[t]->maskt) : 0.0f,
|
||||
_bForce);
|
||||
}
|
||||
}
|
||||
|
||||
if (cache.current[t] != NULL) {
|
||||
f32 shiftScaleS = 1.0f;
|
||||
f32 shiftScaleT = 1.0f;
|
||||
getTextureShiftScale(t, cache, shiftScaleS, shiftScaleT);
|
||||
_location.uCacheShiftScale[t].set(shiftScaleS, shiftScaleT, _bForce);
|
||||
_location.uCacheScale[t].set(cache.current[t]->scaleS, cache.current[t]->scaleT, _bForce);
|
||||
_location.uCacheOffset[t].set(cache.current[t]->offsetS, cache.current[t]->offsetT, _bForce);
|
||||
nFB[t] = cache.current[t]->frameBufferTexture;
|
||||
}
|
||||
}
|
||||
|
||||
_location.uCacheFrameBuffer.set(nFB[0], nFB[1], _bForce);
|
||||
_location.uTexScale.set(gSP.texture.scales, gSP.texture.scalet, _bForce);
|
||||
}
|
||||
|
||||
void UniformBlock::_updateLightUniforms(UniformBlockLocation & _location, bool _bForce)
|
||||
{
|
||||
for (s32 i = 0; i <= gSP.numLights; ++i) {
|
||||
_location.uLightDirection[i].set(&gSP.lights[i].x, _bForce);
|
||||
_location.uLightColor[i].set(&gSP.lights[i].r, _bForce);
|
||||
}
|
||||
}
|
||||
|
||||
void UniformBlock::updateUniforms(ShaderCombiner * _pCombiner)
|
||||
{
|
||||
UniformBlockLocation & location = m_uniforms.at(_pCombiner->getMux());
|
||||
|
||||
_updateColorUniforms(location, false);
|
||||
|
||||
OGLRender::RENDER_STATE rs = video().getRender().getRenderState();
|
||||
if ((rs == OGLRender::rsTriangle || rs == OGLRender::rsLine) && _pCombiner->usesTexture())
|
||||
_updateTextureUniforms(location, _pCombiner->usesTile(0), _pCombiner->usesTile(1), false);
|
||||
|
||||
if (config.generalEmulation.enableHWLighting != 0 && GBI.isHWLSupported() && _pCombiner->usesShadeColor())
|
||||
_updateLightUniforms(location, false);
|
||||
}
|
||||
|
||||
#endif // GL_UNIFORMBLOCK_SUPPORT
|
||||
|
|
|
@ -116,6 +116,7 @@ private:
|
|||
int m_nInputs;
|
||||
};
|
||||
|
||||
#ifdef GL_UNIFORMBLOCK_SUPPORT
|
||||
class UniformBlock
|
||||
{
|
||||
public:
|
||||
|
@ -156,6 +157,7 @@ public:
|
|||
void setColorData(ColorUniforms _index, u32 _dataSize, const void * _data);
|
||||
void updateTextureParameters();
|
||||
void updateLightParameters();
|
||||
void updateUniforms(ShaderCombiner * _pCombiner) {}
|
||||
|
||||
private:
|
||||
void _initTextureBuffer(GLuint _program);
|
||||
|
@ -214,6 +216,84 @@ private:
|
|||
std::vector<GLbyte> m_colorsBlockData;
|
||||
std::vector<GLbyte> m_lightBlockData;
|
||||
};
|
||||
#else
|
||||
class UniformBlock
|
||||
{
|
||||
public:
|
||||
|
||||
UniformBlock() {}
|
||||
~UniformBlock() {}
|
||||
|
||||
enum ColorUniforms {
|
||||
cuFogColor,
|
||||
cuCenterColor,
|
||||
cuScaleColor,
|
||||
cuBlendColor,
|
||||
cuEnvColor,
|
||||
cuPrimColor,
|
||||
cuPrimLod,
|
||||
cuK4,
|
||||
cuK5,
|
||||
cuTotal
|
||||
};
|
||||
|
||||
void bindWithShaderCombiner(ShaderCombiner * _pCombiner);
|
||||
void setColorData(ColorUniforms _index, u32 _dataSize, const void * _data) {}
|
||||
void updateTextureParameters() {}
|
||||
void updateLightParameters() {}
|
||||
void updateUniforms(ShaderCombiner * _pCombiner);
|
||||
|
||||
private:
|
||||
struct fv3Uniform {
|
||||
GLint loc;
|
||||
float val[3];
|
||||
void set(float * _pVal, bool _force) {
|
||||
const size_t szData = sizeof(float)* 3;
|
||||
if (loc >= 0 && (_force || memcmp(val, _pVal, szData) != 0)) {
|
||||
memcpy(val, _pVal, szData);
|
||||
glUniform3fv(loc, 1, _pVal);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct fv4Uniform {
|
||||
GLint loc;
|
||||
float val[4];
|
||||
void set(float * _pVal, bool _force) {
|
||||
const size_t szData = sizeof(float)* 4;
|
||||
if (loc >= 0 && (_force || memcmp(val, _pVal, szData) != 0)) {
|
||||
memcpy(val, _pVal, szData);
|
||||
glUniform4fv(loc, 1, _pVal);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct UniformBlockLocation
|
||||
{
|
||||
UniformBlockLocation(GLuint _program) : m_program(_program) {}
|
||||
|
||||
GLuint m_program;
|
||||
|
||||
// Texture parameters
|
||||
ShaderCombiner::fv2Uniform uTexScale, uTexMask[2], uTexOffset[2], uCacheScale[2], uCacheOffset[2], uCacheShiftScale[2];
|
||||
ShaderCombiner::iv2Uniform uCacheFrameBuffer;
|
||||
|
||||
// Colors
|
||||
fv4Uniform uFogColor, uCenterColor, uScaleColor, uBlendColor, uEnvColor, uPrimColor;
|
||||
ShaderCombiner::fUniform uPrimLod, uK4, uK5;
|
||||
|
||||
// Lights
|
||||
fv3Uniform uLightDirection[8], uLightColor[8];
|
||||
};
|
||||
|
||||
void _updateColorUniforms(UniformBlockLocation & _location, bool _bForce);
|
||||
void _updateTextureUniforms(UniformBlockLocation & _location, bool _bUsesT0, bool _bUsesT1, bool _bForce);
|
||||
void _updateLightUniforms(UniformBlockLocation & _location, bool _bForce);
|
||||
|
||||
typedef std::map<u64, UniformBlockLocation> Uniforms;
|
||||
Uniforms m_uniforms;
|
||||
};
|
||||
#endif // GL_UNIFORMBLOCK_SUPPORT
|
||||
|
||||
void InitShaderCombiner();
|
||||
void DestroyShaderCombiner();
|
||||
|
|
|
@ -624,6 +624,8 @@ void OGLRender::_updateStates(RENDER_STATE _renderState) const
|
|||
_setBlendMode();
|
||||
gDP.changed &= ~(CHANGED_RENDERMODE | CHANGED_CYCLETYPE);
|
||||
}
|
||||
|
||||
cmbInfo.updateParameters();
|
||||
}
|
||||
|
||||
void OGLRender::_setColorArray() const
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "windows/GLFunctions.h"
|
||||
#define GL_IMAGE_TEXTURES_SUPPORT
|
||||
#define GL_MULTISAMPLING_SUPPORT
|
||||
#define GL_UNIFORMBLOCK_SUPPORT
|
||||
#else
|
||||
#include "winlnxdefs.h"
|
||||
#ifdef GLES2
|
||||
|
@ -21,12 +22,14 @@
|
|||
#include <GLES3/gl3.h>
|
||||
#include <GLES3/gl3ext.h>
|
||||
#define GLESX
|
||||
#define GL_UNIFORMBLOCK_SUPPORT
|
||||
#elif defined(GLES3_1)
|
||||
#include <GLES3/gl31.h>
|
||||
#include <GLES3/gl3ext.h>
|
||||
#define GLESX
|
||||
#define GL_IMAGE_TEXTURES_SUPPORT
|
||||
#define GL_MULTISAMPLING_SUPPORT
|
||||
#define GL_UNIFORMBLOCK_SUPPORT
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#if defined(OS_MAC_OS_X)
|
||||
|
@ -38,6 +41,7 @@
|
|||
#include <GL/glext.h>
|
||||
#define GL_IMAGE_TEXTURES_SUPPORT
|
||||
#define GL_MULTISAMPLING_SUPPORT
|
||||
#define GL_UNIFORMBLOCK_SUPPORT
|
||||
#endif // OS_MAC_OS_X
|
||||
#endif // GLES2
|
||||
#ifdef USE_SDL
|
||||
|
|
|
@ -20,6 +20,7 @@ SHADER_VERSION
|
|||
"uniform lowp float uFogAlpha; \n"
|
||||
"uniform mediump vec2 uFogScale; \n"
|
||||
" \n"
|
||||
#ifdef GL_UNIFORMBLOCK_SUPPORT
|
||||
"layout (std140) uniform TextureBlock { \n"
|
||||
" mediump vec2 uTexScale; \n"
|
||||
" mediump vec2 uTexMask[2]; \n"
|
||||
|
@ -29,6 +30,15 @@ SHADER_VERSION
|
|||
" mediump vec2 uCacheShiftScale[2]; \n"
|
||||
" lowp ivec2 uCacheFrameBuffer; \n"
|
||||
"}; \n"
|
||||
#else
|
||||
"uniform mediump vec2 uTexScale; \n"
|
||||
"uniform mediump vec2 uTexMask[2]; \n"
|
||||
"uniform mediump vec2 uTexOffset[2]; \n"
|
||||
"uniform mediump vec2 uCacheScale[2]; \n"
|
||||
"uniform mediump vec2 uCacheOffset[2]; \n"
|
||||
"uniform mediump vec2 uCacheShiftScale[2]; \n"
|
||||
"uniform lowp ivec2 uCacheFrameBuffer; \n"
|
||||
#endif // GL_UNIFORMBLOCK_SUPPORT
|
||||
"out lowp vec4 vShadeColor; \n"
|
||||
"out mediump vec2 vTexCoord0; \n"
|
||||
"out mediump vec2 vTexCoord1; \n"
|
||||
|
@ -168,6 +178,7 @@ SHADER_VERSION
|
|||
"uniform sampler2DMS uMSTex1; \n"
|
||||
"uniform lowp ivec2 uMSTexEnabled; \n"
|
||||
#endif
|
||||
#ifdef GL_UNIFORMBLOCK_SUPPORT
|
||||
"layout (std140) uniform ColorsBlock {\n"
|
||||
" lowp vec4 uFogColor; \n"
|
||||
" lowp vec4 uCenterColor; \n"
|
||||
|
@ -179,6 +190,17 @@ SHADER_VERSION
|
|||
" lowp float uK4; \n"
|
||||
" lowp float uK5; \n"
|
||||
"}; \n"
|
||||
#else
|
||||
"uniform lowp vec4 uFogColor; \n"
|
||||
"uniform lowp vec4 uCenterColor;\n"
|
||||
"uniform lowp vec4 uScaleColor; \n"
|
||||
"uniform lowp vec4 uBlendColor; \n"
|
||||
"uniform lowp vec4 uEnvColor; \n"
|
||||
"uniform lowp vec4 uPrimColor; \n"
|
||||
"uniform lowp float uPrimLod; \n"
|
||||
"uniform lowp float uK4; \n"
|
||||
"uniform lowp float uK5; \n"
|
||||
#endif // GL_UNIFORMBLOCK_SUPPORT
|
||||
#ifdef GLESX
|
||||
"uniform mediump vec2 uScreenScale; \n"
|
||||
#endif
|
||||
|
@ -205,6 +227,7 @@ SHADER_VERSION
|
|||
|
||||
static const char* fragment_shader_header_common_variables_notex =
|
||||
SHADER_VERSION
|
||||
#ifdef GL_UNIFORMBLOCK_SUPPORT
|
||||
"layout (std140) uniform ColorsBlock {\n"
|
||||
" lowp vec4 uFogColor; \n"
|
||||
" lowp vec4 uCenterColor; \n"
|
||||
|
@ -216,6 +239,17 @@ SHADER_VERSION
|
|||
" lowp float uK4; \n"
|
||||
" lowp float uK5; \n"
|
||||
"}; \n"
|
||||
#else
|
||||
"uniform lowp vec4 uFogColor; \n"
|
||||
"uniform lowp vec4 uCenterColor;\n"
|
||||
"uniform lowp vec4 uScaleColor; \n"
|
||||
"uniform lowp vec4 uBlendColor; \n"
|
||||
"uniform lowp vec4 uEnvColor; \n"
|
||||
"uniform lowp vec4 uPrimColor; \n"
|
||||
"uniform lowp float uPrimLod; \n"
|
||||
"uniform lowp float uK4; \n"
|
||||
"uniform lowp float uK5; \n"
|
||||
#endif // GL_UNIFORMBLOCK_SUPPORT
|
||||
#ifdef GLESX
|
||||
"uniform mediump vec2 uScreenScale; \n"
|
||||
#endif
|
||||
|
@ -265,10 +299,15 @@ static const char* fragment_shader_calc_light =
|
|||
#ifndef GLESX
|
||||
SHADER_VERSION
|
||||
#endif
|
||||
"layout (std140) uniform LightBlock { \n"
|
||||
" mediump vec3 uLightDirection[8]; \n"
|
||||
" lowp vec3 uLightColor[8]; \n"
|
||||
"}; \n"
|
||||
#ifdef GL_UNIFORMBLOCK_SUPPORT
|
||||
"layout (std140) uniform LightBlock { \n"
|
||||
" mediump vec3 uLightDirection[8]; \n"
|
||||
" lowp vec3 uLightColor[8]; \n"
|
||||
"}; \n"
|
||||
#else
|
||||
"uniform mediump vec3 uLightDirection[8]; \n"
|
||||
"uniform lowp vec3 uLightColor[8]; \n"
|
||||
#endif // GL_UNIFORMBLOCK_SUPPORT
|
||||
"void calc_light(in lowp float fLights, in lowp vec3 input_color, out lowp vec3 output_color) {\n"
|
||||
" output_color = input_color; \n"
|
||||
" lowp int nLights = int(floor(fLights + 0.5)); \n"
|
||||
|
|
Loading…
Reference in New Issue
Block a user