mirror of https://github.com/bjornbytes/lovr.git
Use GLSL 430 when available;
This commit is contained in:
parent
ea331a12be
commit
8b9e9eba9e
|
@ -1586,6 +1586,14 @@ Shader* lovrShaderCreateGraphics(const char* vertexSource, const char* fragmentS
|
|||
Shader* shader = lovrAlloc(Shader, lovrShaderDestroy);
|
||||
if (!shader) return NULL;
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
const char* vertexHeader = "#version 300 es\nprecision mediump float;\nprecision mediump int;\n";
|
||||
const char* fragmentHeader = vertexHeader;
|
||||
#else
|
||||
const char* vertexHeader = state.features.computeShaders ? "#version 430\n" : "#version 150\n";
|
||||
const char* fragmentHeader = "#version 150\nin vec4 gl_FragCoord;\n";
|
||||
#endif
|
||||
|
||||
const char* vertexSinglepass = state.features.singlepass ?
|
||||
"#extension GL_AMD_vertex_shader_viewport_index : require\n" "#define SINGLEPASS 1\n" :
|
||||
"#define SINGLEPASS 0\n";
|
||||
|
@ -1596,12 +1604,12 @@ Shader* lovrShaderCreateGraphics(const char* vertexSource, const char* fragmentS
|
|||
|
||||
// Vertex
|
||||
vertexSource = vertexSource == NULL ? lovrDefaultVertexShader : vertexSource;
|
||||
const char* vertexSources[] = { lovrShaderVertexHeader, vertexSinglepass, lovrShaderVertexPrefix, vertexSource, lovrShaderVertexSuffix };
|
||||
const char* vertexSources[] = { vertexHeader, vertexSinglepass, lovrShaderVertexPrefix, vertexSource, lovrShaderVertexSuffix };
|
||||
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexSources, sizeof(vertexSources) / sizeof(vertexSources[0]));
|
||||
|
||||
// Fragment
|
||||
fragmentSource = fragmentSource == NULL ? lovrDefaultFragmentShader : fragmentSource;
|
||||
const char* fragmentSources[] = { lovrShaderFragmentHeader, fragmentSinglepass, lovrShaderFragmentPrefix, fragmentSource, lovrShaderFragmentSuffix };
|
||||
const char* fragmentSources[] = { fragmentHeader, fragmentSinglepass, lovrShaderFragmentPrefix, fragmentSource, lovrShaderFragmentSuffix };
|
||||
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentSources, sizeof(fragmentSources) / sizeof(fragmentSources[0]));
|
||||
|
||||
// Link
|
||||
|
|
|
@ -1,34 +1,5 @@
|
|||
#include "resources/shaders.h"
|
||||
|
||||
const char* lovrShaderScalarUniforms[] = {
|
||||
"lovrMetalness",
|
||||
"lovrRoughness"
|
||||
};
|
||||
|
||||
const char* lovrShaderColorUniforms[] = {
|
||||
"lovrDiffuseColor",
|
||||
"lovrEmissiveColor"
|
||||
};
|
||||
|
||||
const char* lovrShaderTextureUniforms[] = {
|
||||
"lovrDiffuseTexture",
|
||||
"lovrEmissiveTexture",
|
||||
"lovrMetalnessTexture",
|
||||
"lovrRoughnessTexture",
|
||||
"lovrOcclusionTexture",
|
||||
"lovrNormalTexture",
|
||||
"lovrEnvironmentTexture"
|
||||
};
|
||||
|
||||
const char* lovrShaderVertexHeader = ""
|
||||
#ifdef EMSCRIPTEN
|
||||
"#version 300 es \n"
|
||||
"precision mediump float; \n"
|
||||
"precision mediump int; \n";
|
||||
#else
|
||||
"#version 150 \n";
|
||||
#endif
|
||||
|
||||
const char* lovrShaderVertexPrefix = ""
|
||||
"#define VERTEX VERTEX \n"
|
||||
"#define MAX_BONES 48 \n"
|
||||
|
@ -77,16 +48,6 @@ const char* lovrShaderVertexSuffix = ""
|
|||
" gl_Position = position(lovrProjection, lovrTransform, pose * vec4(lovrPosition, 1.0)); \n"
|
||||
"}";
|
||||
|
||||
const char* lovrShaderFragmentHeader = ""
|
||||
#ifdef EMSCRIPTEN
|
||||
"#version 300 es \n"
|
||||
"precision mediump float; \n"
|
||||
"precision mediump int; \n";
|
||||
#else
|
||||
"#version 150 \n"
|
||||
"in vec4 gl_FragCoord; \n";
|
||||
#endif
|
||||
|
||||
const char* lovrShaderFragmentPrefix = ""
|
||||
"#define PIXEL PIXEL \n"
|
||||
"#define FRAGMENT FRAGMENT \n"
|
||||
|
@ -181,3 +142,23 @@ const char* lovrFillVertexShader = ""
|
|||
"vec4 position(mat4 projection, mat4 transform, vec4 vertex) { \n"
|
||||
" return vertex; \n"
|
||||
"}";
|
||||
|
||||
const char* lovrShaderScalarUniforms[] = {
|
||||
"lovrMetalness",
|
||||
"lovrRoughness"
|
||||
};
|
||||
|
||||
const char* lovrShaderColorUniforms[] = {
|
||||
"lovrDiffuseColor",
|
||||
"lovrEmissiveColor"
|
||||
};
|
||||
|
||||
const char* lovrShaderTextureUniforms[] = {
|
||||
"lovrDiffuseTexture",
|
||||
"lovrEmissiveTexture",
|
||||
"lovrMetalnessTexture",
|
||||
"lovrRoughnessTexture",
|
||||
"lovrOcclusionTexture",
|
||||
"lovrNormalTexture",
|
||||
"lovrEnvironmentTexture"
|
||||
};
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
extern const char* lovrShaderScalarUniforms[];
|
||||
extern const char* lovrShaderColorUniforms[];
|
||||
extern const char* lovrShaderTextureUniforms[];
|
||||
extern const char* lovrShaderVertexHeader;
|
||||
extern const char* lovrShaderVertexPrefix;
|
||||
extern const char* lovrShaderVertexSuffix;
|
||||
extern const char* lovrShaderFragmentHeader;
|
||||
extern const char* lovrShaderFragmentPrefix;
|
||||
extern const char* lovrShaderFragmentSuffix;
|
||||
extern const char* lovrShaderComputePrefix;
|
||||
|
@ -18,3 +13,7 @@ extern const char* lovrCubeFragmentShader;
|
|||
extern const char* lovrPanoFragmentShader;
|
||||
extern const char* lovrFontFragmentShader;
|
||||
extern const char* lovrFillVertexShader;
|
||||
|
||||
extern const char* lovrShaderScalarUniforms[];
|
||||
extern const char* lovrShaderColorUniforms[];
|
||||
extern const char* lovrShaderTextureUniforms[];
|
||||
|
|
Loading…
Reference in New Issue