OpenGL display driver

This commit is contained in:
elasota
2020-09-26 16:45:52 -04:00
parent da3cdb3a17
commit 45aa5b4cba
26 changed files with 2922 additions and 33 deletions

View File

@@ -0,0 +1,28 @@
#include "Functions.h"
#include "DrawQuadPixelConstants.h"
#define GP_GL_SHADER_CODE_DRAWQUADPALETTEP_GLSL "varying vec4 texCoord;\n"\
"uniform sampler2D surfaceTexture;\n"\
"uniform sampler2D paletteTexture;\n"\
"\n"\
"vec3 SamplePixel(vec2 tc)\n"\
"{\n"\
" float surfaceColor = texture2D(surfaceTexture, tc).r;\n"\
" return texture2D(paletteTexture, vec2(surfaceColor * (255.0 / 256.0) + (0.5 / 256.0), 0.5)).rgb;\n"\
"}\n"\
"\n"\
"void main()\n"\
"{\n"\
" vec4 resultColor = vec4(SamplePixel(texCoord.xy), 1.0);\n"\
" resultColor *= constants_Modulation;\n"\
" resultColor = ApplyFlicker(constants_FlickerAxis, texCoord.xy, constants_FlickerStartThreshold, constants_FlickerEndThreshold, resultColor * constants_Modulation);\n"\
" resultColor = ApplyDesaturation(constants_Desaturation, resultColor);\n"\
"\n"\
" gl_FragColor = vec4(ApplyColorSpaceTransform(resultColor.rgb), resultColor.a);\n"\
"}\n"
namespace GpBinarizedShaders
{
const char *g_drawQuadPaletteP_GL2 = GP_GL_SHADER_CODE_DRAWQUADPIXELCONSTANTS_H GP_GL_SHADER_CODE_FUNCTIONS_H GP_GL_SHADER_CODE_DRAWQUADPALETTEP_GLSL;
const char *g_drawQuadPaletteICCP_GL2 = "#define USE_ICC_PROFILE\n" GP_GL_SHADER_CODE_DRAWQUADPIXELCONSTANTS_H GP_GL_SHADER_CODE_FUNCTIONS_H GP_GL_SHADER_CODE_DRAWQUADPALETTEP_GLSL;
}

View File

@@ -0,0 +1,5 @@
#define GP_GL_SHADER_CODE_DRAWQUADPIXELCONSTANTS_H "uniform vec4 constants_Modulation;\n"\
"uniform vec2 constants_FlickerAxis;\n"\
"uniform float constants_FlickerStartThreshold;\n"\
"uniform float constants_FlickerEndThreshold;\n"\
"uniform float constants_Desaturation;\n"

View File

@@ -0,0 +1,17 @@
#define GP_GL_SHADER_CODE_DRAWQUADV_GLSL "uniform vec4 ndcOriginAndDimensions;\n"\
"uniform vec4 surfaceDimensions_TextureRegion;\n"\
"attribute vec2 posUV;\n"\
"varying vec4 texCoord;\n"\
"\n"\
"void main()\n"\
"{\n"\
" vec2 ndcPos = ndcOriginAndDimensions.xy + posUV.xy * ndcOriginAndDimensions.zw;\n"\
"\n"\
" gl_Position = vec4(ndcPos.x, ndcPos.y, 0.0, 1.0);\n"\
" texCoord = vec4(posUV.xyxy * surfaceDimensions_TextureRegion.zwxy);\n"\
"}\n"
namespace GpBinarizedShaders
{
const char *g_drawQuadV_GL2 = GP_GL_SHADER_CODE_DRAWQUADV_GLSL;
}

View File

@@ -0,0 +1,100 @@
#define GP_GL_SHADER_CODE_FUNCTIONS_H "vec3 pow3(vec3 v, float ex)\n"\
"{\n"\
" return vec3(pow(v.x, ex), pow(v.y, ex), pow(v.z, ex));\n"\
"}\n"\
"\n"\
"float SRGBToLinear(float v)\n"\
"{\n"\
" if (v <= 0.04045)\n"\
" return v * (1.0 / 12.92);\n"\
" else\n"\
" return pow(((v + 0.055) * (1.0 / 1.055)), 2.4);\n"\
"}\n"\
"\n"\
"vec2 SRGBToLinear(vec2 v)\n"\
"{\n"\
" return vec2(SRGBToLinear(v.x), SRGBToLinear(v.y));\n"\
"}\n"\
"\n"\
"vec3 SRGBToLinear(vec3 v)\n"\
"{\n"\
" return vec3(SRGBToLinear(v.x), SRGBToLinear(v.y), SRGBToLinear(v.z));\n"\
"}\n"\
"\n"\
"float LinearToSRGB(float v)\n"\
"{\n"\
" if (v <= 0.0031308)\n"\
" return 12.92 * v;\n"\
" else\n"\
" return 1.055 * pow(v, 1.0 / 2.4) - 0.055;\n"\
"}\n"\
"\n"\
"vec2 LinearToSRGB(vec2 v)\n"\
"{\n"\
" return vec2(LinearToSRGB(v.x), LinearToSRGB(v.y));\n"\
"}\n"\
"\n"\
"vec3 LinearToSRGB(vec3 v)\n"\
"{\n"\
" return vec3(LinearToSRGB(v.x), LinearToSRGB(v.y), LinearToSRGB(v.z));\n"\
"}\n"\
"\n"\
"vec4 ApplyFlicker(vec2 flickerAxis, vec2 coordinate, float startThreshold, float endThreshold, vec4 color)\n"\
"{\n"\
" float flickerTotal = dot(flickerAxis, coordinate);\n"\
" if (flickerTotal < startThreshold)\n"\
" return vec4(0, 0, 0, 0);\n"\
" else if (flickerTotal >= endThreshold)\n"\
" return color;\n"\
"\n"\
" return vec4(1, 1, 1, 1);\n"\
"}\n"\
"\n"\
"vec4 ApplyDesaturation(float desaturation, vec4 color)\n"\
"{\n"\
" // This is intentionally done in gamma space\n"\
" if (desaturation == 0.0)\n"\
" return color;\n"\
"\n"\
" float grayLevel = dot(color.rgb, vec3(3.0, 6.0, 1.0) / 10.0);\n"\
"\n"\
" color.rgb = color.rgb * (1.0 - desaturation) + vec3(grayLevel, grayLevel, grayLevel) * desaturation;\n"\
" return color;\n"\
"}\n"\
"\n"\
"float saturate(float v)\n"\
"{\n"\
" return min(1.0, max(0.0, v));\n"\
"}\n"\
"\n"\
"vec2 saturate(vec2 v)\n"\
"{\n"\
" return vec2(saturate(v.x), saturate(v.y));\n"\
"}\n"\
"\n"\
"vec3 saturate(vec3 v)\n"\
"{\n"\
" return vec3(saturate(v.x), saturate(v.y), saturate(v.z));\n"\
"}\n"\
"\n"\
"vec3 AppleRGBToSRGBLinear(vec3 color)\n"\
"{\n"\
" color = pow3(saturate(color), 1.8);\n"\
"\n"\
" vec3 result;\n"\
" result = color.r * vec3(1.06870538834699, 0.024110476735, 0.00173499822713);\n"\
" result += color.g * vec3(-0.07859532843279, 0.96007030899244, 0.02974755969275);\n"\
" result += color.b * vec3(0.00988984558395, 0.01581936633364, 0.96851741859153);\n"\
"\n"\
" return result;\n"\
"}\n"\
"\n"\
"vec3 ApplyColorSpaceTransform(vec3 color)\n"\
"{\n"\
"#ifdef USE_ICC_PROFILE\n"\
" return saturate(AppleRGBToSRGBLinear(color));\n"\
"#else\n"\
" return SRGBToLinear(color);\n"\
"#endif\n"\
"}\n"\
"\n"

View File

@@ -0,0 +1,50 @@
#include "Functions.h"
#define GP_GL_SHADER_CODE_SCALEQUADP_GLSL "uniform sampler2D surfaceTexture;\n"\
"varying vec4 texCoord;\n"\
"\n"\
"uniform vec4 dxdy_dimensions;\n"\
"\n"\
"vec3 SamplePixel(vec2 coord)\n"\
"{\n"\
" return texture2D(surfaceTexture, (coord + vec2(0.5, 0.5)) / dxdy_dimensions.zw).rgb;\n"\
"}\n"\
"\n"\
"void main()\n"\
"{\n"\
" float dx = dxdy_dimensions.x;\n"\
" float dy = dxdy_dimensions.y;\n"\
" vec2 dimensions = dxdy_dimensions.zw;\n"\
" vec2 texCoordInteger = dxdy_dimensions.zw;\n"\
"\n"\
" vec2 pixelTopLeftCoord = max(vec2(0.0, 0.0), texCoord.zw - vec2(dx, dy) * 0.5);\n"\
" vec2 pixelBottomRightCoord = pixelTopLeftCoord + min(vec2(1.0, 1.0), vec2(dx, dy));\n"\
"\n"\
" vec2 topLeftCoordInteger = floor(pixelTopLeftCoord);\n"\
" vec2 bottomRightCoordInteger = floor(pixelBottomRightCoord);\n"\
"\n"\
" vec2 interpolators = saturate((pixelBottomRightCoord - bottomRightCoordInteger) / vec2(dx, dy));\n"\
"\n"\
" vec3 topLeftColor = SamplePixel(topLeftCoordInteger);\n"\
" vec3 topRightColor = SamplePixel(vec2(bottomRightCoordInteger.x, topLeftCoordInteger.y));\n"\
" vec3 bottomLeftColor = SamplePixel(vec2(topLeftCoordInteger.x, bottomRightCoordInteger.y));\n"\
" vec3 bottomRightColor = SamplePixel(bottomRightCoordInteger);\n"\
"\n"\
" vec3 topColor = (1.0 - interpolators.x) * topLeftColor + interpolators.x * topRightColor;\n"\
" vec3 bottomColor = (1.0 - interpolators.x) * bottomLeftColor + interpolators.x * bottomRightColor;\n"\
" vec3 interpolatedColor = (1.0 - interpolators.y) * topColor + interpolators.y * bottomColor;\n"\
"\n"\
" gl_FragColor = vec4(LinearToSRGB(interpolatedColor), 1.0);\n"\
"}\n"
namespace GpBinarizedShaders
{
const char *g_scaleQuadP_GL2 = GP_GL_SHADER_CODE_FUNCTIONS_H GP_GL_SHADER_CODE_SCALEQUADP_GLSL;
extern const char *g_drawQuadRGBP_GL2;
extern const char *g_drawQuad15BitP_GL2;
extern const char *g_drawQuadRGBICCP_GL2;
extern const char *g_drawQuad15BitICCP_GL2;
}