- use high level textures to render voxels.

This commit is contained in:
Christoph Oelckers 2020-05-30 00:30:56 +02:00
parent cca4fc609f
commit cdcb25bc1f
7 changed files with 55 additions and 53 deletions

View file

@ -194,7 +194,7 @@ struct voxmodel_t : public mdmodel_t
vec3_t siz;
vec3f_t piv;
int32_t is8bit;
TMap<int, OpenGLRenderer::FHardwareTexture*> *texIds;
TMap<int, FGameTexture*> *texIds;
};
EXTERN mdmodel_t **models;

View file

@ -1726,7 +1726,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
}
#endif
int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal);
GLInterface.SetModelTexture(tex, palid, det, detscale, glow);
GLInterface.SetTexture(-1, tex, palid, 0, CLAMP_XY);
if (tspr->clipdist & TSPR_FLAGS_MDHACK)
{

View file

@ -420,11 +420,13 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
polymost_outputGLDebugMessage(3, "polymost_drawpoly(dpxy:%p, n:%d, method_:%X), method: %X", dpxy, n, method_, method);
// This only takes effect for textures with their default set to SamplerClampXY.
int sampleroverride;
if (drawpoly_srepeat && drawpoly_trepeat) sampleroverride = SamplerRepeat;
else if (drawpoly_srepeat) sampleroverride = SamplerClampY;
else if (drawpoly_trepeat) sampleroverride = SamplerClampX;
else sampleroverride = SamplerClampXY;
int sampleroverride = CLAMP_NONE;
if (method & DAMETH_CLAMPED)
{
if (drawpoly_srepeat) sampleroverride |= CLAMP_Y;
if (drawpoly_trepeat) sampleroverride |= CLAMP_X;
}
int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal);
bool success = GLInterface.SetTexture(globalpicnum, tileGetTexture(globalpicnum), palid, method, sampleroverride);

View file

@ -11,6 +11,7 @@
#include "mdsprite.h"
#include "v_video.h"
#include "flatvertices.h"
#include "texturemanager.h"
#include "palette.h"
#include "../../glbackend/glbackend.h"
@ -32,42 +33,59 @@ static int32_t *shcntmal, *shcnt = 0, shcntp;
static int32_t mytexo5, *zbit, gmaxx, gmaxy, garea, pow2m1[33];
static voxmodel_t *gvox;
class FStaticImage : public FImageSource
{
TArray<uint8_t> buffer;
public:
FStaticImage(int w, int h, TArray<uint8_t>& srcbuffer)
{
Width = w;
Height = h;
buffer = std::move(srcbuffer);
bUseGamePalette = false;
}
int CopyPixels(FBitmap* bmp, int conversion) override
{
*bmp = FBitmap(buffer.Data(), 4*Width, Width, Height);
return 0;
}
};
//pitch must equal xsiz*4
static OpenGLRenderer::FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, const PalEntry *paldata)
static FGameTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, const PalEntry *paldata)
{
// Correct for GL's RGB order; also apply gamma here:
const coltype *const pic = (const coltype *)picbuf;
coltype *pic2 = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype));
TArray<uint8_t> buffer(xsiz * ysiz * sizeof(PalEntry));
PalEntry* pic2 = (PalEntry*)buffer.Data();
if (!is8bit)
{
for (bssize_t i=xsiz*ysiz-1; i>=0; i--)
for (int i=xsiz*ysiz-1; i>=0; i--)
{
pic2[i].r = pic[i].b;
pic2[i].r = pic[i].r;
pic2[i].g = pic[i].g;
pic2[i].b = pic[i].r;
pic2[i].b = pic[i].b;
pic2[i].a = 255;
}
}
else
{
for (bssize_t i=xsiz*ysiz-1; i>=0; i--)
for (int i=xsiz*ysiz-1; i>=0; i--)
{
const int32_t ii = pic[i].a;
pic2[i].r = paldata[ii].b;
pic2[i].r = paldata[ii].r;
pic2[i].g = paldata[ii].g;
pic2[i].b = paldata[ii].r;
pic2[i].b = paldata[ii].b;
pic2[i].a = 255;
}
}
auto tex = GLInterface.NewTexture(4);
tex->CreateTexture((uint8_t*)pic2, xsiz, ysiz, 15, true, "Voxel"); // Mipmap should be false for this but currently this causes render errors because the proper sampler cannot be selected.
Xfree(pic2);
return tex;
auto tt = MakeGameTexture(new FImageTexture(new FStaticImage(xsiz, ysiz, buffer)), "", ETextureType::Special);
TexMan.AddGameTexture(tt, false);
return tt;
}
static int32_t getvox(int32_t x, int32_t y, int32_t z)
@ -838,18 +856,6 @@ void voxfree(voxmodel_t *m)
DO_FREE_AND_NULL(m->mytex);
DO_FREE_AND_NULL(m->quad);
if (m->texIds)
{
TMap<int, OpenGLRenderer::FHardwareTexture*>::Iterator it(*m->texIds);
TMap<int, OpenGLRenderer::FHardwareTexture*>::Pair* pair;
while (it.NextPair(pair))
{
if (pair->Value) delete pair->Value;
}
delete m->texIds;
}
Xfree(m);
}
@ -1084,11 +1090,6 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
pc[0] = pc[1] = pc[2] = 1.f;
auto& h = lookups.tables[globalpal];
if (h.tintFlags & (TINTF_USEONART|TINTF_ALWAYSUSEART))
GLInterface.SetTinting(h.tintFlags, h.tintColor, h.tintColor);
else
GLInterface.SetTinting(-1, 0xffffff, 0xffffff);
if (!shadowHack)
{
@ -1135,9 +1136,9 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
#if 1
int palId = TRANSLATION(Translation_Remap + curbasepal, globalpal);
auto palette = GPalette.TranslationToTable(palId);
if (!m->texIds) m->texIds = new TMap<int, OpenGLRenderer::FHardwareTexture*>;
if (!m->texIds) m->texIds = new TMap<int, FGameTexture*>;
auto pTex = m->texIds->CheckKey(palId);
OpenGLRenderer::FHardwareTexture* htex;
FGameTexture* htex;
if (!pTex)
{
htex = gloadtex(m->mytex, m->mytexx, m->mytexy, m->is8bit, palette->Palette);
@ -1149,7 +1150,15 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
}
GLInterface.SetPalswap(globalpal);
GLInterface.BindTexture(0, htex, -1);
GLInterface.SetTexture(-1, htex, 0/*TRANSLATION(Translation_Remap + curbasepal, globalpal)*/, 0, CLAMP_XY);
// This must be done after setting up the texture.
auto& h = lookups.tables[globalpal];
if (h.tintFlags & (TINTF_USEONART|TINTF_ALWAYSUSEART))
GLInterface.SetTinting(h.tintFlags, h.tintColor, h.tintColor);
else
GLInterface.SetTinting(-1, 0xffffff, 0xffffff);
GLInterface.UseBrightmaps(false);
GLInterface.UseGlowMapping(false);
GLInterface.UseDetailMapping(false);

View file

@ -61,7 +61,7 @@ OpenGLRenderer::FHardwareTexture* GLInstance::LoadTexture(FTexture *tex, int tex
return hwtex;
}
bool GLInstance::SetTextureInternal(int picnum, FGameTexture* tex, int paletteid, int method, int sampleroverride, FGameTexture *det, float detscale, FGameTexture *glow)
bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int method, int sampleroverride)
{
TexturePick pick;
if (!PickTexture(picnum, tex, paletteid, pick)) return false;

View file

@ -289,7 +289,7 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
bool reset = false;
for (int i = 0; i < MAX_TEXTURES; i++)
{
if (texIds[i] != oldState.TexId[i] || samplerIds[i] != oldState.SamplerId[i])
if ( texIds[i] != oldState.TexId[i] || samplerIds[i] != oldState.SamplerId[i])
{
if (i != 0)
{

View file

@ -480,17 +480,8 @@ public:
}
OpenGLRenderer::FHardwareTexture *LoadTexture(FTexture* tex, int texturetype, int palid);
bool SetTextureInternal(int globalpicnum, FGameTexture* tex, int palette, int method, int sampleroverride, FGameTexture *det, float detscale, FGameTexture *glow);
bool SetTexture(int globalpicnum, FGameTexture* tex, int palette, int method, int sampleroverride)
{
return SetTextureInternal(globalpicnum, tex, palette, method, sampleroverride, nullptr, 1, nullptr);
}
bool SetModelTexture(FGameTexture *tex, int palette, FGameTexture *det, float detscale, FGameTexture *glow)
{
return SetTextureInternal(-1, tex, palette, 8/*DAMETH_MODEL*/, -1, det, detscale, glow);
}
bool SetTexture(int globalpicnum, FGameTexture* tex, int palette, int method, int sampleroverride);
};
extern GLInstance GLInterface;