Commit ab93ef80 authored by Evan Ramos's avatar Evan Ramos Committed by NY00123
Browse files

WIP: Engine: Add unsorted stuff for Duke 64

parent d3df3054
......@@ -1097,6 +1097,9 @@ static CONSTEXPR int32_t const enginecompatibilitymode = ENGINE_EDUKE32;
EXTERN int32_t crctab16[256];
EXTERN int32_t duke64;
extern bool (*rt_tileload_callback)(int16_t tileNum);
/*************************************************************************
POSITION VARIABLES:
......
......@@ -104,10 +104,14 @@ int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char
// in mact/src/mathutil.c: "Ken's reverse-engineering job".
// Note that mathutil.c contains practically the same code, but where the
// individual x/y(/z) distances are passed instead.
extern int32_t duke64;
static inline int32_t sepldist(const int32_t dx, const int32_t dy)
{
vec2_t d = { klabs(dx), klabs(dy) };
if (duke64)
return Blrintf(Bsqrtf(float(d.x)*float(d.x)+float(d.y)*float(d.y)));
if (!d.y) return d.x;
if (!d.x) return d.y;
......@@ -124,6 +128,9 @@ static inline int32_t sepdist(const int32_t dx, const int32_t dy, const int32_t
{
vec3_t d = { klabs(dx), klabs(dy), klabs(dz>>4) };
if (duke64)
return Blrintf(Bsqrtf(float(d.x)*float(d.x)+float(d.y)*float(d.y)+float(d.z)*float(d.z)));
if (d.x < d.y)
swaplong(&d.x, &d.y);
......
......@@ -27,6 +27,7 @@ extern void Polymost_prepare_loadboard(void);
//void phex(char v, char *s);
void polymost_setuptexture(const int32_t dameth, int filter);
void uploadtexture(int32_t doalloc, vec2_t siz, int32_t texfmt, coltype *pic, vec2_t tsiz, int32_t dameth);
void uploadtextureindexed(int32_t doalloc, vec2_t offset, vec2_t siz, intptr_t tile);
void uploadbasepalette(int32_t basepalnum);
......@@ -60,6 +61,8 @@ void polymost_useDetailMapping(char useDetailMapping);
void polymost_useGlowMapping(char useGlowMapping);
void polymost_usePaletteIndexing(char usePaletteIndexing);
GLuint polymost2_compileShader(GLenum shaderType, const char* const source, int* pLength = nullptr);
float* multiplyMatrix4f(float m0[4*4], const float m1[4*4]);
void polymost_initdrawpoly(void);
......@@ -116,6 +119,8 @@ extern int32_t r_vertexarrays;
extern int32_t r_yshearing;
extern int32_t r_persistentStreamBuffer;
extern int32_t r_brightnesshack;
extern int32_t polymostcenterhoriz;
extern GLuint drawpolyVertsID;
......@@ -223,6 +228,10 @@ enum {
DAMETH_INDEXED = 512,
DAMETH_N64 = 1024,
DAMETH_N64_INTENSIVITY = 2048,
DAMETH_N64_SCALED = 2097152,
// used internally by polymost_domost
DAMETH_BACKFACECULL = -1,
......@@ -287,6 +296,10 @@ enum pthtyp_flags {
PTH_INDEXED = 512,
PTH_ONEBITALPHA = 1024,
PTH_N64 = 2048,
PTH_N64_INTENSIVITY = 4096,
PTH_N64_SCALED = 8192,
// temporary until I create separate flags for samplers
PTH_DEPTH_SAMPLER = 16384,
PTH_TEMP_SKY_HACK = 32768
......@@ -320,6 +333,12 @@ EDUKE32_STATIC_ASSERT(TO_PTH_NOTRANSFIX(DAMETH_TRANS1) == 0);
EDUKE32_STATIC_ASSERT(TO_PTH_NOTRANSFIX(DAMETH_MASKPROPS) == 0);
#define TO_PTH_INDEXED(dameth) ((dameth)&DAMETH_INDEXED)
EDUKE32_STATIC_ASSERT(TO_PTH_INDEXED(DAMETH_INDEXED) == PTH_INDEXED);
#define TO_PTH_N64(dameth) (((dameth)&DAMETH_N64)<<1)
EDUKE32_STATIC_ASSERT(TO_PTH_N64(DAMETH_N64) == PTH_N64);
#define TO_PTH_N64_INTENSIVITY(dameth) (((dameth)&DAMETH_N64_INTENSIVITY)<<1)
EDUKE32_STATIC_ASSERT(TO_PTH_N64_INTENSIVITY(DAMETH_N64_INTENSIVITY) == PTH_N64_INTENSIVITY);
#define TO_PTH_N64_SCALED(dameth) (((dameth)&DAMETH_N64_SCALED)>>8)
EDUKE32_STATIC_ASSERT(TO_PTH_N64_SCALED(DAMETH_N64_SCALED) == PTH_N64_SCALED);
extern void gloadtile_art(int32_t,int32_t,int32_t,int32_t,int32_t,pthtyp *,int32_t);
extern int32_t gloadtile_hi(int32_t,int32_t,int32_t,hicreplctyp *,int32_t,pthtyp *,int32_t,polytintflags_t);
......
......@@ -366,6 +366,7 @@ void palettePostLoadTables(void)
redcol = paletteGetClosestColor(255, 0, 0);
// Bmemset(PaletteIndexFullbrights, 0, sizeof(PaletteIndexFullbrights));
if (!duke64)
for (bssize_t c = 0; c < 255; ++c) // skipping transparent color
{
uint8_t const index = palookup0[c];
......@@ -745,7 +746,7 @@ void videoSetPalette(char dabrightness, uint8_t dapalid, uint8_t flags)
}
videoSetGamma();
j = !gammabrightness ? curbrightness : 0;
j = (!gammabrightness || ((flags & 32) != 0 && videoGetRenderMode() != REND_POLYMOST))?curbrightness:0;
for (i=0; i<256; i++)
{
......@@ -762,6 +763,13 @@ void videoSetPalette(char dabrightness, uint8_t dapalid, uint8_t flags)
curpalettefaded[i].f = 0;
}
#ifdef USE_OPENGL
if ((flags & 32) != 0 && videoGetRenderMode() == REND_POLYMOST)
r_brightnesshack = curbrightness;
else
r_brightnesshack = 0;
#endif
if ((flags&16) && palfadedelta) // keep the fade
paletteSetFade(palfadedelta>>2);
......
......@@ -51,6 +51,7 @@ int32_t r_vertexarrays = 1;
int32_t r_yshearing;
int32_t r_persistentStreamBuffer = 1;
int32_t r_brightnesshack = 0;
int32_t r_rortexture = 0;
int32_t r_rortexturerange = 0;
int32_t r_rorphase = 0;
......@@ -149,7 +150,6 @@ int32_t glprojectionhacks = 2;
static GLuint polymosttext = 0;
int32_t glrendmode = REND_POLYMOST;
// used for fogcalc
static float fogresult, fogresult2;
coltypef fogcol, fogtable[MAXPALOOKUPS];
......@@ -221,6 +221,8 @@ static GLint polymost1NPOTEmulationFactorLoc = -1;
static float polymost1NPOTEmulationFactor = 1.f;
static GLint polymost1NPOTEmulationXOffsetLoc = -1;
static float polymost1NPOTEmulationXOffset = 0.f;
static GLint polymost1BrightnessLoc = -1;
static float polymost1Brightness = 1.f;
static GLint polymost1RotMatrixLoc = -1;
static float polymost1RotMatrix[16] = { 1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
......@@ -450,7 +452,7 @@ static void calcmat(vec3f_t a0, const vec2f_t *offset, float f, float mat[16], i
}
#endif // POLYMOST2
static GLuint polymost2_compileShader(GLenum shaderType, const char* const source, int * pLength = nullptr)
GLuint polymost2_compileShader(GLenum shaderType, const char* const source, int * pLength)
{
GLuint shaderID = glCreateShader(shaderType);
if (shaderID == 0)
......@@ -648,6 +650,7 @@ static void polymost_setCurrentShaderProgram(uint32_t programID)
polymost1NPOTEmulationLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulation");
polymost1NPOTEmulationFactorLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulationFactor");
polymost1NPOTEmulationXOffsetLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulationXOffset");
polymost1BrightnessLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_brightness");
polymost1RotMatrixLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_rotMatrix");
polymost1ShadeInterpolateLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_shadeInterpolate");
......@@ -668,6 +671,7 @@ static void polymost_setCurrentShaderProgram(uint32_t programID)
glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation);
glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor);
glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset);
glUniform1f(polymost1BrightnessLoc, polymost1Brightness);
glUniformMatrix4fv(polymost1RotMatrixLoc, 1, false, polymost1RotMatrix);
glUniform1f(polymost1ShadeInterpolateLoc, polymost1ShadeInterpolate);
}
......@@ -852,6 +856,15 @@ void polymost_shadeInterpolate(int32_t shadeInterpolate)
}
}
void polymost_setBrightness(int brightness)
{
if (gl.currentShaderProgramID == polymost1CurrentShaderProgramID)
{
polymost1Brightness = 8.f / (brightness + 8.f);
glUniform1f(polymost1BrightnessLoc, polymost1Brightness);
}
}
static void polymost_bindPth(pthtyp const * const pPth)
{
Bassert(pPth);
......@@ -1987,7 +2000,7 @@ static int32_t tile_is_sky(int32_t tilenum)
#endif
static void polymost_setuptexture(const int32_t dameth, int filter)
void polymost_setuptexture(const int32_t dameth, int filter)
{
gltexfiltermode = clamp(gltexfiltermode, 0, NUMGLFILTERMODES-1);
......@@ -6868,6 +6881,8 @@ void polymost_drawrooms()
buildgl_setDepthFunc(GL_ALWAYS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS
// glDepthRange(0.0, 1.0); //<- this is more widely supported than glPolygonOffset
polymost_setBrightness(r_brightnesshack);
gvrcorrection = viewingrange*(1.f/65536.f);
if (glprojectionhacks == 2)
{
......
......@@ -34,6 +34,7 @@ uniform float u_usePalette;
uniform float u_npotEmulation;
uniform float u_npotEmulationFactor;
uniform float u_npotEmulationXOffset;
uniform float u_brightness;
uniform float u_shadeInterpolate;
#ifdef POLYMOST1_EXTENDED
......@@ -107,11 +108,19 @@ void main()
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fogFactor);
#ifdef POLYMOST1_EXTENDED
vec4 glowColor = texture2D(s_glow, gl_TexCoord[4].xy);
coordY = mix(gl_TexCoord[4].y,gl_TexCoord[4].x,u_usePalette);
coordX = mix(gl_TexCoord[4].x,gl_TexCoord[4].y,u_usePalette);
period = floor(coordY/u_npotEmulationFactor);
coordX += u_npotEmulationXOffset*floor(mod(coordY,u_npotEmulationFactor));
coordY = period+mod(coordY,u_npotEmulationFactor);
newCoord = mix(gl_TexCoord[4].xy,mix(vec2(coordX,coordY),vec2(coordY,coordX),u_usePalette),u_npotEmulation);
vec4 glowColor = texture2D(s_glow, newCoord);
color.rgb = mix(color.rgb, glowColor.rgb, u_useGlowMapping*glowColor.a*(c_one-u_useColorOnly));
#endif
color.a *= v_color.a;
color.rgb = pow(color.rgb, vec3(u_brightness));
gl_FragData[0] = color;
}
......@@ -46,6 +46,8 @@ static const char *texcache_errors[TEXCACHEERRORS] = {
"glGetTexLevelParameteriv failed",
};
void (*gloadtile_n64)(int32_t dapic, int32_t dapal, int32_t tintpalnum, int32_t dashade, int32_t dameth, pthtyp *pth, int32_t doalloc) = nullptr;
static pthtyp *texcache_tryart(int32_t const dapicnum, int32_t const dapalnum, int32_t const dashade, int32_t dameth)
{
const int32_t j = dapicnum&(GLTEXCACHEADSIZ-1);
......@@ -62,6 +64,34 @@ static pthtyp *texcache_tryart(int32_t const dapicnum, int32_t const dapalnum, i
searchpalnum = 0;
}
if (dameth & DAMETH_N64)
{
// load from art
for (pth=texcache.list[j]; pth; pth=pth->next)
if (pth->picnum == dapicnum && (pth->flags & PTH_N64)
&& (pth->flags & (PTH_CLAMPED | PTH_N64_INTENSIVITY | PTH_N64_SCALED)) == (TO_PTH_CLAMPED(dameth) | TO_PTH_N64_INTENSIVITY(dameth) | TO_PTH_N64_SCALED(dameth)))
{
if (pth->flags & PTH_INVALIDATED)
{
pth->flags &= ~PTH_INVALIDATED;
gloadtile_n64(dapicnum, searchpalnum, tintpalnum, dashade, dameth, pth, 0);
pth->palnum = dapalnum;
}
return pth;
}
pth = (pthtyp *)Xcalloc(1,sizeof(pthtyp));
gloadtile_n64(dapicnum, searchpalnum, tintpalnum, dashade, dameth, pth, 1);
pth->palnum = dapalnum;
pth->next = texcache.list[j];
texcache.list[j] = pth;
return pth;
}
// load from art
for (pth=texcache.list[j]; pth; pth=pth->next)
if (pth->picnum == dapicnum &&
......
......@@ -631,6 +631,8 @@ int32_t artLoadFiles(const char *filename, int32_t askedsize)
//
static void tilePostLoad(int16_t tilenume);
bool (*rt_tileload_callback)(int16_t tileNum) = nullptr;
bool tileLoad(int16_t tileNum)
{
if ((unsigned) tileNum >= (unsigned) MAXTILES) return 0;
......@@ -644,7 +646,8 @@ bool tileLoad(int16_t tileNum)
g_cache.allocateBlock(&waloff[tileNum], dasiz, &walock[tileNum]);
}
tileLoadData(tileNum, dasiz, (char *) waloff[tileNum]);
if (!duke64 || !rt_tileload_callback || !rt_tileload_callback(tileNum))
tileLoadData(tileNum, dasiz, (char *) waloff[tileNum]);
#ifdef USE_OPENGL
if (videoGetRenderMode() >= REND_POLYMOST &&
......@@ -726,8 +729,7 @@ void tileLoadData(int16_t tilenume, int32_t dasiz, char *buffer)
if (artfil == buildvfs_kfd_invalid)
{
LOG_F(ERROR, "Failed opening .art file %s!", fn);
engineUnInit();
Bexit(EXIT_FAILURE);
return;
}
artfilnum = tfn;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment