mirror of https://github.com/bjornbytes/lovr.git
Add highp shader flag that sets default fragment precision to highp;
Also, precision qualifier is required to work on desktop GL, so we don't need ifdefs for it!
This commit is contained in:
parent
cae8bba522
commit
c502f5b62a
|
@ -2241,10 +2241,8 @@ static char* lovrShaderGetFlagCode(ShaderFlag* flags, uint32_t flagCount) {
|
|||
Shader* lovrShaderInitGraphics(Shader* shader, const char* vertexSource, int vertexSourceLength, const char* fragmentSource, int fragmentSourceLength, ShaderFlag* flags, uint32_t flagCount, bool multiview) {
|
||||
#if defined(LOVR_WEBGL) || defined(LOVR_GLES)
|
||||
const char* version = "#version 300 es\n";
|
||||
const char* precision[2] = { "precision highp float;\nprecision highp int;\n", "precision mediump float;\nprecision mediump int;\n" };
|
||||
#else
|
||||
const char* version = state.features.compute ? "#version 430\n" : "#version 150\n";
|
||||
const char* precision[2] = { "", "" };
|
||||
#endif
|
||||
|
||||
const char* singlepass[2] = { "", "" };
|
||||
|
@ -2259,15 +2257,15 @@ Shader* lovrShaderInitGraphics(Shader* shader, const char* vertexSource, int ver
|
|||
|
||||
// Vertex
|
||||
vertexSource = vertexSource == NULL ? lovrUnlitVertexShader : vertexSource;
|
||||
const char* vertexSources[] = { version, singlepass[0], precision[0], flagSource ? flagSource : "", lovrShaderVertexPrefix, vertexSource, lovrShaderVertexSuffix };
|
||||
int vertexSourceLengths[] = { -1, -1, -1, -1, -1, vertexSourceLength, -1 };
|
||||
const char* vertexSources[] = { version, singlepass[0], flagSource ? flagSource : "", lovrShaderVertexPrefix, vertexSource, lovrShaderVertexSuffix };
|
||||
int vertexSourceLengths[] = { -1, -1, -1, -1, vertexSourceLength, -1 };
|
||||
size_t vertexSourceCount = sizeof(vertexSources) / sizeof(vertexSources[0]);
|
||||
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexSources, vertexSourceLengths, vertexSourceCount);
|
||||
|
||||
// Fragment
|
||||
fragmentSource = fragmentSource == NULL ? lovrUnlitFragmentShader : fragmentSource;
|
||||
const char* fragmentSources[] = { version, singlepass[1], precision[1], flagSource ? flagSource : "", lovrShaderFragmentPrefix, fragmentSource, lovrShaderFragmentSuffix };
|
||||
int fragmentSourceLengths[] = { -1, -1, -1, -1, -1, fragmentSourceLength, -1 };
|
||||
const char* fragmentSources[] = { version, singlepass[1], flagSource ? flagSource : "", lovrShaderFragmentPrefix, fragmentSource, lovrShaderFragmentSuffix };
|
||||
int fragmentSourceLengths[] = { -1, -1, -1, -1, fragmentSourceLength, -1 };
|
||||
size_t fragmentSourceCount = sizeof(fragmentSources) / sizeof(fragmentSources[0]);
|
||||
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentSources, fragmentSourceLengths, fragmentSourceCount);
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ const char* lovrShaderVertexPrefix = ""
|
|||
"#else \n"
|
||||
"#define lovrVertex vec4(lovrPosition, 1.) \n"
|
||||
"#endif \n"
|
||||
"precision highp float; \n"
|
||||
"precision highp int; \n"
|
||||
"in vec3 lovrPosition; \n"
|
||||
"in vec3 lovrNormal; \n"
|
||||
"in vec2 lovrTexCoord; \n"
|
||||
|
@ -70,6 +72,13 @@ const char* lovrShaderFragmentPrefix = ""
|
|||
"#define FRAGMENT FRAGMENT \n"
|
||||
"#define lovrTexCoord texCoord \n"
|
||||
"#define lovrVertexColor vertexColor \n"
|
||||
"#ifdef FLAG_highp \n"
|
||||
"precision highp float; \n"
|
||||
"precision highp int; \n"
|
||||
"#else \n"
|
||||
"precision mediump float; \n"
|
||||
"precision mediump int; \n"
|
||||
"#endif \n"
|
||||
"in vec2 texCoord; \n"
|
||||
"in vec4 vertexColor; \n"
|
||||
"in vec4 lovrGraphicsColor; \n"
|
||||
|
|
Loading…
Reference in New Issue