1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-06-25 05:49:34 +00:00

Replace ShaderCombiner by graphics::CombinerProgram WIP

This commit is contained in:
Sergey Lipskiy 2017-01-05 17:55:01 +07:00
parent 1d706e1fd1
commit 9725c527b9
8 changed files with 60 additions and 27 deletions

View File

@ -285,7 +285,7 @@ void RDRAMtoColorBuffer::copyFromRDRAM(u32 _address, bool _bCFB)
gDP.otherMode.cycleType = cycleType;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
currentCombiner()->updateFrameBufferInfo();
// currentCombiner()->updateFrameBufferInfo();
glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);

View File

@ -12,6 +12,8 @@
#include "Config.h"
#include "PluginAPI.h"
#include "RSP.h"
#include "Graphics/Context.h"
#include "Graphics/CombinerProgram.h"
static int saRGBExpanded[] =
{
@ -191,7 +193,8 @@ void SimplifyCycle( CombineCycle *cc, CombinerStage *stage )
}
}
ShaderCombiner * CombinerInfo::_compile(u64 mux) const
//ShaderCombiner * CombinerInfo::_compile(u64 mux) const
graphics::CombinerProgram * CombinerInfo::_compile(u64 mux) const
{
gDPCombine combine;
@ -245,7 +248,8 @@ ShaderCombiner * CombinerInfo::_compile(u64 mux) const
}
}
return new ShaderCombiner( color, alpha, combine );
// return new ShaderCombiner( color, alpha, combine );
return gfxContext.createCombinerProgram(color, alpha, CombinerKey(combine.mux));
}
void CombinerInfo::update()
@ -267,17 +271,17 @@ void CombinerInfo::setCombine(u64 _mux )
const CombinerKey key(_mux);
if (m_pCurrent != nullptr && m_pCurrent->getKey() == key) {
m_bChanged = false;
m_pCurrent->update(false);
// m_pCurrent->update(false);
return;
}
Combiners::const_iterator iter = m_combiners.find(key);
if (iter != m_combiners.end()) {
m_pCurrent = iter->second;
m_pCurrent->update(false);
// m_pCurrent->update(false);
} else {
m_pCurrent = _compile(_mux);
m_pCurrent->update(true);
m_pUniformCollection->bindWithShaderCombiner(m_pCurrent);
// m_pUniformCollection->bindWithShaderCombiner(m_pCurrent);
m_combiners[m_pCurrent->getKey()] = m_pCurrent;
}
m_bChanged = true;
@ -285,36 +289,42 @@ void CombinerInfo::setCombine(u64 _mux )
void CombinerInfo::updatePrimColor()
{
return;
if (m_pUniformCollection != nullptr)
m_pUniformCollection->setColorData(UniformCollection::cuPrimColor, sizeof(f32)* 5, &gDP.primColor.r);
}
void CombinerInfo::updateEnvColor()
{
return;
if (m_pUniformCollection != nullptr)
m_pUniformCollection->setColorData(UniformCollection::cuEnvColor, sizeof(f32)* 4, &gDP.envColor.r);
}
void CombinerInfo::updateFogColor()
{
return;
if (m_pUniformCollection != nullptr)
m_pUniformCollection->setColorData(UniformCollection::cuFogColor, sizeof(f32)* 4, &gDP.fogColor.r);
}
void CombinerInfo::updateBlendColor()
{
return;
if (m_pUniformCollection != nullptr)
m_pUniformCollection->setColorData(UniformCollection::cuBlendColor, sizeof(f32)* 4, &gDP.blendColor.r);
}
void CombinerInfo::updateKeyColor()
{
return;
if (m_pUniformCollection != nullptr)
m_pUniformCollection->setColorData(UniformCollection::cuCenterColor, sizeof(f32)* 8, &gDP.key.center.r);
}
void CombinerInfo::updateConvertColor()
{
return;
if (m_pUniformCollection == nullptr)
return;
f32 convert[2] = { gDP.convert.k4*0.0039215689f, gDP.convert.k5*0.0039215689f };
@ -323,12 +333,14 @@ void CombinerInfo::updateConvertColor()
void CombinerInfo::updateTextureParameters()
{
return;
if (m_pUniformCollection != nullptr)
m_pUniformCollection->updateTextureParameters();
}
void CombinerInfo::updateLightParameters()
{
return;
if (config.generalEmulation.enableHWLighting != 0) {
if (m_pUniformCollection != nullptr)
m_pUniformCollection->updateLightParameters();
@ -338,8 +350,9 @@ void CombinerInfo::updateLightParameters()
void CombinerInfo::updateParameters(OGLRender::RENDER_STATE _renderState)
{
if (m_pUniformCollection != nullptr)
m_pUniformCollection->updateUniforms(m_pCurrent, _renderState);
// if (m_pUniformCollection != nullptr)
// m_pUniformCollection->updateUniforms(m_pCurrent, _renderState);
m_pCurrent->update(false);
}
void CombinerInfo::setPolygonMode(OGLRender::RENDER_STATE _renderState)
@ -487,10 +500,11 @@ bool CombinerInfo::_loadShadersStorage()
fin.read((char*)&len, sizeof(len));
for (u32 i = 0; i < len; ++i) {
m_pCurrent = new ShaderCombiner();
// TODO implement
// m_pCurrent = new ShaderCombiner();
fin >> *m_pCurrent;
m_pCurrent->update(true);
m_pUniformCollection->bindWithShaderCombiner(m_pCurrent);
// m_pUniformCollection->bindWithShaderCombiner(m_pCurrent);
m_combiners[m_pCurrent->getKey()] = m_pCurrent;
}
}

View File

@ -114,6 +114,10 @@ struct CombineCycle
int sa, sb, m, a;
};
namespace graphics {
class CombinerProgram;
}
class ShaderCombiner;
class UniformCollection;
class CombinerInfo
@ -124,7 +128,8 @@ public:
void update();
void setCombine(u64 _mux);
ShaderCombiner * getCurrent() const {return m_pCurrent;}
// ShaderCombiner * getCurrent() const {return m_pCurrent;}
graphics::CombinerProgram * getCurrent() const { return m_pCurrent; }
bool isChanged() const {return m_bChanged;}
bool isShaderCacheSupported() const { return m_bShaderCacheSupported; }
size_t getCombinersNumber() const { return m_combiners.size(); }
@ -159,7 +164,8 @@ private:
void _saveShadersStorage() const;
bool _loadShadersStorage();
u32 _getConfigOptionsBitSet() const;
ShaderCombiner * _compile(u64 mux) const;
//ShaderCombiner * _compile(u64 mux) const;
graphics::CombinerProgram * _compile(u64 mux) const;
bool m_bChanged;
bool m_bShaderCacheSupported;
@ -167,14 +173,17 @@ private:
u32 m_shadersLoaded;
u32 m_configOptionsBitSet;
ShaderCombiner * m_pCurrent;
typedef std::map<CombinerKey, ShaderCombiner *> Combiners;
// ShaderCombiner * m_pCurrent;
// typedef std::map<CombinerKey, ShaderCombiner *> Combiners;
graphics::CombinerProgram * m_pCurrent;
typedef std::map<CombinerKey, graphics::CombinerProgram *> Combiners;
Combiners m_combiners;
UniformCollection * m_pUniformCollection;
};
inline
ShaderCombiner * currentCombiner() {
//ShaderCombiner * currentCombiner() {
graphics::CombinerProgram * currentCombiner() {
return CombinerInfo::get().getCurrent();
}

View File

@ -1847,7 +1847,7 @@ graphics::CombinerProgram * CombinerProgramBuilder::buildCombinerProgram(Combine
UniformGroups uniforms;
m_uniformFactory->buildUniforms(program, combinerInputs, bIsRect, uniforms);
return new CombinerProgramImpl(program, combinerInputs, std::move(uniforms));
return new CombinerProgramImpl(_key, program, combinerInputs, std::move(uniforms));
}
static

View File

@ -3,8 +3,12 @@
using namespace glsl;
CombinerProgramImpl::CombinerProgramImpl(GLuint _program, const CombinerInputs & _inputs, UniformGroups && _uniforms)
CombinerProgramImpl::CombinerProgramImpl(const CombinerKey & _key,
GLuint _program,
const CombinerInputs & _inputs,
UniformGroups && _uniforms)
: m_bNeedUpdate(true)
, m_key(_key)
, m_program(_program)
, m_inputs(_inputs)
, m_uniforms(std::move(_uniforms))
@ -32,7 +36,7 @@ void CombinerProgramImpl::update(bool _force)
CombinerKey CombinerProgramImpl::getKey() const
{
return CombinerKey();
return m_key;
}
bool CombinerProgramImpl::usesTexture() const

View File

@ -17,7 +17,10 @@ namespace glsl {
class CombinerProgramImpl : public graphics::CombinerProgram
{
public:
CombinerProgramImpl(GLuint _program, const CombinerInputs & _inputs, UniformGroups && _uniforms);
CombinerProgramImpl(const CombinerKey & _key,
GLuint _program,
const CombinerInputs & _inputs,
UniformGroups && _uniforms);
~CombinerProgramImpl();
void activate() override;
@ -31,6 +34,7 @@ namespace glsl {
private:
bool m_bNeedUpdate;
CombinerKey m_key;
GLuint m_program;
CombinerInputs m_inputs;
UniformGroups m_uniforms;

View File

@ -277,7 +277,7 @@ void InitShaderCombiner()
g_dither_shader_object = _createShader(GL_FRAGMENT_SHADER, fragment_shader_dither);
#endif // GLESX
noiseTex.init();
// noiseTex.init();
g_monochrome_image_program = createRectShaderProgram(vertex_shader_rect_nocolor, zelda_monochrome_fragment_shader);
glUseProgram(g_monochrome_image_program);
const int texLoc = glGetUniformLocation(g_monochrome_image_program, "uColorImage");

View File

@ -1176,7 +1176,8 @@ void OGLRender::_updateTextures(RENDER_STATE _renderState) const
{
//For some reason updating the texture cache on the first frame of LOZ:OOT causes a nullptr Pointer exception...
CombinerInfo & cmbInfo = CombinerInfo::get();
ShaderCombiner * pCurrentCombiner = cmbInfo.getCurrent();
//ShaderCombiner * pCurrentCombiner = cmbInfo.getCurrent();
graphics::CombinerProgram * pCurrentCombiner = cmbInfo.getCurrent();
if (pCurrentCombiner != nullptr) {
for (u32 t = 0; t < 2; ++t) {
if (pCurrentCombiner->usesTile(t))
@ -1316,7 +1317,7 @@ void OGLRender::_prepareDrawTriangle(bool _dma)
_setColorArray();
_setTexCoordArrays();
}
currentCombiner()->updateRenderState();
// currentCombiner()->updateRenderState();
bool bFlatColors = false;
if (!RSP.bLLE && (gSP.geometryMode & G_LIGHTING) == 0) {
@ -1522,7 +1523,7 @@ void OGLRender::drawLine(int _v0, int _v1, float _width)
glVertexAttribPointer(SC_MODIFY, 4, GL_BYTE, GL_FALSE, sizeof(SPVertex), &triangles.vertices[0].modify);
m_renderState = rsLine;
currentCombiner()->updateRenderState();
// currentCombiner()->updateRenderState();
}
if ((triangles.vertices[_v0].modify & MODIFY_XY) != 0)
@ -1553,7 +1554,7 @@ void OGLRender::drawRect(int _ulx, int _uly, int _lrx, int _lry, float *_pColor)
if (updateArrays)
glVertexAttribPointer(SC_RECT_POSITION, 4, GL_FLOAT, GL_FALSE, sizeof(GLVertex), &m_rect[0].x);
currentCombiner()->updateRenderState();
// currentCombiner()->updateRenderState();
FrameBuffer * pCurrentBuffer = frameBufferList().getCurrent();
OGLVideo & ogl = video();
@ -1764,7 +1765,7 @@ void OGLRender::drawTexturedRect(const TexturedRectParams & _params)
CombinerInfo & cmbInfo = CombinerInfo::get();
cmbInfo.setPolygonMode(rsTexRect);
cmbInfo.update();
currentCombiner()->updateRenderState();
// currentCombiner()->updateRenderState();
_updateTextures(rsTexRect);
cmbInfo.updateParameters(rsTexRect);
if (CombinerInfo::get().isChanged())
@ -1797,7 +1798,7 @@ void OGLRender::drawTexturedRect(const TexturedRectParams & _params)
glVertexAttribPointer(SC_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), &m_rect[0].s0);
glVertexAttribPointer(SC_TEXCOORD1, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), &m_rect[0].s1);
}
currentCombiner()->updateRenderState();
// currentCombiner()->updateRenderState();
if (_params.texrectCmd && texturedRectSpecial != nullptr && texturedRectSpecial(_params)) {
gSP.changed |= CHANGED_GEOMETRYMODE;
@ -1808,7 +1809,8 @@ void OGLRender::drawTexturedRect(const TexturedRectParams & _params)
return;
}
ShaderCombiner * pCurrentCombiner = currentCombiner();
// ShaderCombiner * pCurrentCombiner = currentCombiner();
graphics::CombinerProgram * pCurrentCombiner = currentCombiner();
const FrameBuffer * pCurrentBuffer = _params.pBuffer;
OGLVideo & ogl = video();
TextureCache & cache = textureCache();