Only set fogdepth to highp on PowerVR. May fix #4333

This commit is contained in:
Henrik Rydgård 2013-10-28 15:22:33 +01:00
parent b2fa3b54fe
commit 0471a8c886
4 changed files with 34 additions and 19 deletions

View File

@ -29,7 +29,7 @@
#include <cstdio>
#include "gfx_es2/gl_state.h"
#include "gfx_es2/gpu_features.h"
#include "Core/Reporting.h"
#include "Core/Config.h"
#include "GPU/GLES/FragmentShaderGenerator.h"
@ -59,9 +59,7 @@ const bool safeDestFactors[16] = {
true, //GE_DSTBLEND_FIXB,
};
static bool IsAlphaTestTriviallyTrue() {
GEComparison alphaTestFunc = gstate.getAlphaTestFunction();
int alphaTestRef = gstate.getAlphaTestRef();
int alphaTestMask = gstate.getAlphaTestMask();
@ -75,7 +73,7 @@ static bool IsAlphaTestTriviallyTrue() {
case GE_COMP_GEQUAL:
return alphaTestRef == 0;
// Non-zero check. If we have no depth testing (and thus no depth writing), and an alpha func that will result in no change if zero alpha, get rid of the alpha test.
// Speeds up Lumines by a LOT on PowerVR.
case GE_COMP_NOTEQUAL:
@ -201,6 +199,12 @@ void GenerateFragmentShader(char *buffer) {
#if defined(GLSL_ES_1_0)
WRITE(p, "#version 100\n"); // GLSL ES 1.0
WRITE(p, "precision lowp float;\n");
// PowerVR needs highp to do the fog in MHU correctly.
// Others don't, and some can't handle highp in the fragment shader.
if (gl_extensions.gpuVendor != GPU_VENDOR_POWERVR) {
WRITE(p, "#define highp mediump\n");
}
#elif !defined(FORCE_OPENGL_2_0)
WRITE(p, "#version 110\n");
// Remove lowp/mediump in non-mobile implementations
@ -236,7 +240,7 @@ void GenerateFragmentShader(char *buffer) {
}
if (gstate.isTextureMapEnabled() && gstate.getTextureFunction() == GE_TEXFUNC_BLEND)
WRITE(p, "uniform lowp vec3 u_texenv;\n");
WRITE(p, "varying lowp vec4 v_color0;\n");
if (lmode)
WRITE(p, "varying lowp vec3 v_color1;\n");

View File

@ -19,15 +19,12 @@
#include "Globals.h"
struct FragmentShaderID
{
struct FragmentShaderID {
FragmentShaderID() {d[0] = 0xFFFFFFFF;}
void clear() {d[0] = 0xFFFFFFFF;}
u32 d[1];
bool operator < (const FragmentShaderID &other) const
{
for (size_t i = 0; i < sizeof(d) / sizeof(u32); i++)
{
bool operator < (const FragmentShaderID &other) const {
for (size_t i = 0; i < sizeof(d) / sizeof(u32); i++) {
if (d[i] < other.d[i])
return true;
if (d[i] > other.d[i])
@ -35,10 +32,8 @@ struct FragmentShaderID
}
return false;
}
bool operator == (const FragmentShaderID &other) const
{
for (size_t i = 0; i < sizeof(d) / sizeof(u32); i++)
{
bool operator == (const FragmentShaderID &other) const {
for (size_t i = 0; i < sizeof(d) / sizeof(u32); i++) {
if (d[i] != other.d[i])
return false;
}
@ -46,7 +41,6 @@ struct FragmentShaderID
}
};
void ComputeFragmentShaderID(FragmentShaderID *id);
void GenerateFragmentShader(char *buffer);

View File

@ -54,6 +54,10 @@ Shader::Shader(const char *code, uint32_t shaderType, bool useHWTransform) : fai
GLsizei len;
glGetShaderInfoLog(shader, MAX_INFO_LOG_SIZE, &len, infoLog);
infoLog[len] = '\0';
#ifdef ANDROID
ELOG("Error in shader compilation! %s\n", infoLog);
ELOG("Shader source:\n%s\n", (const char *)code);
#endif
ERROR_LOG(G3D, "Error in shader compilation!\n");
ERROR_LOG(G3D, "Info log: %s\n", infoLog);
ERROR_LOG(G3D, "Shader source:\n%s\n", (const char *)code);
@ -108,6 +112,9 @@ LinkedShader::LinkedShader(Shader *vs, Shader *fs, u32 vertType, bool useHWTrans
if (bufLength) {
char* buf = new char[bufLength];
glGetProgramInfoLog(program, bufLength, NULL, buf);
#ifdef ANDROID
ELOG("Could not link program:\n %s", buf);
#endif
ERROR_LOG(G3D, "Could not link program:\n %s", buf);
ERROR_LOG(G3D, "VS:\n%s", vs->source().c_str());
ERROR_LOG(G3D, "FS:\n%s", fs->source().c_str());

View File

@ -18,6 +18,8 @@
#include <stdio.h>
#include <locale.h>
#include "gfx_es2/gpu_features.h"
#if defined(_WIN32) && defined(_DEBUG)
#include "Common/CommonWindows.h"
#endif
@ -26,7 +28,6 @@
#include "GPU/ge_constants.h"
#include "GPU/GPUState.h"
#include "Core/Config.h"
#include "GPU/GLES/VertexShaderGenerator.h"
// SDL 1.2 on Apple does not have support for OpenGL 3 and hence needs
@ -274,7 +275,16 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
else
WRITE(p, "varying mediump vec2 v_texcoord;\n");
}
if (enableFog) WRITE(p, "varying highp float v_fogdepth;\n");
if (enableFog) {
// See the fragment shader generator
if (gl_extensions.gpuVendor == GPU_VENDOR_POWERVR) {
WRITE(p, "varying highp float v_fogdepth;\n");
} else {
WRITE(p, "varying mediump float v_fogdepth;\n");
}
}
WRITE(p, "void main() {\n");