1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Fix verious GL errors in GLES 3.1 mode and Mario tennis.

This commit is contained in:
Francisco Zurita 2016-10-28 00:15:49 -04:00 committed by Sergey Lipskiy
parent 428f3ad637
commit df366f0f6b
7 changed files with 68 additions and 51 deletions

View File

@ -146,7 +146,7 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture
if (_multisample) {
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _pTexture->glName);
#if defined(GLES3_1)
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, _pTexture->realWidth, _pTexture->realHeight, false);
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT24, _pTexture->realWidth, _pTexture->realHeight, false);
#else
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, _pTexture->realWidth, _pTexture->realHeight, false);
#endif

View File

@ -54,7 +54,7 @@ void FBOTextureFormats::init()
depthImageFormatBytes = 16;
lutInternalFormat = GL_R32UI;
lutFormat = GL_RED;
lutFormat = GL_RED_INTEGER;
lutType = GL_UNSIGNED_INT;
lutFormatBytes = 4;
#else

View File

@ -736,7 +736,7 @@ void FrameBufferList::attachDepthBuffer()
pDepthBuffer->initDepthImageTexture(m_pCurrent);
pDepthBuffer->initDepthBufferTexture(m_pCurrent);
#ifndef USE_DEPTH_RENDERBUFFER
#ifdef GLES2
#ifdef GLESX
if (pDepthBuffer->m_pDepthBufferTexture->realWidth == m_pCurrent->m_pTexture->realWidth) {
#else
if (pDepthBuffer->m_pDepthBufferTexture->realWidth >= m_pCurrent->m_pTexture->realWidth) {

View File

@ -142,10 +142,10 @@ void InitZlutTexture()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.lutInternalFormat,
512, 512, 0, fboFormats.lutFormat, fboFormats.lutType,
zLUT);
glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
//glBindImageTexture requires an immutable texture object, glTexStorage2D does this
glTexStorage2D(GL_TEXTURE_2D, 1, fboFormats.lutInternalFormat, 512, 512);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 512, fboFormats.lutFormat, fboFormats.lutType, zLUT);
glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, fboFormats.lutInternalFormat);
}
static
@ -153,7 +153,8 @@ void DestroyZlutTexture()
{
if (!video().getRender().isImageTexturesSupported())
return;
glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, fboFormats.lutInternalFormat);
if (g_zlut_tex > 0) {
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTextures(1, &g_zlut_tex);

View File

@ -743,53 +743,59 @@ MAIN_SHADER_VERSION
// 3 point texture filtering.
// Original author: ArthurCarvalho
// GLSL implementation: twinaphex, mupen64plus-libretro project.
"#define TEX_OFFSET(off) texture(tex, texCoord - (off)/texSize) \n"
"lowp vec4 texFilter(in sampler2D tex, in mediump vec2 texCoord) \n"
"{ \n"
" mediump vec2 texSize = vec2(textureSize(tex,0)); \n"
" mediump vec2 texelSize = vec2(1.0) / texSize; \n"
" lowp vec4 c = texture(tex, texCoord); \n"
" if (abs(texCoord.s - uTextureBounds[0]) < texelSize.x || abs(texCoord.s - uTextureBounds[2]) < texelSize.x) return c; \n"
" if (abs(texCoord.t - uTextureBounds[1]) < texelSize.y || abs(texCoord.t - uTextureBounds[3]) < texelSize.y) return c; \n"
" \n"
" mediump vec2 offset = fract(texCoord*texSize - vec2(0.5)); \n"
" offset -= step(1.0, offset.x + offset.y); \n"
" lowp vec4 zero = vec4(0.0); \n"
" lowp vec4 c0 = TEX_OFFSET(offset); \n"
" lowp vec4 c1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y)); \n"
" lowp vec4 c2 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y))); \n"
" return c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0); \n"
"} \n"
"#define TEX_OFFSET(off, tex, texCoord, texSize) texture(tex, texCoord - (off)/texSize) \n"
"#define TEX_FILTER(name, tex, texCoord) \\\n"
"{ \\\n"
" mediump vec2 texSize = vec2(textureSize(tex,0)); \\\n"
" mediump vec2 texelSize = vec2(1.0) / texSize; \\\n"
" lowp vec4 c = texture(tex, texCoord); \\\n"
" if (abs(texCoord.s - uTextureBounds[0]) < texelSize.x || abs(texCoord.s - uTextureBounds[2]) < texelSize.x){ \\\n"
" name = c; \\\n"
" } else if (abs(texCoord.t - uTextureBounds[1]) < texelSize.y || abs(texCoord.t - uTextureBounds[3]) < texelSize.y){ \\\n"
" name = c; \\\n"
" } else { \\\n"
" mediump vec2 offset = fract(texCoord*texSize - vec2(0.5)); \\\n"
" offset -= step(1.0, offset.x + offset.y); \\\n"
" lowp vec4 zero = vec4(0.0); \\\n"
" lowp vec4 c0 = TEX_OFFSET(offset, tex, texCoord, texSize); \\\n"
" lowp vec4 c1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y), tex, texCoord, texSize); \\\n"
" lowp vec4 c2 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y)), tex, texCoord, texSize); \\\n"
" name = c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0); \\\n"
" } \\\n"
"} \\\n"
" \n"
;
const char * strTexrectDrawerTexBilinearFilter =
MAIN_SHADER_VERSION
"uniform mediump vec4 uTextureBounds; \n"
"#define TEX_OFFSET(off) texture(tex, texCoord - (off)/texSize) \n"
"lowp vec4 texFilter(in sampler2D tex, in mediump vec2 texCoord) \n"
"{ \n"
" mediump vec2 texSize = vec2(textureSize(tex,0)); \n"
" mediump vec2 texelSize = vec2(1.0) / texSize; \n"
" lowp vec4 c = texture(tex, texCoord); \n"
" if (abs(texCoord.s - uTextureBounds[0]) < texelSize.x || abs(texCoord.s - uTextureBounds[2]) < texelSize.x) return c; \n"
" if (abs(texCoord.t - uTextureBounds[1]) < texelSize.y || abs(texCoord.t - uTextureBounds[3]) < texelSize.y) return c; \n"
" \n"
" mediump vec2 offset = fract(texCoord*texSize - vec2(0.5)); \n"
" offset -= step(1.0, offset.x + offset.y); \n"
" lowp vec4 zero = vec4(0.0); \n"
" \n"
" lowp vec4 p0q0 = TEX_OFFSET(offset); \n"
" lowp vec4 p1q0 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y)); \n"
" \n"
" lowp vec4 p0q1 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y))); \n"
" lowp vec4 p1q1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y - sign(offset.y))); \n"
" \n"
" mediump vec2 interpolationFactor = abs(offset); \n"
" lowp vec4 pInterp_q0 = mix( p0q0, p1q0, interpolationFactor.x ); // Interpolates top row in X direction. \n"
" lowp vec4 pInterp_q1 = mix( p0q1, p1q1, interpolationFactor.x ); // Interpolates bottom row in X direction. \n"
" return mix( pInterp_q0, pInterp_q1, interpolationFactor.y ); // Interpolate in Y direction. \n"
"} \n"
"#define TEX_OFFSET(off, tex, texCoord, texSize) texture(tex, texCoord - (off)/texSize) \n"
"#define TEX_FILTER(name, tex, texCoord) \\\n"
"{ \\\n"
" mediump vec2 texSize = vec2(textureSize(tex,0)); \\\n"
" mediump vec2 texelSize = vec2(1.0) / texSize; \\\n"
" lowp vec4 c = texture(tex, texCoord); \\\n"
" if (abs(texCoord.s - uTextureBounds[0]) < texelSize.x || abs(texCoord.s - uTextureBounds[2]) < texelSize.x){ \\\n"
" name = c; \\\n"
" } else if (abs(texCoord.t - uTextureBounds[1]) < texelSize.y || abs(texCoord.t - uTextureBounds[3]) < texelSize.y){ \\\n"
" name = c; \\\n"
" } else { \\\n"
" mediump vec2 offset = fract(texCoord*texSize - vec2(0.5)); \\\n"
" offset -= step(1.0, offset.x + offset.y); \\\n"
" lowp vec4 zero = vec4(0.0); \\\n"
" \\\n"
" lowp vec4 p0q0 = TEX_OFFSET(offset, tex, texCoord, texSize); \\\n"
" lowp vec4 p1q0 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y), tex, texCoord, texSize); \\\n"
" \\\n"
" lowp vec4 p0q1 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y)), tex, texCoord, texSize); \\\n"
" lowp vec4 p1q1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y - sign(offset.y)), tex, texCoord, texSize); \\\n"
" \\\n"
" mediump vec2 interpolationFactor = abs(offset); \\\n"
" lowp vec4 pInterp_q0 = mix( p0q0, p1q0, interpolationFactor.x ); \\\n" // Interpolates top row in X direction.
" lowp vec4 pInterp_q1 = mix( p0q1, p1q1, interpolationFactor.x ); \\\n" // Interpolates bottom row in X direction.
" name = mix( pInterp_q0, pInterp_q1, interpolationFactor.y ); \\\n" // Interpolate in Y direction.
" } \\\n"
"} \\\n"
" \n"
;
@ -801,7 +807,7 @@ const char * strTexrectDrawerFragmentShaderTex =
"out lowp vec4 fragColor; \n"
"void main() \n"
"{ \n"
" fragColor = texFilter(uTex0, vTexCoord0); \n"
" TEX_FILTER(fragColor, uTex0, vTexCoord0); \n"
" if (fragColor == uTestColor) discard; \n"
" if (uEnableAlphaTest == 1 && !(fragColor.a > 0.0)) discard; \n"
"} \n"

View File

@ -63,11 +63,17 @@ GLuint createShaderProgram(const char * _strVertex, const char * _strFragment)
glCompileShader(vertex_shader_object);
assert(checkShaderCompileStatus(vertex_shader_object));
if (!checkShaderCompileStatus(vertex_shader_object))
logErrorShader(GL_VERTEX_SHADER, _strVertex);
GLuint fragment_shader_object = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader_object, 1, &_strFragment, nullptr);
glCompileShader(fragment_shader_object);
assert(checkShaderCompileStatus(fragment_shader_object));
if (!checkShaderCompileStatus(fragment_shader_object))
logErrorShader(GL_VERTEX_SHADER, _strFragment);
GLuint program = glCreateProgram();
glBindAttribLocation(program, SC_POSITION, "aPosition");
glBindAttribLocation(program, SC_TEXCOORD0, "aTexCoord0");

View File

@ -20,6 +20,8 @@
#include "Config.h"
#include "GLSLCombiner.h"
#include "ShaderUtils.h"
#include <FBOTextureFormats.h>
#include "Log.h"
struct point {
GLfloat x;
@ -45,8 +47,10 @@ struct point {
#ifdef GLES2
const GLenum monohromeformat = GL_LUMINANCE;
const GLenum monohromeInternalformat = GL_LUMINANCE;
#else
const GLenum monohromeformat = GL_RED;
const GLenum monohromeInternalformat = GL_R8;
#endif // GLES2
static
@ -153,7 +157,7 @@ struct Atlas {
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, monohromeformat, w, h, 0, monohromeformat, GL_UNSIGNED_BYTE, 0);
glTexImage2D(GL_TEXTURE_2D, 0, monohromeInternalformat, w, h, 0, monohromeformat, GL_UNSIGNED_BYTE, 0);
/* We require 1 byte alignment when uploading texture data */
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);