ogl: support glsl120
This commit is contained in:
parent
3897e1959e
commit
4c40e70b8a
|
@ -598,9 +598,9 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
|
|
||||||
if (ApiType == API_OPENGL)
|
if (ApiType == API_OPENGL)
|
||||||
{
|
{
|
||||||
WRITE(p, "out float4 ocol0;\n");
|
WRITE(p, "COLOROUT(ocol0)\n");
|
||||||
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||||
WRITE(p, "out float4 ocol1;\n");
|
WRITE(p, "COLOROUT(ocol1)\n");
|
||||||
|
|
||||||
if (per_pixel_depth)
|
if (per_pixel_depth)
|
||||||
WRITE(p, "#define depth gl_FragDepth\n");
|
WRITE(p, "#define depth gl_FragDepth\n");
|
||||||
|
|
|
@ -105,8 +105,8 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
|
||||||
|
|
||||||
if (ApiType == API_OPENGL)
|
if (ApiType == API_OPENGL)
|
||||||
{
|
{
|
||||||
WRITE(p, " out float4 ocol0;\n");
|
WRITE(p, " COLOROUT(ocol0)\n");
|
||||||
WRITE(p, " in float2 uv0;\n");
|
WRITE(p, " VARYIN float2 uv0;\n");
|
||||||
WRITE(p, "void main()\n");
|
WRITE(p, "void main()\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -187,7 +187,7 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
|
||||||
if (ApiType == API_OPENGL)
|
if (ApiType == API_OPENGL)
|
||||||
{
|
{
|
||||||
WRITE(p, " out float4 ocol0;\n");
|
WRITE(p, " out float4 ocol0;\n");
|
||||||
WRITE(p, " in float2 uv0;\n");
|
WRITE(p, " VARYIN float2 uv0;\n");
|
||||||
WRITE(p, "void main()\n");
|
WRITE(p, "void main()\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -123,8 +123,15 @@ void SHADER::SetProgramBindings()
|
||||||
glBindFragDataLocationIndexed(glprogid, 0, 0, "ocol0");
|
glBindFragDataLocationIndexed(glprogid, 0, 0, "ocol0");
|
||||||
glBindFragDataLocationIndexed(glprogid, 0, 1, "ocol1");
|
glBindFragDataLocationIndexed(glprogid, 0, 1, "ocol1");
|
||||||
}
|
}
|
||||||
else
|
else if(g_ogl_config.eSupportedGLSLVersion > GLSL_120)
|
||||||
|
{
|
||||||
glBindFragDataLocation(glprogid, 0, "ocol0");
|
glBindFragDataLocation(glprogid, 0, "ocol0");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ogl2 shaders don't need to bind output colors.
|
||||||
|
// gl_FragColor already point to color channel
|
||||||
|
}
|
||||||
|
|
||||||
// Need to set some attribute locations
|
// Need to set some attribute locations
|
||||||
glBindAttribLocation(glprogid, SHADER_POSITION_ATTRIB, "rawpos");
|
glBindAttribLocation(glprogid, SHADER_POSITION_ATTRIB, "rawpos");
|
||||||
|
@ -482,35 +489,17 @@ void ProgramShaderCache::Shutdown(void)
|
||||||
|
|
||||||
void ProgramShaderCache::CreateHeader ( void )
|
void ProgramShaderCache::CreateHeader ( void )
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion;
|
||||||
// Intel Windows driver has a issue:
|
|
||||||
// their glsl doesn't know about the ubo extension, so we can't load it.
|
|
||||||
// but as version 140, ubo is in core and don't have to be loaded in glsl.
|
|
||||||
// as sandy do ogl3.1, glsl 140 is supported, so force it in this way.
|
|
||||||
// TODO: remove this again when the issue is fixed:
|
|
||||||
// see http://communities.intel.com/thread/36084
|
|
||||||
bool glsl140_hack = strcmp(g_ogl_config.gl_vendor, "Intel") == 0;
|
|
||||||
#elif __APPLE__
|
|
||||||
// as apple doesn't support glsl130 at all, we also have to use glsl140
|
|
||||||
bool glsl140_hack = true;
|
|
||||||
#else
|
|
||||||
bool glsl140_hack = false;
|
|
||||||
#endif
|
|
||||||
// Intel HD Graphics on the Ironlake chipset has been abandoned by Intel
|
|
||||||
// It supports every feature we need but not GLSL 1.3
|
|
||||||
// This is to check if it is Ironlake then drop to GLSL 1.2
|
|
||||||
bool glsl120_hack = strstr(g_ogl_config.gl_renderer, "Ironlake") != 0;
|
|
||||||
|
|
||||||
snprintf(s_glsl_header, sizeof(s_glsl_header),
|
snprintf(s_glsl_header, sizeof(s_glsl_header),
|
||||||
"#version %s\n"
|
"#version %s\n"
|
||||||
"%s\n" // tex_rect
|
"%s\n" // tex_rect
|
||||||
"%s\n" // ubo
|
"%s\n" // ubo
|
||||||
|
|
||||||
"\n"// A few required defines and ones that will make our lives a lot easier
|
"\n"// A few required defines and ones that will make our lives a lot easier
|
||||||
"#define ATTRIN in\n"
|
"#define ATTRIN %s\n"
|
||||||
"#define ATTROUT out\n"
|
"#define ATTROUT %s\n"
|
||||||
"#define VARYIN centroid in\n"
|
"#define VARYIN %s\n"
|
||||||
"#define VARYOUT centroid out\n"
|
"#define VARYOUT %s\n"
|
||||||
|
|
||||||
// Silly differences
|
// Silly differences
|
||||||
"#define float2 vec2\n"
|
"#define float2 vec2\n"
|
||||||
|
@ -522,10 +511,27 @@ void ProgramShaderCache::CreateHeader ( void )
|
||||||
"#define saturate(x) clamp(x, 0.0f, 1.0f)\n"
|
"#define saturate(x) clamp(x, 0.0f, 1.0f)\n"
|
||||||
"#define lerp(x, y, z) mix(x, y, z)\n"
|
"#define lerp(x, y, z) mix(x, y, z)\n"
|
||||||
|
|
||||||
|
// glsl 120 hack
|
||||||
|
"%s\n"
|
||||||
|
"%s\n"
|
||||||
|
"%s\n"
|
||||||
|
"%s\n"
|
||||||
|
"%s\n"
|
||||||
|
"#define COLOROUT(name) %s\n"
|
||||||
|
|
||||||
, glsl120_hack ? "120" : glsl140_hack ? "140" : "130"
|
, v==GLSL_120 ? "120" : v==GLSL_130 ? "130" : "140"
|
||||||
, glsl140_hack ? "#define texture2DRect texture" : "#extension GL_ARB_texture_rectangle : enable"
|
, v<=GLSL_130 ? "#extension GL_ARB_texture_rectangle : enable" : "#define texture2DRect texture"
|
||||||
, g_ActiveConfig.backend_info.bSupportsGLSLUBO && !glsl140_hack ? "#extension GL_ARB_uniform_buffer_object : enable" : "// ubo disabled"
|
, g_ActiveConfig.backend_info.bSupportsGLSLUBO && v!=GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : ""
|
||||||
|
, v==GLSL_120 ? "attribute" : "in"
|
||||||
|
, v==GLSL_120 ? "attribute" : "out"
|
||||||
|
, v==GLSL_120 ? "varying" : "centroid in"
|
||||||
|
, v==GLSL_120 ? "varying" : "centroid out"
|
||||||
|
, v==GLSL_120 ? "#define texture texture2D" : ""
|
||||||
|
, v==GLSL_120 ? "#define round(x) floor((x)+0.5f)" : ""
|
||||||
|
, v==GLSL_120 ? "#define out " : ""
|
||||||
|
, v==GLSL_120 ? "#define ocol0 gl_FragColor" : ""
|
||||||
|
, v==GLSL_120 ? "#define ocol1 gl_FragColor" : "" //TODO: implemenet dual source blend
|
||||||
|
, v==GLSL_120 ? "" : "out vec4 name;"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,9 +128,9 @@ const u8 rasters[char_count][char_height] = {
|
||||||
|
|
||||||
static const char *s_vertexShaderSrc =
|
static const char *s_vertexShaderSrc =
|
||||||
"uniform vec2 charSize;\n"
|
"uniform vec2 charSize;\n"
|
||||||
"in vec2 rawpos;\n"
|
"ATTRIN vec2 rawpos;\n"
|
||||||
"in vec2 tex0;\n"
|
"ATTRIN vec2 tex0;\n"
|
||||||
"out vec2 uv0;\n"
|
"VARYOUT vec2 uv0;\n"
|
||||||
"void main(void) {\n"
|
"void main(void) {\n"
|
||||||
" gl_Position = vec4(rawpos,0,1);\n"
|
" gl_Position = vec4(rawpos,0,1);\n"
|
||||||
" uv0 = tex0 * charSize;\n"
|
" uv0 = tex0 * charSize;\n"
|
||||||
|
@ -139,8 +139,8 @@ static const char *s_vertexShaderSrc =
|
||||||
static const char *s_fragmentShaderSrc =
|
static const char *s_fragmentShaderSrc =
|
||||||
"uniform sampler2D samp8;\n"
|
"uniform sampler2D samp8;\n"
|
||||||
"uniform vec4 color;\n"
|
"uniform vec4 color;\n"
|
||||||
"in vec2 uv0;\n"
|
"VARYIN vec2 uv0;\n"
|
||||||
"out vec4 ocol0;\n"
|
"COLOROUT(ocol0)\n"
|
||||||
"void main(void) {\n"
|
"void main(void) {\n"
|
||||||
" ocol0 = texture(samp8,uv0) * color;\n"
|
" ocol0 = texture(samp8,uv0) * color;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
|
@ -349,6 +349,28 @@ Renderer::Renderer()
|
||||||
g_ogl_config.gl_vendor = (const char*)glGetString(GL_VENDOR);
|
g_ogl_config.gl_vendor = (const char*)glGetString(GL_VENDOR);
|
||||||
g_ogl_config.gl_renderer = (const char*)glGetString(GL_RENDERER);
|
g_ogl_config.gl_renderer = (const char*)glGetString(GL_RENDERER);
|
||||||
g_ogl_config.gl_version = (const char*)glGetString(GL_VERSION);
|
g_ogl_config.gl_version = (const char*)glGetString(GL_VERSION);
|
||||||
|
g_ogl_config.glsl_version = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||||
|
|
||||||
|
if(strstr(g_ogl_config.glsl_version, "1.00") || strstr(g_ogl_config.glsl_version, "1.10"))
|
||||||
|
{
|
||||||
|
ERROR_LOG(VIDEO, "GPU: OGL ERROR: Need at least GLSL 1.20\n"
|
||||||
|
"GPU: Does your video card support OpenGL 2.1?\n"
|
||||||
|
"GPU: Your driver supports glsl %s", g_ogl_config.glsl_version);
|
||||||
|
bSuccess = false;
|
||||||
|
}
|
||||||
|
else if(strstr(g_ogl_config.glsl_version, "1.20"))
|
||||||
|
{
|
||||||
|
g_ogl_config.eSupportedGLSLVersion = GLSL_120;
|
||||||
|
g_Config.backend_info.bSupportsDualSourceBlend = false; //TODO: implemenet dual source blend
|
||||||
|
}
|
||||||
|
else if(strstr(g_ogl_config.glsl_version, "1.30"))
|
||||||
|
{
|
||||||
|
g_ogl_config.eSupportedGLSLVersion = GLSL_130;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_ogl_config.eSupportedGLSLVersion = GLSL_140;
|
||||||
|
}
|
||||||
|
|
||||||
glGetIntegerv(GL_MAX_SAMPLES, &g_ogl_config.max_samples);
|
glGetIntegerv(GL_MAX_SAMPLES, &g_ogl_config.max_samples);
|
||||||
if(g_ogl_config.max_samples < 1)
|
if(g_ogl_config.max_samples < 1)
|
||||||
|
@ -487,15 +509,15 @@ void Renderer::Init()
|
||||||
s_pfont = new RasterFont();
|
s_pfont = new RasterFont();
|
||||||
|
|
||||||
ProgramShaderCache::CompileShader(s_ShowEFBCopyRegions,
|
ProgramShaderCache::CompileShader(s_ShowEFBCopyRegions,
|
||||||
"in vec2 rawpos;\n"
|
"ATTRIN vec2 rawpos;\n"
|
||||||
"in vec3 color0;\n"
|
"ATTRIN vec3 color0;\n"
|
||||||
"out vec4 c;\n"
|
"VARYOUT vec4 c;\n"
|
||||||
"void main(void) {\n"
|
"void main(void) {\n"
|
||||||
" gl_Position = vec4(rawpos,0,1);\n"
|
" gl_Position = vec4(rawpos,0,1);\n"
|
||||||
" c = vec4(color0, 1.0);\n"
|
" c = vec4(color0, 1.0);\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"in vec4 c;\n"
|
"VARYIN vec4 c;\n"
|
||||||
"out vec4 ocol0;\n"
|
"COLOROUT(ocol0)\n"
|
||||||
"void main(void) {\n"
|
"void main(void) {\n"
|
||||||
" ocol0 = c;\n"
|
" ocol0 = c;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
|
@ -9,6 +9,12 @@ namespace OGL
|
||||||
|
|
||||||
void ClearEFBCache();
|
void ClearEFBCache();
|
||||||
|
|
||||||
|
enum GLSL_VERSION {
|
||||||
|
GLSL_120,
|
||||||
|
GLSL_130,
|
||||||
|
GLSL_140 // and above
|
||||||
|
};
|
||||||
|
|
||||||
// ogl-only config, so not in VideoConfig.h
|
// ogl-only config, so not in VideoConfig.h
|
||||||
extern struct VideoConfig {
|
extern struct VideoConfig {
|
||||||
bool bSupportsGLSLCache;
|
bool bSupportsGLSLCache;
|
||||||
|
@ -17,10 +23,12 @@ extern struct VideoConfig {
|
||||||
bool bSupportsGLBaseVertex;
|
bool bSupportsGLBaseVertex;
|
||||||
bool bSupportCoverageMSAA;
|
bool bSupportCoverageMSAA;
|
||||||
bool bSupportSampleShading;
|
bool bSupportSampleShading;
|
||||||
|
GLSL_VERSION eSupportedGLSLVersion;
|
||||||
|
|
||||||
const char *gl_vendor;
|
const char *gl_vendor;
|
||||||
const char *gl_renderer;
|
const char *gl_renderer;
|
||||||
const char* gl_version;
|
const char* gl_version;
|
||||||
|
const char* glsl_version;
|
||||||
|
|
||||||
s32 max_samples;
|
s32 max_samples;
|
||||||
} g_ogl_config;
|
} g_ogl_config;
|
||||||
|
|
|
@ -421,8 +421,8 @@ TextureCache::TextureCache()
|
||||||
const char *pColorMatrixProg =
|
const char *pColorMatrixProg =
|
||||||
"uniform sampler2DRect samp9;\n"
|
"uniform sampler2DRect samp9;\n"
|
||||||
"uniform vec4 colmat[7];\n"
|
"uniform vec4 colmat[7];\n"
|
||||||
"in vec2 uv0;\n"
|
"VARYIN vec2 uv0;\n"
|
||||||
"out vec4 ocol0;\n"
|
"COLOROUT(ocol0)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void main(){\n"
|
"void main(){\n"
|
||||||
" vec4 texcol = texture2DRect(samp9, uv0);\n"
|
" vec4 texcol = texture2DRect(samp9, uv0);\n"
|
||||||
|
@ -433,8 +433,8 @@ TextureCache::TextureCache()
|
||||||
const char *pDepthMatrixProg =
|
const char *pDepthMatrixProg =
|
||||||
"uniform sampler2DRect samp9;\n"
|
"uniform sampler2DRect samp9;\n"
|
||||||
"uniform vec4 colmat[5];\n"
|
"uniform vec4 colmat[5];\n"
|
||||||
"in vec2 uv0;\n"
|
"VARYIN vec2 uv0;\n"
|
||||||
"out vec4 ocol0;\n"
|
"COLOROUT(ocol0)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void main(){\n"
|
"void main(){\n"
|
||||||
" vec4 texcol = texture2DRect(samp9, uv0);\n"
|
" vec4 texcol = texture2DRect(samp9, uv0);\n"
|
||||||
|
@ -445,9 +445,9 @@ TextureCache::TextureCache()
|
||||||
|
|
||||||
|
|
||||||
const char *VProgram =
|
const char *VProgram =
|
||||||
"in vec2 rawpos;\n"
|
"ATTRIN vec2 rawpos;\n"
|
||||||
"in vec2 tex0;\n"
|
"ATTRIN vec2 tex0;\n"
|
||||||
"out vec2 uv0;\n"
|
"VARYOUT vec2 uv0;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" uv0 = tex0;\n"
|
" uv0 = tex0;\n"
|
||||||
|
|
|
@ -66,9 +66,9 @@ static int s_cached_srcWidth = 0;
|
||||||
static int s_cached_srcHeight = 0;
|
static int s_cached_srcHeight = 0;
|
||||||
|
|
||||||
static const char *VProgram =
|
static const char *VProgram =
|
||||||
"in vec2 rawpos;\n"
|
"ATTRIN vec2 rawpos;\n"
|
||||||
"in vec2 tex0;\n"
|
"ATTRIN vec2 tex0;\n"
|
||||||
"out vec2 uv0;\n"
|
"VARYOUT vec2 uv0;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" uv0 = tex0;\n"
|
" uv0 = tex0;\n"
|
||||||
|
@ -80,8 +80,8 @@ void CreatePrograms()
|
||||||
// Output is BGRA because that is slightly faster than RGBA.
|
// Output is BGRA because that is slightly faster than RGBA.
|
||||||
const char *FProgramRgbToYuyv =
|
const char *FProgramRgbToYuyv =
|
||||||
"uniform sampler2DRect samp9;\n"
|
"uniform sampler2DRect samp9;\n"
|
||||||
"in vec2 uv0;\n"
|
"VARYIN vec2 uv0;\n"
|
||||||
"out vec4 ocol0;\n"
|
"COLOROUT(ocol0)\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec3 c0 = texture2DRect(samp9, uv0).rgb;\n"
|
" vec3 c0 = texture2DRect(samp9, uv0).rgb;\n"
|
||||||
|
@ -96,8 +96,8 @@ void CreatePrograms()
|
||||||
|
|
||||||
const char *FProgramYuyvToRgb =
|
const char *FProgramYuyvToRgb =
|
||||||
"uniform sampler2DRect samp9;\n"
|
"uniform sampler2DRect samp9;\n"
|
||||||
"in vec2 uv0;\n"
|
"VARYIN vec2 uv0;\n"
|
||||||
"out vec4 ocol0;\n"
|
"COLOROUT(ocol0)\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec4 c0 = texture2DRect(samp9, uv0).rgba;\n"
|
" vec4 c0 = texture2DRect(samp9, uv0).rgba;\n"
|
||||||
|
|
Loading…
Reference in New Issue