mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-28 23:11:58 +00:00
- implemented shader support for rendering the SW renderer canvas with legacy OpenGL.
This commit is contained in:
parent
8cd3cf04e7
commit
94e8d59dde
7 changed files with 43 additions and 11 deletions
|
@ -138,7 +138,7 @@ CUSTOM_CVAR(Int, gl_lightmode, 3, CVAR_ARCHIVE | CVAR_NOINITCALL)
|
||||||
if (newself > 4) newself = 8; // use 8 for software lighting to avoid conflicts with the bit mask
|
if (newself > 4) newself = 8; // use 8 for software lighting to avoid conflicts with the bit mask
|
||||||
if (newself < 0) newself = 0;
|
if (newself < 0) newself = 0;
|
||||||
if (self != newself) self = newself;
|
if (self != newself) self = newself;
|
||||||
else if (level.info->lightmode == -1) level.lightmode = self;
|
else if ((level.info == nullptr || level.info->lightmode == -1)) level.lightmode = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,31 @@ void gl_PatchMenu()
|
||||||
|
|
||||||
void gl_SetTextureMode(int type)
|
void gl_SetTextureMode(int type)
|
||||||
{
|
{
|
||||||
|
if (type == TM_SWCANVAS)
|
||||||
|
{
|
||||||
|
int shader = V_IsTrueColor() ? 2 : 0;
|
||||||
|
float c1[4], c2[4];
|
||||||
|
if (gl_RenderState.mColormapState > CM_DEFAULT && gl_RenderState.mColormapState < CM_MAXCOLORMAP)
|
||||||
|
{
|
||||||
|
FSpecialColormap *scm = &SpecialColormaps[gl_RenderState.mColormapState - CM_FIRSTSPECIALCOLORMAP];
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
c1[i] = scm->ColorizeStart[i];
|
||||||
|
c2[i] = scm->ColorizeEnd[i] - scm->ColorizeStart[i];
|
||||||
|
}
|
||||||
|
c1[3] = 0;
|
||||||
|
c2[3] = 0;
|
||||||
|
shader++;
|
||||||
|
}
|
||||||
|
// Type 2 (unaltered true color) can be done without activating the shader.
|
||||||
|
if (shader != 2)
|
||||||
|
{
|
||||||
|
GLRenderer->legacyShaders->BindShader(shader, c1, c2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else type = TM_MODULATE;
|
||||||
|
}
|
||||||
|
glUseProgram(0);
|
||||||
if (type == TM_MASK)
|
if (type == TM_MASK)
|
||||||
{
|
{
|
||||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||||
|
|
|
@ -78,7 +78,7 @@ LegacyShaderContainer::~LegacyShaderContainer()
|
||||||
for (auto p : Shaders) if (p) delete p;
|
for (auto p : Shaders) if (p) delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
LegacyShader* LegacyShaderContainer::CreatePixelShader(const FString& vertexsrc, const FString& fragmentsrc, const FString &defines)
|
LegacyShader* LegacyShaderContainer::CreatePixelShader(const FString& vertex, const FString& fragment, const FString &defines)
|
||||||
{
|
{
|
||||||
auto shader = new LegacyShader();
|
auto shader = new LegacyShader();
|
||||||
char buffer[10000];
|
char buffer[10000];
|
||||||
|
@ -91,6 +91,7 @@ LegacyShader* LegacyShaderContainer::CreatePixelShader(const FString& vertexsrc,
|
||||||
if (shader->FragmentShader == 0) { Printf("glCreateShader(GL_FRAGMENT_SHADER) failed. Disabling OpenGL hardware acceleration.\n"); return nullptr; }
|
if (shader->FragmentShader == 0) { Printf("glCreateShader(GL_FRAGMENT_SHADER) failed. Disabling OpenGL hardware acceleration.\n"); return nullptr; }
|
||||||
|
|
||||||
{
|
{
|
||||||
|
FString vertexsrc = defines + vertex;
|
||||||
int lengths[1] = { (int)vertexsrc.Len() };
|
int lengths[1] = { (int)vertexsrc.Len() };
|
||||||
const char *sources[1] = { vertexsrc.GetChars() };
|
const char *sources[1] = { vertexsrc.GetChars() };
|
||||||
glShaderSource(shader->VertexShader, 1, sources, lengths);
|
glShaderSource(shader->VertexShader, 1, sources, lengths);
|
||||||
|
@ -98,6 +99,7 @@ LegacyShader* LegacyShaderContainer::CreatePixelShader(const FString& vertexsrc,
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
FString fragmentsrc = defines + fragment;
|
||||||
int lengths[1] = { (int)fragmentsrc.Len() };
|
int lengths[1] = { (int)fragmentsrc.Len() };
|
||||||
const char *sources[1] = { fragmentsrc.GetChars() };
|
const char *sources[1] = { fragmentsrc.GetChars() };
|
||||||
glShaderSource(shader->FragmentShader, 1, sources, lengths);
|
glShaderSource(shader->FragmentShader, 1, sources, lengths);
|
||||||
|
@ -138,8 +140,8 @@ LegacyShader* LegacyShaderContainer::CreatePixelShader(const FString& vertexsrc,
|
||||||
|
|
||||||
shader->ConstantLocations[0] = glGetUniformLocation(shader->Program, "uColor1");
|
shader->ConstantLocations[0] = glGetUniformLocation(shader->Program, "uColor1");
|
||||||
shader->ConstantLocations[1] = glGetUniformLocation(shader->Program, "uColor2");
|
shader->ConstantLocations[1] = glGetUniformLocation(shader->Program, "uColor2");
|
||||||
shader->ImageLocation = glGetUniformLocation(shader->Program, "Image");
|
shader->ImageLocation = glGetUniformLocation(shader->Program, "tex");
|
||||||
shader->PaletteLocation = glGetUniformLocation(shader->Program, "Palette");
|
shader->PaletteLocation = glGetUniformLocation(shader->Program, "palette");
|
||||||
|
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
|
@ -802,7 +802,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
||||||
{
|
{
|
||||||
auto index = cmd.mSpecialColormap - &SpecialColormaps[0];
|
auto index = cmd.mSpecialColormap - &SpecialColormaps[0];
|
||||||
if (index < 0 || (unsigned)index >= SpecialColormaps.Size()) index = 0; // if it isn't in the table FBitmap cannot use it. Shouldn't happen anyway.
|
if (index < 0 || (unsigned)index >= SpecialColormaps.Size()) index = 0; // if it isn't in the table FBitmap cannot use it. Shouldn't happen anyway.
|
||||||
if (!gl.legacyMode)
|
if (!gl.legacyMode || cmd.mTexture->UseType == ETextureType::SWCanvas)
|
||||||
{
|
{
|
||||||
gl_RenderState.SetFixedColormap(CM_FIRSTSPECIALCOLORMAPFORCED + int(index));
|
gl_RenderState.SetFixedColormap(CM_FIRSTSPECIALCOLORMAPFORCED + int(index));
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ enum EPassType
|
||||||
|
|
||||||
class FRenderState
|
class FRenderState
|
||||||
{
|
{
|
||||||
|
friend void gl_SetTextureMode(int type);
|
||||||
bool mTextureEnabled;
|
bool mTextureEnabled;
|
||||||
bool mFogEnabled;
|
bool mFogEnabled;
|
||||||
bool mGlowEnabled;
|
bool mGlowEnabled;
|
||||||
|
|
|
@ -59,7 +59,11 @@ public:
|
||||||
|
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
||||||
{
|
{
|
||||||
memcpy(bmp->GetPixels(), GPalette.BaseColors, 1024);
|
PalEntry *pe = (PalEntry*)bmp->GetPixels();
|
||||||
|
for (int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
pe[i] = GPalette.BaseColors[i].d | 0xff000000;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
uniform sampler2D pal;
|
uniform sampler2D palette;
|
||||||
uniform vec4 uColor1;
|
uniform vec4 uColor1;
|
||||||
uniform vec4 uColor2;
|
uniform vec4 uColor2;
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ vec4 TextureLookup(vec2 tex_coord)
|
||||||
{
|
{
|
||||||
#ifdef PAL_TEX
|
#ifdef PAL_TEX
|
||||||
float index = texture2D(tex, tex_coord).x;
|
float index = texture2D(tex, tex_coord).x;
|
||||||
index = index * 256.0 + 0.5; // We only have full 256-color palettes here.
|
index = ((index * 255.0) + 0.5) / 256.0;
|
||||||
return texture2D(pal, vec2(index, 0.5));
|
return texture2D(palette, vec2(index, 0.5));
|
||||||
#else
|
#else
|
||||||
return texture2D(tex, tex_coord);
|
return texture2D(tex, tex_coord);
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,13 +16,13 @@ vec4 TextureLookup(vec2 tex_coord)
|
||||||
|
|
||||||
float grayscale(vec4 rgb)
|
float grayscale(vec4 rgb)
|
||||||
{
|
{
|
||||||
return dot(color.rgb, vec3(0.4, 0.56, 0.14));
|
return dot(rgb.rgb, vec3(0.4, 0.56, 0.14));
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#ifndef SPECIALCM
|
#ifndef SPECIALCM
|
||||||
FragColor = TextureLookup(gl_TexCoord[0].xy);
|
gl_FragColor = TextureLookup(gl_TexCoord[0].xy);
|
||||||
#else
|
#else
|
||||||
vec4 frag = TextureLookup(gl_TexCoord[0].xy);
|
vec4 frag = TextureLookup(gl_TexCoord[0].xy);
|
||||||
float gray = grayscale(frag);
|
float gray = grayscale(frag);
|
||||||
|
|
Loading…
Reference in a new issue