Permalink
Browse files

video-gliden64: Update to commit 5176e94.

gonetz/GLideN64@5176e94

* 5176e94 Fix screenshot capture when fb emulation enabled.
* 072553b Fix screen scale for LOD when multiple of native resolution is used.
* a2c39af Fixed crash in RDRAMtoFrameBuffer::CopyFromRDRAM in GLES2 mode.
* ff67350 Revert "Increase only y coordinate of rect in COPY or FILL mode." because it causes regression in Mischief Makers.
* 9d8ef24 Code refactor: use std::string instead of plain char buffer in compileCombiner.
* b7369e9 Correct alpha compare: - Take into account coverage flags.   This is still not quite correct without proper coverage emulation. - Discard pixels with zero alpha if uCvgXAlpha flag is set.   Resulted pixel coverage is function of pixel alpha multiplied by actual   coverage in that mode, thus pixel with zero alpha has zero coverage and discarded.
* 56f85e0 Fix OpenGL ES 3.0 plugin in Nexus 6p
* 913b0e7 Disable fog for Turbo3D ucode.
* 438f5e3 Adds noisy warning if we can't find Texture Image support
* 7fb2ad2 Fixing what is almost certainly a memory leak
* 675d777 Fix windowed modes list initialization in GUI.
* c504b9b Correct depth buffer removal: if depth buffer removed, clear pointers on it for all frame buffers.
  • Loading branch information...
1 parent a4dae34 commit 7b1aae75a6c5b3baac1f896622fe8ecb5884e421 @fzurita fzurita committed Mar 12, 2016
@@ -1749,7 +1749,6 @@ void RDRAMtoFrameBuffer::CopyFromRDRAM(u32 _address, bool _bCFB)
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
#else
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
- free(ptr);
#endif
m_pTexture->scaleS = 1.0f / (float)m_pTexture->realWidth;
@@ -145,7 +145,7 @@ void DestroyShaderCombiner() {
ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCombine & _combine) : m_combine(_combine)
{
- char strCombiner[1024];
+ std::string strCombiner;
m_nInputs = compileCombiner(_color, _alpha, strCombiner);
if (usesTexture()) {
@@ -179,6 +179,10 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
strFragmentShader.append(" vec_color = vec4(input_color, vShadeColor.a); \n");
strFragmentShader.append(strCombiner);
+ strFragmentShader.append(
+ " if (uCvgXAlpha != 0 && alpha2 == 0.0) discard; \n"
+ );
+
if (!g_weakGLSL) {
strFragmentShader.append(
" lowp int fogUsage = uFogUsage; \n"
@@ -253,6 +257,8 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uFogMode);
LocateUniform(uFogUsage);
LocateUniform(uAlphaCompareMode);
+ LocateUniform(uCvgXAlpha);
+ LocateUniform(uAlphaCvgSel);
LocateUniform(uEnableAlphaTest);
LocateUniform(uEnableDepth);
LocateUniform(uEnableDepthCompare)
@@ -482,28 +488,23 @@ void ShaderCombiner::updateDepthInfo(bool _bForce) {
void ShaderCombiner::updateAlphaTestInfo(bool _bForce) {
if (gDP.otherMode.cycleType == G_CYC_FILL) {
m_uniforms.uEnableAlphaTest.set(0, _bForce);
- m_uniforms.uAlphaTestValue.set(0.0f, _bForce);
} else if (gDP.otherMode.cycleType == G_CYC_COPY) {
if (gDP.otherMode.alphaCompare & G_AC_THRESHOLD) {
m_uniforms.uEnableAlphaTest.set(1, _bForce);
+ m_uniforms.uAlphaCvgSel.set(0, _bForce);
m_uniforms.uAlphaTestValue.set(0.5f, _bForce);
} else {
m_uniforms.uEnableAlphaTest.set(0, _bForce);
- m_uniforms.uAlphaTestValue.set(0.0f, _bForce);
}
- } else if (((gDP.otherMode.alphaCompare & G_AC_THRESHOLD) != 0) && (gDP.otherMode.alphaCvgSel == 0) && (gDP.otherMode.forceBlender == 0 || gDP.blendColor.a > 0)) {
+ } else if ((gDP.otherMode.alphaCompare & G_AC_THRESHOLD) != 0) {
m_uniforms.uEnableAlphaTest.set(1, _bForce);
- m_uniforms.uAlphaTestValue.set(max(gDP.blendColor.a, 1.0f / 256.0f), _bForce);
- } else if ((gDP.otherMode.alphaCompare == G_AC_DITHER) && (gDP.otherMode.alphaCvgSel == 0)) {
- m_uniforms.uEnableAlphaTest.set(1, _bForce);
- m_uniforms.uAlphaTestValue.set(0.0f, _bForce);
- } else if (gDP.otherMode.cvgXAlpha != 0) {
- m_uniforms.uEnableAlphaTest.set(1, _bForce);
- m_uniforms.uAlphaTestValue.set(0.125f, _bForce);
+ m_uniforms.uAlphaTestValue.set(gDP.blendColor.a, _bForce);
+ m_uniforms.uAlphaCvgSel.set(gDP.otherMode.alphaCvgSel, _bForce);
} else {
m_uniforms.uEnableAlphaTest.set(0, _bForce);
- m_uniforms.uAlphaTestValue.set(0.0f, _bForce);
}
+
+ m_uniforms.uCvgXAlpha.set(gDP.otherMode.cvgXAlpha, _bForce);
}
void SetMonochromeCombiner() {
@@ -166,6 +166,8 @@ SHADER_VERSION
"uniform lowp ivec2 uFbFixedAlpha;\n"
"uniform lowp int uSpecialBlendMode;\n"
"uniform lowp int uEnableAlphaTest; \n"
+"uniform lowp int uCvgXAlpha; \n"
+"uniform lowp int uAlphaCvgSel; \n"
"uniform lowp float uAlphaTestValue;\n"
"uniform mediump vec2 uDepthScale; \n"
"IN lowp vec4 vShadeColor; \n"
@@ -202,6 +204,8 @@ SHADER_VERSION
"uniform lowp int uFogUsage; \n"
"uniform lowp int uSpecialBlendMode;\n"
"uniform lowp int uEnableAlphaTest; \n"
+"uniform lowp int uCvgXAlpha; \n"
+"uniform lowp int uAlphaCvgSel; \n"
"uniform lowp float uAlphaTestValue;\n"
"uniform mediump vec2 uDepthScale; \n"
"IN lowp vec4 vShadeColor; \n"
@@ -96,7 +96,8 @@ class ShaderCombiner {
uEnableDepth, uEnableDepthCompare, uEnableDepthUpdate,
uDepthMode, uDepthSource, uRenderState, uSpecialBlendMode,
uMaxTile, uTextureDetail, uTexturePersp, uTextureFilterMode, uMSAASamples,
- uAlphaCompareMode, uAlphaDitherMode, uColorDitherMode;
+ uAlphaCompareMode, uAlphaDitherMode, uColorDitherMode,
+ uCvgXAlpha, uAlphaCvgSel;
fUniform uFogAlpha, uMinLod, uDeltaZ, uAlphaTestValue, uMSAAScale;
@@ -31,7 +31,6 @@
#include <zlib.h>
#include <memory.h>
#include <stdlib.h>
-#include "../Log.h"
TxCache::~TxCache()
{
@@ -308,8 +307,6 @@ TxCache::save(const wchar_t *path, const wchar_t *filename, int config)
boolean
TxCache::load(const wchar_t *path, const wchar_t *filename, int config)
{
- LOG(LOG_ERROR, "Loading!!! Path: %ls/%ls, config=0x%x", path, filename, config);
-
/* find it on disk */
char cbuf[MAX_PATH];
@@ -327,7 +324,7 @@ TxCache::load(const wchar_t *path, const wchar_t *filename, int config)
wcstombs(cbuf, filename, MAX_PATH);
gzFile gzfp = gzopen(cbuf, "rb");
- LOG(LOG_ERROR, "gzfp:%x file:%ls\n", gzfp, filename);
+ DBG_INFO(80, wst("gzfp:%x file:%ls\n"), gzfp, filename);
if (gzfp) {
/* yep, we have it. load it into memory cache. */
int dataSize;
@@ -336,11 +333,7 @@ TxCache::load(const wchar_t *path, const wchar_t *filename, int config)
/* read header to determine config match */
gzread(gzfp, &tmpconfig, 4);
- LOG(LOG_ERROR, "Loading high res textures file_config=0x%x, current_config=0x%x",tmpconfig, config);
-
if (tmpconfig == config) {
-
-
do {
GHQTexInfo tmpInfo;
@@ -370,6 +363,7 @@ TxCache::load(const wchar_t *path, const wchar_t *filename, int config)
/* skip in between to prevent the loop from being tied down to vsync */
if (_callback && (!(_cache.size() % 100) || gzeof(gzfp)))
(*_callback)(wst("[%d] total mem:%.02fmb - %ls\n"), _cache.size(), (float)_totalSize/1000000, filename);
+
} while (!gzeof(gzfp));
gzclose(gzfp);
}
@@ -52,7 +52,6 @@
#include <math.h>
#include <stdlib.h>
#include <string.h>
-#include "../Log.h"
TxHiResCache::~TxHiResCache()
{
@@ -98,7 +97,6 @@ TxHiResCache::TxHiResCache(int maxwidth, int maxheight, int maxbpp, int options,
}
#if DUMP_CACHE
-
/* read in hires texture cache */
if (_options & DUMP_HIRESTEXCACHE) {
/* find it on disk */
@@ -108,8 +106,6 @@ TxHiResCache::TxHiResCache(int maxwidth, int maxheight, int maxbpp, int options,
cachepath += wst("cache");
int config = _options & (HIRESTEXTURES_MASK|TILE_HIRESTEX|FORCE16BPP_HIRESTEX|GZ_HIRESTEXCACHE|LET_TEXARTISTS_FLY);
- LOG(LOG_ERROR, "config=0x%x, options=0x%x", config, _options);
-
_haveCache = TxCache::load(cachepath.c_str(), filename.c_str(), config);
}
#endif
@@ -282,19 +282,58 @@ ShaderCombiner::ShaderCombiner() : m_bNeedUpdate(true)
ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCombine & _combine) : m_combine(_combine), m_bNeedUpdate(true)
{
- char strCombiner[1024];
+ std::string strCombiner;
m_nInputs = compileCombiner(_color, _alpha, strCombiner);
+ const bool bUseLod = usesLOD();
+ const bool bUseHWLight = config.generalEmulation.enableHWLighting != 0 && GBI.isHWLSupported() && usesShadeColor();
+
if (usesTexture()) {
strFragmentShader.assign(fragment_shader_header_common_variables);
- strFragmentShader.append(fragment_shader_header_common_functions);
- }
- else {
+
+#ifdef GL_MULTISAMPLING_SUPPORT
+ if (config.video.multisampling > 0) {
+ strFragmentShader.append(fragment_shader_header_common_variables_ms_enabled);
+ if(usesTile(0))
+ strFragmentShader.append(fragment_shader_header_common_variables_ms_tex0);
+ if(usesTile(1))
+ strFragmentShader.append(fragment_shader_header_common_variables_ms_tex1);
+ }
+#endif
+
+ strFragmentShader.append(fragment_shader_header_noise);
+ strFragmentShader.append(fragment_shader_header_noise_dither);
+
+ if (bUseLod)
+ strFragmentShader.append(fragment_shader_header_mipmap);
+ else {
+ strFragmentShader.append(fragment_shader_header_readTex);
+#ifdef GL_MULTISAMPLING_SUPPORT
+ if (config.video.multisampling > 0)
+ strFragmentShader.append(fragment_shader_header_readTexMS);
+#endif
+ }
+#ifdef GL_IMAGE_TEXTURES_SUPPORT
+ if (video().getRender().isImageTexturesSupported() && config.frameBufferEmulation.N64DepthCompare != 0)
+ strFragmentShader.append(fragment_shader_header_depth_compare);
+#endif
+
+ } else {
strFragmentShader.assign(fragment_shader_header_common_variables_notex);
- strFragmentShader.append(fragment_shader_header_common_functions_notex);
+ strFragmentShader.append(fragment_shader_header_noise);
+ strFragmentShader.append(fragment_shader_header_noise_dither);
+
+#ifdef GL_IMAGE_TEXTURES_SUPPORT
+ if (video().getRender().isImageTexturesSupported() && config.frameBufferEmulation.N64DepthCompare != 0)
+ strFragmentShader.append(fragment_shader_header_depth_compare);
+#endif
+
}
+
+ if (bUseHWLight)
+ strFragmentShader.append(fragment_shader_header_calc_light);
+
strFragmentShader.append(fragment_shader_header_main);
- const bool bUseLod = usesLOD();
if (bUseLod) {
strFragmentShader.append(" lowp vec4 readtex0, readtex1; \n");
strFragmentShader.append(" lowp float lod_frac = mipmap(readtex0, readtex1); \n");
@@ -323,14 +362,17 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
strFragmentShader.append(" lowp vec4 readtex1 = readTex(uTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1] != 0); \n");
#endif // GL_MULTISAMPLING_SUPPORT
}
- const bool bUseHWLight = config.generalEmulation.enableHWLighting != 0 && GBI.isHWLSupported() && usesShadeColor();
if (bUseHWLight)
strFragmentShader.append(" calc_light(vNumLights, vShadeColor.rgb, input_color); \n");
else
strFragmentShader.append(" input_color = vShadeColor.rgb;\n");
strFragmentShader.append(" vec_color = vec4(input_color, vShadeColor.a); \n");
strFragmentShader.append(strCombiner);
+ strFragmentShader.append(
+ " if (uCvgXAlpha != 0 && alpha2 == 0.0) discard; \n"
+ );
+
if (config.generalEmulation.enableNoise != 0) {
strFragmentShader.append(
" if (uColorDitherMode == 2) colorNoiseDither(snoise(), color2); \n"
@@ -390,26 +432,8 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
const GLchar * strShaderData = strFragmentShader.data();
glShaderSource(fragmentShader, 1, &strShaderData, NULL);
glCompileShader(fragmentShader);
- if (!checkShaderCompileStatus(fragmentShader))
- {
- int pos = 0;
- int max = 900;
- LOG(LOG_ERROR, "Error in fragment shader");
-
- while(pos < strFragmentShader.length() )
- {
- if(strFragmentShader.length() - pos < max)
- {
- LOG(LOG_ERROR, "%s", strFragmentShader.substr(pos).data());
- }
- else
- {
- LOG(LOG_ERROR, "%s", strFragmentShader.substr(pos, max).data());
- }
-
- pos += max;
- }
- }
+ if (!checkShaderCompileStatus(fragmentShader))
+ logErrorShader(GL_FRAGMENT_SHADER, strFragmentShader);
m_program = glCreateProgram();
_locate_attributes();
@@ -464,6 +488,8 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uAlphaCompareMode);
LocateUniform(uAlphaDitherMode);
LocateUniform(uColorDitherMode);
+ LocateUniform(uCvgXAlpha);
+ LocateUniform(uAlphaCvgSel);
LocateUniform(uEnableLod);
LocateUniform(uEnableAlphaTest);
LocateUniform(uEnableDepth);
@@ -654,7 +680,10 @@ void ShaderCombiner::updateLOD(bool _bForce)
if (config.generalEmulation.enableLOD != 0) {
const int uCalcLOD = (gDP.otherMode.textureLOD == G_TL_LOD) ? 1 : 0;
m_uniforms.uEnableLod.set(uCalcLOD, _bForce);
- m_uniforms.uScreenScale.set(video().getScaleX(), video().getScaleY(), _bForce);
+ if (config.frameBufferEmulation.nativeResFactor == 0)
+ m_uniforms.uScreenScale.set(video().getScaleX(), video().getScaleY(), _bForce);
+ else
+ m_uniforms.uScreenScale.set(float(config.frameBufferEmulation.nativeResFactor), float(config.frameBufferEmulation.nativeResFactor), _bForce);
m_uniforms.uTextureDetail.set(gDP.otherMode.textureDetail, _bForce);
}
}
@@ -729,28 +758,23 @@ void ShaderCombiner::updateDepthInfo(bool _bForce) {
void ShaderCombiner::updateAlphaTestInfo(bool _bForce) {
if (gDP.otherMode.cycleType == G_CYC_FILL) {
m_uniforms.uEnableAlphaTest.set(0, _bForce);
- m_uniforms.uAlphaTestValue.set(0.0f, _bForce);
} else if (gDP.otherMode.cycleType == G_CYC_COPY) {
if (gDP.otherMode.alphaCompare & G_AC_THRESHOLD) {
m_uniforms.uEnableAlphaTest.set(1, _bForce);
+ m_uniforms.uAlphaCvgSel.set(0, _bForce);
m_uniforms.uAlphaTestValue.set(0.5f, _bForce);
} else {
m_uniforms.uEnableAlphaTest.set(0, _bForce);
- m_uniforms.uAlphaTestValue.set(0.0f, _bForce);
}
- } else if (((gDP.otherMode.alphaCompare & G_AC_THRESHOLD) != 0) && (gDP.otherMode.alphaCvgSel == 0) && (gDP.otherMode.forceBlender == 0 || gDP.blendColor.a > 0)) {
- m_uniforms.uEnableAlphaTest.set(1, _bForce);
- m_uniforms.uAlphaTestValue.set(max(gDP.blendColor.a, 1.0f / 256.0f), _bForce);
- } else if ((gDP.otherMode.alphaCompare == G_AC_DITHER) && (gDP.otherMode.alphaCvgSel == 0)) {
+ } else if ((gDP.otherMode.alphaCompare & G_AC_THRESHOLD) != 0) {
m_uniforms.uEnableAlphaTest.set(1, _bForce);
- m_uniforms.uAlphaTestValue.set(0.0f, _bForce);
- } else if (gDP.otherMode.cvgXAlpha != 0) {
- m_uniforms.uEnableAlphaTest.set(1, _bForce);
- m_uniforms.uAlphaTestValue.set(0.125f, _bForce);
+ m_uniforms.uAlphaTestValue.set(gDP.blendColor.a, _bForce);
+ m_uniforms.uAlphaCvgSel.set(gDP.otherMode.alphaCvgSel, _bForce);
} else {
m_uniforms.uEnableAlphaTest.set(0, _bForce);
- m_uniforms.uAlphaTestValue.set(0.0f, _bForce);
}
+
+ m_uniforms.uCvgXAlpha.set(gDP.otherMode.cvgXAlpha, _bForce);
}
std::ostream & operator<< (std::ostream & _os, const ShaderCombiner & _combiner)
Oops, something went wrong.

0 comments on commit 7b1aae7

Please sign in to comment.