diff --git a/src/g_level.cpp b/src/g_level.cpp index 50d77d4a7..095e8cd2c 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -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 < 0) newself = 0; 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; } diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index f2cdd56d4..28ceb6be6 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -130,6 +130,31 @@ void gl_PatchMenu() 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) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); diff --git a/src/gl/compatibility/gl_swshader20.cpp b/src/gl/compatibility/gl_swshader20.cpp index 93d0ad14b..334a09612 100644 --- a/src/gl/compatibility/gl_swshader20.cpp +++ b/src/gl/compatibility/gl_swshader20.cpp @@ -78,7 +78,7 @@ LegacyShaderContainer::~LegacyShaderContainer() 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(); 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; } { + FString vertexsrc = defines + vertex; int lengths[1] = { (int)vertexsrc.Len() }; const char *sources[1] = { vertexsrc.GetChars() }; 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() }; const char *sources[1] = { fragmentsrc.GetChars() }; 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[1] = glGetUniformLocation(shader->Program, "uColor2"); - shader->ImageLocation = glGetUniformLocation(shader->Program, "Image"); - shader->PaletteLocation = glGetUniformLocation(shader->Program, "Palette"); + shader->ImageLocation = glGetUniformLocation(shader->Program, "tex"); + shader->PaletteLocation = glGetUniformLocation(shader->Program, "palette"); return shader; } diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 731b6daac..6f89d176f 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -802,7 +802,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) { 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 (!gl.legacyMode) + if (!gl.legacyMode || cmd.mTexture->UseType == ETextureType::SWCanvas) { gl_RenderState.SetFixedColormap(CM_FIRSTSPECIALCOLORMAPFORCED + int(index)); } diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index d6b660650..54590e9de 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -73,6 +73,7 @@ enum EPassType class FRenderState { + friend void gl_SetTextureMode(int type); bool mTextureEnabled; bool mFogEnabled; bool mGlowEnabled; diff --git a/src/gl/scene/gl_swscene.cpp b/src/gl/scene/gl_swscene.cpp index 7ee4766a4..b0cf14fd5 100644 --- a/src/gl/scene/gl_swscene.cpp +++ b/src/gl/scene/gl_swscene.cpp @@ -59,7 +59,11 @@ public: 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; } }; diff --git a/wadsrc/static/shaders/swgl/swshadergl2.fp b/wadsrc/static/shaders/swgl/swshadergl2.fp index 3a0ab3fa7..a65538fb5 100644 --- a/wadsrc/static/shaders/swgl/swshadergl2.fp +++ b/wadsrc/static/shaders/swgl/swshadergl2.fp @@ -1,5 +1,5 @@ uniform sampler2D tex; -uniform sampler2D pal; +uniform sampler2D palette; uniform vec4 uColor1; uniform vec4 uColor2; @@ -7,8 +7,8 @@ vec4 TextureLookup(vec2 tex_coord) { #ifdef PAL_TEX float index = texture2D(tex, tex_coord).x; - index = index * 256.0 + 0.5; // We only have full 256-color palettes here. - return texture2D(pal, vec2(index, 0.5)); + index = ((index * 255.0) + 0.5) / 256.0; + return texture2D(palette, vec2(index, 0.5)); #else return texture2D(tex, tex_coord); #endif @@ -16,13 +16,13 @@ vec4 TextureLookup(vec2 tex_coord) 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() { #ifndef SPECIALCM - FragColor = TextureLookup(gl_TexCoord[0].xy); + gl_FragColor = TextureLookup(gl_TexCoord[0].xy); #else vec4 frag = TextureLookup(gl_TexCoord[0].xy); float gray = grayscale(frag);