From 9402a006f4f9f0e86bb38cdf3003075c75044149 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 7 Dec 2023 18:35:27 +0100 Subject: [PATCH 1/8] FF_HORIZONTALFLIP and mobj->mirrored from: https://git.do.srb2.org/STJr/SRB2/-/merge_requests/987 --- src/dehacked.c | 1 + src/hardware/hw_drv.h | 2 +- src/hardware/hw_main.c | 7 +++++++ src/hardware/hw_md2.c | 3 ++- src/hardware/r_opengl/r_opengl.c | 15 +++++++++------ src/lua_mobjlib.c | 1 + src/p_mobj.h | 1 + src/p_pspr.h | 2 ++ src/p_saveg.c | 2 ++ src/r_things.c | 9 +++++++-- 10 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 349b66e7c..c641887fa 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8277,6 +8277,7 @@ struct { // Frame settings {"FF_FRAMEMASK",FF_FRAMEMASK}, + {"FF_HORIZONTALFLIP",FF_HORIZONTALFLIP}, {"FF_PAPERSPRITE",FF_PAPERSPRITE}, {"FF_ANIMATE",FF_ANIMATE}, {"FF_FULLBRIGHT",FF_FULLBRIGHT}, diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 56055a9dc..b80543f76 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -49,7 +49,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); //Hurdler: added for new development -EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, FSurfaceInfo *Surface); +EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); EXPORT void HWRAPI(CreateModelVBOs) (model_t *model); EXPORT void HWRAPI(SetTransform) (FTransform *stransform); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 12dfa7683..8a912e59c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5505,6 +5505,9 @@ void HWR_ProjectSprite(mobj_t *thing) size_t lumpoff; unsigned rot; UINT8 flip; + boolean mirrored = thing->mirrored; + boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); + angle_t ang; const boolean papersprite = (thing->frame & FF_PAPERSPRITE); INT32 heightsec, phs; @@ -5606,6 +5609,8 @@ void HWR_ProjectSprite(mobj_t *thing) #endif ang = R_PointToAngle (interp.x, interp.y) - interp.angle; + if (mirrored) + ang = InvAngle(ang); if (sprframe->rotate == SRF_SINGLE) { @@ -5710,6 +5715,8 @@ void HWR_ProjectSprite(mobj_t *thing) this_xscale = spritexscale * this_scale; this_yscale = spriteyscale * this_scale; + + flip = !flip != !hflip; if (flip) { diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index b3e6b8e95..9cd077588 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1149,6 +1149,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) INT32 tics = spr->mobj->tics; //mdlframe_t *next = NULL; const UINT8 flip = (UINT8)((spr->mobj->eflags & MFE_VERTICALFLIP) == MFE_VERTICALFLIP); + const UINT8 hflip = (UINT8)(!(spr->mobj->mirrored) != !(spr->mobj->frame & FF_HORIZONTALFLIP)); spritedef_t *sprdef; spriteframe_t *sprframe; spriteinfo_t *sprinfo; @@ -1435,7 +1436,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) p.y += ox * gr_viewcos; p.z += oy; - HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, md2->scale * xs, md2->scale * ys, flip, &Surf); + HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, md2->scale * xs, md2->scale * ys, flip, hflip, &Surf); } } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index b69a3c951..9292f8236 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3552,7 +3552,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) #define BUFFER_OFFSET(i) ((char*)(i)) -static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, FSurfaceInfo *Surface) +static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) { static GLRGBAFloat poly = {0,0,0,0}; static GLRGBAFloat tint = {0,0,0,0}; @@ -3613,12 +3613,13 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float pglEnable(GL_NORMALIZE); #ifdef USE_FTRANSFORM_MIRROR - // flipped is if the object is flipped + // flipped is if the object is vertically flipped + // hflipped is if the object is horizontally flipped // pos->flip is if the screen is flipped vertically // pos->mirror is if the screen is flipped horizontally // XOR all the flips together to figure out what culling to use! { - boolean reversecull = (flipped ^ pos->flip ^ pos->mirror); + boolean reversecull = (flipped ^ hflipped ^ pos->flip ^ pos->mirror); if (reversecull) pglCullFace(GL_FRONT); else @@ -3626,7 +3627,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float } #else // pos->flip is if the screen is flipped too - if (flipped != pos->flip) // If either are active, but not both, invert the model's culling + if (flipped ^ hflipped ^ pos->flip) // If one or three of these are active, but not two, invert the model's culling pglCullFace(GL_FRONT); else pglCullFace(GL_BACK); @@ -3636,6 +3637,8 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float pglTranslatef(pos->x, pos->z, pos->y); if (flipped) scaley = -scaley; + if (hflipped) + scalez = -scalez; #ifdef USE_FTRANSFORM_ANGLEZ pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); // rotate by slope from Kart #endif @@ -3764,9 +3767,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float // -----------------+ // HWRAPI DrawModel : Draw a model // -----------------+ -EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, FSurfaceInfo *Surface) +EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) { - DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, Surface); + DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface); } // -----------------+ diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 06c56645f..52eda4554 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -143,6 +143,7 @@ static const udata_field_t mobj_fields[] = { FIELD(mobj_t, cvmem, udatalib_getter_int32, udatalib_setter_int32), FIELD(mobj_t, standingslope, udatalib_getter_slope, mobj_standingslope_noset), FIELD(mobj_t, colorized, udatalib_getter_boolean, udatalib_setter_boolean), + FIELD(mobj_t, mirrored, udatalib_getter_boolean, udatalib_setter_boolean), FIELD(mobj_t, rollmodel, udatalib_getter_boolean, udatalib_setter_boolean), { NULL }, }; diff --git a/src/p_mobj.h b/src/p_mobj.h index 67a579c11..d53d7e3f0 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -395,6 +395,7 @@ typedef struct mobj_s boolean resetinterp; // if true, some fields should not be interpolated (see R_InterpolateMobjState implementation) boolean colorized; // Whether the mobj uses the rainbow colormap + boolean mirrored; // The object's rotations will be mirrored left to right, e.g., see frame AL from the right and AR from the left boolean rollmodel; // OpenGL: Should this model rotate? tic_t slamsoundtimer; diff --git a/src/p_pspr.h b/src/p_pspr.h index e74266002..5ac1d1d84 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -37,6 +37,8 @@ /// \brief Frame flags: only the frame number #define FF_FRAMEMASK 0x1ff +/// \brief Frame flags: Flip sprite horizontally +#define FF_HORIZONTALFLIP 0x400 /// \brief Frame flags: Thin, paper-like sprite (for collision equivalent, see MF_PAPERCOLLISION) #define FF_PAPERSPRITE 0x800 /// \brief Frame flags: Simple stateless animation diff --git a/src/p_saveg.c b/src/p_saveg.c index 530a0834c..d4e9b2f5e 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1990,6 +1990,8 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->stretchslam = 0; mobj->slamsoundtimer = 0; + mobj->mirrored = 0; + mobj->z = z; mobj->floorz = floorz; mobj->ceilingz = ceilingz; diff --git a/src/r_things.c b/src/r_things.c index 6334716ce..0278bf32a 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1315,9 +1315,10 @@ static void R_ProjectSprite(mobj_t *thing) size_t rot; UINT8 flip; - /*boolean vflip = (!(thing->eflags & MFE_VERTICALFLIP) != !R_ThingVerticallyFlipped(thing)); + /*boolean vflip = (!(thing->eflags & MFE_VERTICALFLIP) != !R_ThingVerticallyFlipped(thing));*/ + boolean mirrored = thing->mirrored; - boolean hflip = (!R_ThingHorizontallyFlipped(thing) != !mirrored);*/ + boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); INT32 lindex; @@ -1445,6 +1446,8 @@ static void R_ProjectSprite(mobj_t *thing) if (sprframe->rotate != SRF_SINGLE || papersprite) { ang = R_PointToAngle (interp.x, interp.y) - interp.angle; + if (mirrored) + ang = InvAngle(ang); if (papersprite) ang_scale = abs(FINESINE(ang>>ANGLETOFINESHIFT)); } @@ -1539,6 +1542,8 @@ static void R_ProjectSprite(mobj_t *thing) spr_offset += interp.spritexoffset * flipoffset; spr_topoffset += interp.spriteyoffset * flipoffset; } + + flip = !flip != !hflip; if (flip) offset = spr_offset - spr_width; -- 2.54.0 From d78fb05be0fc71aac84b7b72ee9dd860f747366b Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Dec 2023 07:50:23 +0100 Subject: [PATCH 2/8] use glGenerateMipmap instead of gluBuild2DMipmaps as advised by https://www.khronos.org/opengl/wiki/Common_Mistakes#gluBuild2DMipmaps fixes the godawful stuttering everywhere with mipmaps enabled --- src/hardware/r_opengl/r_opengl.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index b69a3c951..caf1beede 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -453,6 +453,10 @@ static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; typedef GLint (APIENTRY * PFNgluBuild2DMipmaps) (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data); static PFNgluBuild2DMipmaps pgluBuild2DMipmaps; +/* 3.0 functions */ +typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); +static PFNglGenerateMipmap pglGenerateMipmap; + /* 1.3 functions for multitexturing */ typedef void (APIENTRY *PFNglActiveTexture) (GLenum); static PFNglActiveTexture pglActiveTexture; @@ -1028,6 +1032,8 @@ void SetupGLFunc4(void) // GLU pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps"); + + pglGenerateMipmap = GetGLFunc("glGenerateMipmap"); } // jimita @@ -2080,7 +2086,10 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { - pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + + //pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff @@ -2101,7 +2110,9 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { - pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + //pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff @@ -2121,7 +2132,9 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) { if (MipMap) { - pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + //pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); // Control the mipmap level of detail pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); // the lower the number, the higer the detail if (pTexInfo->flags & TF_TRANSPARENT) @@ -3245,6 +3258,13 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) MipMap = GL_FALSE; min_filter = GL_LINEAR; } + + if (!pglGenerateMipmap) + { + MipMap = GL_FALSE; + min_filter = GL_LINEAR; + } + Flush(); //??? if we want to change filter mode by texture, remove this break; -- 2.54.0 From 8d123f5e83b44cf6a8c07b15a933c65006dcc57d Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Dec 2023 08:25:59 +0100 Subject: [PATCH 3/8] use the old thing when gl version below 3.0 also should compile for those with gl version lower than 3 hopefully uhhh idk if this even is right at all tbh --- src/hardware/r_opengl/r_opengl.c | 66 +++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index caf1beede..c467d92eb 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -454,8 +454,10 @@ typedef GLint (APIENTRY * PFNgluBuild2DMipmaps) (GLenum target, GLint internalFo static PFNgluBuild2DMipmaps pgluBuild2DMipmaps; /* 3.0 functions */ +#ifdef GL_VERSION_3_0 typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); static PFNglGenerateMipmap pglGenerateMipmap; +#endif /* 1.3 functions for multitexturing */ typedef void (APIENTRY *PFNglActiveTexture) (GLenum); @@ -1033,7 +1035,9 @@ void SetupGLFunc4(void) // GLU pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps"); +#ifdef GL_VERSION_3_0 pglGenerateMipmap = GetGLFunc("glGenerateMipmap"); +#endif } // jimita @@ -2086,10 +2090,18 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { - pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglGenerateMipmap(GL_TEXTURE_2D); - - //pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); +#ifdef GL_VERSION_3_0 + if (gl_version[0] == '1' || gl_version[0] == '2') +#endif + pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); +#ifdef GL_VERSION_3_0 + else + { + pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + } +#endif + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff @@ -2110,9 +2122,18 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { - pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglGenerateMipmap(GL_TEXTURE_2D); - //pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); +#ifdef GL_VERSION_3_0 + if (gl_version[0] == '1' || gl_version[0] == '2') +#endif + pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); +#ifdef GL_VERSION_3_0 + else + { + pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + } +#endif + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff @@ -2132,9 +2153,17 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) { if (MipMap) { - pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglGenerateMipmap(GL_TEXTURE_2D); - //pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); +#ifdef GL_VERSION_3_0 + if (gl_version[0] == '1' || gl_version[0] == '2') +#endif + pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); +#ifdef GL_VERSION_3_0 + else + { + pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + } +#endif // Control the mipmap level of detail pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); // the lower the number, the higer the detail if (pTexInfo->flags & TF_TRANSPARENT) @@ -3253,18 +3282,27 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) mag_filter = GL_LINEAR; min_filter = GL_NEAREST; } - if (!pgluBuild2DMipmaps) +#ifdef GL_VERSION_3_0 + if (gl_version[0] == '1' || gl_version[0] == '2') { - MipMap = GL_FALSE; - min_filter = GL_LINEAR; +#endif + if (!pgluBuild2DMipmaps) + { + MipMap = GL_FALSE; + min_filter = GL_LINEAR; + } +#ifdef GL_VERSION_3_0 } - + else + if (!pglGenerateMipmap) { MipMap = GL_FALSE; min_filter = GL_LINEAR; } +#endif + Flush(); //??? if we want to change filter mode by texture, remove this break; -- 2.54.0 From 5c4e00694a0a42412b8c5d48027dce3047fce4f0 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 12 Dec 2023 09:26:49 +0100 Subject: [PATCH 4/8] uh oops accidentally broke polyobjects --- src/hardware/hw_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3e3e23375..99b75a181 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3405,8 +3405,11 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t } // reference point for flat texture coord for each vertex around the polygon - flatxref = (float)((polysector->origVerts[0].x & (~flatflag)) / fflatsize); - flatyref = (float)((polysector->origVerts[0].y & (~flatflag)) / fflatsize); + flatxref = FIXED_TO_FLOAT(polysector->origVerts[0].x); + flatyref = FIXED_TO_FLOAT(polysector->origVerts[0].y); + + flatxref = (float)(((fixed_t)flatxref & (~flatflag)) / fflatsize); + flatyref = (float)(((fixed_t)flatyref & (~flatflag)) / fflatsize); // transform v3d = planeVerts; -- 2.54.0 From 58147117be2b1821c2e207a968f7106a1bca861a Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Dec 2023 11:12:23 +0100 Subject: [PATCH 5/8] gl 1.4 and gl2 can use GL_GENERATE_MIPMAP uhhhhhhh --- src/hardware/r_opengl/r_opengl.c | 61 +++++++++++++++++++------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index c467d92eb..f3a6e1220 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1969,6 +1969,10 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) const GLvoid *ptex = tex; INT32 w, h; GLuint texnum = 0; + + const GLubyte *versionGL = pglGetString(GL_VERSION); + int majorGL, minorGL; + sscanf(versionGL, "%d.%d", &majorGL, &minorGL); if (!pTexInfo->downloaded) { @@ -2090,18 +2094,20 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { -#ifdef GL_VERSION_3_0 - if (gl_version[0] == '1' || gl_version[0] == '2') -#endif + if (majorGL == 1 && minorGL >= 0 && minorGL < 4) pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) + { + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + } #ifdef GL_VERSION_3_0 - else + else if (majorGL >= 3) { pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); pglGenerateMipmap(GL_TEXTURE_2D); } #endif - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff @@ -2122,18 +2128,20 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { -#ifdef GL_VERSION_3_0 - if (gl_version[0] == '1' || gl_version[0] == '2') -#endif + if (majorGL == 1 && minorGL >= 0 && minorGL < 4) pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) + { + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + } #ifdef GL_VERSION_3_0 - else + else if (majorGL >= 3) { pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); pglGenerateMipmap(GL_TEXTURE_2D); } #endif - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff @@ -2153,12 +2161,15 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) { if (MipMap) { -#ifdef GL_VERSION_3_0 - if (gl_version[0] == '1' || gl_version[0] == '2') -#endif + if (majorGL == 1 && minorGL >= 0 && minorGL < 4) pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) + { + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + } #ifdef GL_VERSION_3_0 - else + else if (majorGL >= 3) { pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); pglGenerateMipmap(GL_TEXTURE_2D); @@ -3233,6 +3244,10 @@ EXPORT void HWRAPI(RenderSkyDome) (INT32 tex, INT32 texture_width, INT32 texture // ========================================================================== EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) { + const GLubyte *versionGL = pglGetString(GL_VERSION); + int majorGL, minorGL; + sscanf(versionGL, "%d.%d", &majorGL, &minorGL); + switch (IdState) { case HWD_SET_SHADERS: @@ -3282,25 +3297,23 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) mag_filter = GL_LINEAR; min_filter = GL_NEAREST; } -#ifdef GL_VERSION_3_0 - if (gl_version[0] == '1' || gl_version[0] == '2') + if (majorGL == 1 && minorGL >= 0 && minorGL < 4) { -#endif if (!pgluBuild2DMipmaps) { MipMap = GL_FALSE; min_filter = GL_LINEAR; } + } #ifdef GL_VERSION_3_0 - } else - - if (!pglGenerateMipmap) { - MipMap = GL_FALSE; - min_filter = GL_LINEAR; - } - + if (!pglGenerateMipmap) + { + MipMap = GL_FALSE; + min_filter = GL_LINEAR; + } + } #endif Flush(); //??? if we want to change filter mode by texture, remove this -- 2.54.0 From 14f0e70a9b1cd8422c97190825167be437d17647 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 13 Dec 2023 00:31:49 +0300 Subject: [PATCH 6/8] Retreive OpenGL version only once at startup --- src/hardware/hw_drv.h | 4 +++- src/hardware/hw_main.c | 2 ++ src/hardware/r_opengl/r_opengl.c | 20 +++++++++++++------- src/sdl/hwsym_sdl.c | 1 + src/sdl/i_video.c | 1 + 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 56055a9dc..da1eb39d5 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -28,6 +28,7 @@ // ========================================================================== EXPORT boolean HWRAPI(Init) (void); +EXPORT void HWRAPI(SetupGLInfo) (void); #if defined (PURESDL) || defined (macintosh) EXPORT void HWRAPI(SetPalette) (INT32 *, RGBA_t *gamma); #else @@ -95,6 +96,7 @@ EXPORT void HWRAPI(ClearLightTableCache) (void); struct hwdriver_s { Init pfnInit; + SetupGLInfo pfnSetupGLInfo; SetPalette pfnSetPalette; FinishUpdate pfnFinishUpdate; Draw2DLine pfnDraw2DLine; @@ -146,4 +148,4 @@ extern struct hwdriver_s hwdriver; #endif //not defined _CREATE_DLL_ -#endif //__HWR_DRV_H__ \ No newline at end of file +#endif //__HWR_DRV_H__ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3e3e23375..6da219df8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6599,6 +6599,8 @@ void HWR_Startup(void) CONS_Printf("HWR_Startup()...\n"); HWR_InitTextureCache(); HWR_InitMD2(); + + HWD.pfnSetupGLInfo(); } if (rendermode == render_opengl) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index f3a6e1220..e3783b4bf 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -166,6 +166,8 @@ static const GLfloat byte2float[256] = { 0.972549f, 0.976471f, 0.980392f, 0.984314f, 0.988235f, 0.992157f, 0.996078f, 1.000000f }; +// Loaded OpenGL version +static int majorGL = 0, minorGL = 0; // -----------------+ // GL_DBG_Printf : Output debug messages to debug log if DEBUG_TO_FILE is defined, @@ -1589,6 +1591,17 @@ EXPORT boolean HWRAPI(Init) (void) } +// -----------------+ +// SetupGLInfo : Retreive and store currently loaded OpenGL version +// -----------------+ +EXPORT void HWRAPI(SetupGLInfo) (void) +{ + const GLubyte *versionGL = pglGetString(GL_VERSION); + CONS_Printf("Loaded OpenGL version %s\n", (const char*)versionGL); + sscanf((const char*)versionGL, "%d.%d", &majorGL, &minorGL); +} + + // -----------------+ // ClearMipMapCache : Flush OpenGL textures from memory // -----------------+ @@ -1970,9 +1983,6 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) INT32 w, h; GLuint texnum = 0; - const GLubyte *versionGL = pglGetString(GL_VERSION); - int majorGL, minorGL; - sscanf(versionGL, "%d.%d", &majorGL, &minorGL); if (!pTexInfo->downloaded) { @@ -3244,10 +3254,6 @@ EXPORT void HWRAPI(RenderSkyDome) (INT32 tex, INT32 texture_width, INT32 texture // ========================================================================== EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) { - const GLubyte *versionGL = pglGetString(GL_VERSION); - int majorGL, minorGL; - sscanf(versionGL, "%d.%d", &majorGL, &minorGL); - switch (IdState) { case HWD_SET_SHADERS: diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 81cf4f29f..a64a11135 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -78,6 +78,7 @@ void *hwSym(const char *funcName,void *handle) funcPointer = &OglSdlSetPalette; GETFUNC(Init); + GETFUNC(SetupGLInfo); GETFUNC(Draw2DLine); GETFUNC(DrawPolygon); GETFUNC(SetBlend); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 06bece476..2eb843f60 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2109,6 +2109,7 @@ void I_StartupGraphics(void) if (rendermode == render_opengl) { HWD.pfnInit = hwSym("Init",NULL); + HWD.pfnSetupGLInfo = hwSym("SetupGLInfo",NULL); HWD.pfnFinishUpdate = NULL; HWD.pfnDraw2DLine = hwSym("Draw2DLine",NULL); HWD.pfnDrawPolygon = hwSym("DrawPolygon",NULL); -- 2.54.0 From f2ad6199bf63809beabeb60f1b5edbf187fe5152 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 13 Dec 2023 01:04:12 +0100 Subject: [PATCH 7/8] experiment: change max LOD to 16 suprisingly, this made stutters even less for some reason, will need to test things --- src/hardware/r_opengl/r_opengl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e3783b4bf..d8c11ca5c 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2122,7 +2122,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); } else @@ -2156,7 +2156,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); } else @@ -2190,7 +2190,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); } else { -- 2.54.0 From b56402a0a98291a6c8834b2a4061efaa0580b85c Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 16 Dec 2023 05:31:49 +0100 Subject: [PATCH 8/8] software sprites should do the same as opengl no idea why it even was like that tbh sliptiding was not toggable here Fixes https://github.com/Indev450/SRB2Kart-Saturn/issues/82 --- src/r_things.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 0278bf32a..d112c05f2 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1489,19 +1489,15 @@ static void R_ProjectSprite(mobj_t *thing) spr_topoffset = spritecachedinfo[lump].topoffset; #ifdef ROTSPRITE - if (thing->player) - { - sliptiderollangle = FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), ((cv_sloperoll.value == 1) ? thing->player->sliproll*(thing->player->sliptidemem) : 0)); - } - else - sliptiderollangle = 0; - - if ((thing->rollangle)||(thing->sloperoll)||sliptiderollangle) + if ((thing->rollangle)||(thing->sloperoll)||(thing->player && thing->player->sliproll)) { if (thing->player) - rollsum = (thing->rollangle) + (thing->sloperoll) + sliptiderollangle; + { + sliptiderollangle = cv_sliptideroll.value ? thing->player->sliproll*(thing->player->sliptidemem) : 0; + rollsum = (thing->rollangle)+(thing->sloperoll)+FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); + } else - rollsum = (thing->rollangle) + (thing->sloperoll); + rollsum = (thing->rollangle)+(thing->sloperoll); rollangle = R_GetRollAngle(rollsum); rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); -- 2.54.0