- added an engine resource file.

Currently this only contains the main Polymost shaders and the resources from nblood.pk3.
The latter cannot be used yet because the Build resource management system is too stubborn to add the newly added file without some changes.
It's better to refactor the entire system instead.
This commit is contained in:
Christoph Oelckers 2019-10-04 23:29:00 +02:00
parent ae1e090716
commit d058084c10
77 changed files with 173 additions and 67 deletions

View file

@ -66,7 +66,7 @@ function( add_pk3 PK3_NAME PK3_DIR )
# Phase 1: Create a list of all source files for this PK3 archive, except
# for a couple of strife image file names that confuse CMake.
file(GLOB_RECURSE PK3_SRCS ${PK3_DIR}/*)
# Exclude from the source list some gdemolition .png files with brackets in the
# Exclude from the source list some demolition .png files with brackets in the
# file names here, because they confuse CMake.
# This only affects the list of source files shown in the IDE.
# It does not actually remove the files from the PK3 archive.
@ -415,7 +415,7 @@ add_subdirectory( tools )
add_subdirectory( libraries/dumb )
add_subdirectory( libraries/gdtoa )
add_subdirectory( libraries/enet )
#add_subdirectory( wadsrc )
add_subdirectory( wadsrc )
add_subdirectory( source )
if( NOT CMAKE_CROSSCOMPILING )

View file

@ -743,13 +743,9 @@ set( FASTMATH_SOURCES
thirdparty/src/xxhash.c
# Will we need this anymore with ZLib being available?
thirdparty/src/miniz.c
thirdparty/src/miniz_tdef.c
thirdparty/src/miniz_tinfl.c
# These will be exported to a resource file later - until that works they need to be explicitly compiled.
polymost1Vert.glsl.cpp
polymost1Frag.glsl.cpp
#thirdparty/src/miniz.c
#thirdparty/src/miniz_tdef.c
#thirdparty/src/miniz_tinfl.c
# Another bit of cruft just to make S(hit)DL happy...
sdlappicon.cpp

View file

@ -22,6 +22,7 @@
#ifdef WITHKPLIB
#include "kplib.h"
#include "zstring.h"
//Insert '|' in front of filename
//Doing this tells kzopen to load the file only if inside a .ZIP file
@ -723,6 +724,8 @@ static int32_t kread_grp(int32_t handle, void *buffer, int32_t leng);
static int32_t klseek_grp(int32_t handle, int32_t offset, int32_t whence);
static void kclose_grp(int32_t handle);
static bool alreadycalled;
extern FString progdir;
int initgroupfile(const char *filename)
{
char buf[70];

View file

@ -12,6 +12,7 @@ Ken Silverman's official web site: http://www.advsys.net/ken
#include "kplib.h"
#include "mdsprite.h"
#include "polymost.h"
#include "files.h"
#include "../../glbackend/glbackend.h"
extern char textfont[2048], smalltextfont[2048];
@ -140,10 +141,9 @@ int32_t r_useindexedcolortextures = -1;
static int32_t lastbasepal = -1;
static FHardwareTexture *paletteTextureIDs[MAXBASEPALS];
static FHardwareTexture *palswapTextureID = nullptr;
extern char const *polymost1Frag;
extern char const *polymost1Vert;
//extern char const *polymost1Frag;
//extern char const *polymost1Vert;
static GLuint polymost1CurrentShaderProgramID = 0;
static GLuint polymost1BasicShaderProgramID = 0;
static GLuint polymost1ExtendedShaderProgramID = 0;
static GLint polymost1TexSamplerLoc = -1;
static GLint polymost1PalSwapSamplerLoc = -1;
@ -671,9 +671,6 @@ void polymost_useDetailMapping(char useDetailMapping)
if (currentShaderProgramID != polymost1CurrentShaderProgramID || useDetailMapping == polymost1UseDetailMapping)
return;
if (useDetailMapping)
polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID);
polymost1UseDetailMapping = useDetailMapping;
glUniform1f(polymost1UseDetailMappingLoc, polymost1UseDetailMapping);
}
@ -683,9 +680,6 @@ void polymost_useGlowMapping(char useGlowMapping)
if (currentShaderProgramID != polymost1CurrentShaderProgramID || useGlowMapping == polymost1UseGlowMapping)
return;
if (useGlowMapping)
polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID);
polymost1UseGlowMapping = useGlowMapping;
glUniform1f(polymost1UseGlowMappingLoc, polymost1UseGlowMapping);
}
@ -738,6 +732,8 @@ void useShaderProgram(uint32_t shaderID)
currentShaderProgramID = shaderID;
}
FileReader GetBaseResource(const char* fn);
// one-time initialization of OpenGL for polymost
void polymost_glinit()
{
@ -746,31 +742,47 @@ void polymost_glinit()
currentTextureID = 0;
char allPacked = false;
auto fr1 = GetBaseResource("demolition/shaders/glsl/polymost.vp");
TArray<uint8_t> polymost1Vert = fr1.Read();
fr1 = GetBaseResource("demolition/shaders/glsl/polymost.fp");
TArray<uint8_t> polymost1Frag = fr1.Read();
// Zero-terminate both strings.
polymost1Vert.Push(0);
polymost1Frag.Push(0);
polymost1ExtendedShaderProgramID = glCreateProgram();
GLuint polymost1BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, polymost1Vert);
GLuint polymost1ExtendedFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, polymost1Frag);
GLuint polymost1BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, (char*)polymost1Vert.Data());
GLuint polymost1ExtendedFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, (char*)polymost1Frag.Data());
glAttachShader(polymost1ExtendedShaderProgramID, polymost1BasicVertexShaderID);
glAttachShader(polymost1ExtendedShaderProgramID, polymost1ExtendedFragmentShaderID);
glLinkProgram(polymost1ExtendedShaderProgramID);
int polymost1BasicFragLen = strlen(polymost1Frag);
char* polymost1BasicFrag = (char*) malloc(polymost1BasicFragLen);
memcpy(polymost1BasicFrag, polymost1Frag, polymost1BasicFragLen);
char* extDefineSubstr = strstr(polymost1BasicFrag, " #define POLYMOST1_EXTENDED");
if (extDefineSubstr)
{
//Disable extensions for basic fragment shader
extDefineSubstr[0] = '/';
extDefineSubstr[1] = '/';
}
polymost1BasicShaderProgramID = glCreateProgram();
GLuint polymost1BasicFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, polymost1BasicFrag, polymost1BasicFragLen);
glAttachShader(polymost1BasicShaderProgramID, polymost1BasicVertexShaderID);
glAttachShader(polymost1BasicShaderProgramID, polymost1BasicFragmentShaderID);
glLinkProgram(polymost1BasicShaderProgramID);
free(polymost1BasicFrag);
polymost1BasicFrag = 0;
char buffer[10000];
glGetShaderInfoLog(polymost1BasicVertexShaderID, 10000, NULL, buffer);
if (*buffer)
{
initprintf("Vertex shader:\n%s\n", buffer);
}
glGetShaderInfoLog(polymost1ExtendedFragmentShaderID, 10000, NULL, buffer);
if (*buffer)
{
initprintf("Fragment shader:\n%s\n", buffer);
}
glGetProgramInfoLog(polymost1ExtendedShaderProgramID, 10000, NULL, buffer);
if (*buffer)
{
initprintf("Linking:\n%s\n", buffer);
}
GLint status = 0;
glGetProgramiv(polymost1ExtendedShaderProgramID, GL_LINK_STATUS, &status);
auto linked = (status == GL_TRUE);
if (!linked)
{
// only print message if there's an error.
wm_msgbox("Fatal error", "Unable to init shader\n");
exit(1);
}
// set defaults
polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID);
glUniform1i(polymost1TexSamplerLoc, 0);
@ -779,10 +791,6 @@ void polymost_glinit()
glUniform1i(polymost1DetailSamplerLoc, 3);
glUniform1i(polymost1GlowSamplerLoc, 4);
polymost_setPalswapSize(256, numshades+1);
polymost_setCurrentShaderProgram(polymost1BasicShaderProgramID);
glUniform1i(polymost1TexSamplerLoc, 0);
glUniform1i(polymost1PalSwapSamplerLoc, 1);
glUniform1i(polymost1PaletteSamplerLoc, 2);
useShaderProgram(0);
lastbasepal = -1;
@ -1125,7 +1133,7 @@ void uploadtexture(FHardwareTexture *tex, int32_t doalloc, vec2_t siz, int32_t t
void uploadbasepalette(int32_t basepalnum)
{
if (!polymost1BasicShaderProgramID)
if (!polymost1ExtendedShaderProgramID)
{
//POGO: if we haven't initialized properly yet, we shouldn't be uploading base palettes
return;
@ -1157,7 +1165,7 @@ void uploadbasepalette(int32_t basepalnum)
void uploadpalswap(int32_t palookupnum)
{
if (!polymost1BasicShaderProgramID)
if (!polymost1ExtendedShaderProgramID)
{
//POGO: if we haven't initialized properly yet, we shouldn't be uploading palette swap tables
return;

View file

@ -1,13 +1,48 @@
#include <memory>
#include "glbackend.h"
#include "glad/glad.h"
#include "gl_samplers.h"
#include "baselayer.h"
#include "resourcefile.h"
std::unique_ptr<FResourceFile> engine_res;
// The resourge manager in cache1d is far too broken to add some arbitrary file without some adjustment.
// For now, keep this file here, until the resource management can be redone in a more workable fashion.
extern FString progdir;
void InitBaseRes()
{
if (!engine_res)
{
// If we get here for the first time, load the engine-internal data.
FString baseres = progdir + "demolition.pk3";
engine_res.reset(FResourceFile::OpenResourceFile(baseres, true, true));
if (!engine_res)
{
wm_msgbox("Fatal error", "Engine resources (demolition.pk3) not found");
exit(-1);
}
}
}
FileReader GetBaseResource(const char* fn)
{
auto lump = engine_res->FindLump(fn);
if (!lump)
{
wm_msgbox("Fatal error", "Base resource '%s' not found", fn);
exit(-1);
}
return lump->NewReader();
}
GLInstance GLInterface;
void GLInstance::Init()
{
InitBaseRes();
if (!mSamplers)
{
mSamplers = new FSamplerManager;

View file

@ -8,6 +8,7 @@
#include "zstring.h"
#include "winbits.h"
FString progdir;
//
// CheckWinVersion() -- check to see what version of Windows we happen to be running under (stripped down to what is actually still supported.)
//
@ -127,7 +128,13 @@ int32_t win_buildargs(char **argvbuf)
*wp = 0;
}
return buildargc;
// Figure out what directory the program resides in.
progdir = argvbuf[0];
auto lastsep = progdir.LastIndexOf('/');
if (lastsep != -1)
progdir.Truncate(lastsep + 1);
return buildargc;
}

BIN
wadsrc/CMakeLists.txt Normal file

Binary file not shown.

View file

@ -1,4 +1,3 @@
char const *polymost1Frag = R"shader(
#version 110
//include an additional space here so that we can programmatically search for and disable this preprocessor definition easily
@ -11,10 +10,8 @@ uniform sampler2D s_palswap;
//s_palette is the base palette texture where u is the color index
uniform sampler2D s_palette;
#ifdef POLYMOST1_EXTENDED
uniform sampler2D s_detail;
uniform sampler2D s_glow;
#endif
//u_texturePosSize is the texture position & size packaged into a single vec4 as {pos.x, pos.y, size.x, size.y}
uniform vec4 u_texturePosSize;
@ -37,10 +34,8 @@ uniform float u_npotEmulationXOffset;
uniform float u_shadeInterpolate;
uniform float u_brightness;
#ifdef POLYMOST1_EXTENDED
uniform float u_useDetailMapping;
uniform float u_useGlowMapping;
#endif
varying vec4 v_color;
varying float v_distance;
@ -81,19 +76,15 @@ void main()
palettedColor.a = c_one-floor(color.r);
color = mix(color, palettedColor, u_usePalette);
#ifdef POLYMOST1_EXTENDED
vec4 detailColor = texture2D(s_detail, gl_TexCoord[3].xy);
detailColor = mix(c_vec4_one, 2.0*detailColor, u_useDetailMapping*detailColor.a);
color.rgb *= detailColor.rgb;
#endif
if (u_useDetailMapping != 0.0)
{
vec4 detailColor = texture2D(s_detail, gl_TexCoord[3].xy);
detailColor = mix(c_vec4_one, 2.0*detailColor, detailColor.a);
color.rgb *= detailColor.rgb;
}
color = mix(color, c_vec4_one, u_useColorOnly);
// DEBUG
//color = texture2D(s_palswap, gl_TexCoord[0].xy);
//color = texture2D(s_palette, gl_TexCoord[0].xy);
//color = texture2D(s_texture, gl_TexCoord[0].yx);
color.rgb = mix(v_color.rgb*color.rgb, color.rgb, fullbright);
float fogEnabled = mix(u_fogEnabled, c_zero, u_usePalette);
@ -102,14 +93,15 @@ void main()
//float fogFactor = clamp(gl_FogFragCoord, fullbright, c_one);
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fogFactor);
#ifdef POLYMOST1_EXTENDED
vec4 glowColor = texture2D(s_glow, gl_TexCoord[4].xy);
color.rgb = mix(color.rgb, glowColor.rgb, u_useGlowMapping*glowColor.a*(c_one-u_useColorOnly));
#endif
if (u_useGlowMapping != 0.0)
{
vec4 glowColor = texture2D(s_glow, gl_TexCoord[4].xy);
color.rgb = mix(color.rgb, glowColor.rgb, glowColor.a*(c_one-u_useColorOnly));
}
color.a *= v_color.a;
color.rgb = pow(color.rgb, vec3(u_brightness));
gl_FragData[0] = color;
}
)shader";

View file

@ -1,4 +1,3 @@
char const *polymost1Vert = R"shader(
#version 110
varying vec4 v_color;
@ -32,4 +31,3 @@ void main()
v_color = gl_Color;
v_distance = gl_Vertex.z;
}
)shader";

View file

@ -0,0 +1 @@
include blood_widescreen.def

View file

@ -0,0 +1,66 @@
tilefromtexture 2200 { file "tiles/2200.png" ifcrc -588541517 }
tilefromtexture 2574 { file "tiles/2574.png" ifcrc -635337039 }
tilefromtexture 9216 { file "tiles/9216.png" }
tilefromtexture 9217 { file "tiles/9217.png" }
tilefromtexture 9218 { file "tiles/9218.png" }
tilefromtexture 9219 { file "tiles/9219.png" }
tilefromtexture 9220 { file "tiles/9220.png" }
tilefromtexture 9221 { file "tiles/9221.png" }
tilefromtexture 9222 { file "tiles/9222.png" }
tilefromtexture 9223 { file "tiles/9223.png" }
tilefromtexture 9224 { file "tiles/9224.png" }
tilefromtexture 9225 { file "tiles/9225.png" }
tilefromtexture 9226 { file "tiles/9226.png" }
tilefromtexture 9227 { file "tiles/9227.png" }
tilefromtexture 9228 { file "tiles/9228.png" }
tilefromtexture 9229 { file "tiles/9229.png" }
tilefromtexture 9230 { file "tiles/9230.png" }
tilefromtexture 9231 { file "tiles/9231.png" }
tilefromtexture 9232 { file "tiles/9232.png" }
tilefromtexture 9233 { file "tiles/9233.png" }
tilefromtexture 9234 { file "tiles/9234.png" }
tilefromtexture 9235 { file "tiles/9235.png" }
tilefromtexture 9236 { file "tiles/9236.png" }
tilefromtexture 9237 { file "tiles/9237.png" }
tilefromtexture 9238 { file "tiles/9238.png" }
tilefromtexture 9239 { file "tiles/9239.png" }
tilefromtexture 9240 { file "tiles/9240.png" }
tilefromtexture 9241 { file "tiles/9241.png" }
tilefromtexture 9242 { file "tiles/9242.png" }
tilefromtexture 9243 { file "tiles/9243.png" }
tilefromtexture 9244 { file "tiles/9244.png" }
tilefromtexture 9245 { file "tiles/9245.png" }
tilefromtexture 9246 { file "tiles/9246.png" }
tilefromtexture 9247 { file "tiles/9247.png" }
tilefromtexture 9248 { file "tiles/9248.png" }
tilefromtexture 9249 { file "tiles/9249.png" }
tilefromtexture 9250 { file "tiles/9250.png" }
tilefromtexture 9251 { file "tiles/9251.png" }
tilefromtexture 9252 { file "tiles/9252.png" }
tilefromtexture 9253 { file "tiles/9253.png" }
tilefromtexture 9254 { file "tiles/9254.png" }
tilefromtexture 9255 { file "tiles/9255.png" }
tilefromtexture 9256 { file "tiles/9256.png" }
tilefromtexture 9257 { file "tiles/9257.png" }
tilefromtexture 9258 { file "tiles/9258.png" }
tilefromtexture 9259 { file "tiles/9259.png" }
tilefromtexture 9260 { file "tiles/9260.png" }
tilefromtexture 9261 { file "tiles/9261.png" }
tilefromtexture 9262 { file "tiles/9262.png" }
tilefromtexture 9263 { file "tiles/9263.png" }
tilefromtexture 9264 { file "tiles/9264.png" }
tilefromtexture 9265 { file "tiles/9265.png" }
tilefromtexture 9266 { file "tiles/9266.png" }
tilefromtexture 9267 { file "tiles/9267.png" }
tilefromtexture 9268 { file "tiles/9268.png" }
tilefromtexture 9269 { file "tiles/9269.png" }
tilefromtexture 9270 { file "tiles/9270.png" }
tilefromtexture 9271 { file "tiles/9271.png" }
tilefromtexture 9272 { file "tiles/9272.png" }
tilefromtexture 9273 { file "tiles/9273.png" }
tilefromtexture 9274 { file "tiles/9274.png" }
tilefromtexture 9275 { file "tiles/9275.png" }
tilefromtexture 9276 { file "tiles/9276.png" }
tilefromtexture 9277 { file "tiles/9277.png" }
tilefromtexture 9278 { file "tiles/9278.png" }
tilefromtexture 9279 { file "tiles/9279.png" }

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B