2019-10-20 06:07:12 +00:00
|
|
|
/*
|
|
|
|
** gl_texture.cpp
|
|
|
|
** high level GL texture interface
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2019 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2019-10-20 06:02:45 +00:00
|
|
|
#include "palette.h"
|
2013-05-15 02:17:17 +00:00
|
|
|
#include "build.h"
|
|
|
|
#include "polymost.h"
|
2019-10-10 21:29:13 +00:00
|
|
|
#include "textures.h"
|
|
|
|
#include "bitmap.h"
|
2019-11-05 22:35:38 +00:00
|
|
|
#include "v_font.h"
|
2020-05-23 12:40:54 +00:00
|
|
|
#include "palettecontainer.h"
|
2019-10-10 21:29:13 +00:00
|
|
|
#include "../../glbackend/glbackend.h"
|
2020-05-27 20:54:20 +00:00
|
|
|
#include "texturemanager.h"
|
2020-05-29 13:55:08 +00:00
|
|
|
#include "v_video.h"
|
2019-03-01 08:51:50 +00:00
|
|
|
|
2019-10-18 09:37:07 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Retrieve the texture to be used.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2020-05-29 13:55:08 +00:00
|
|
|
OpenGLRenderer::FHardwareTexture* GLInstance::LoadTexture(FTexture *tex, int textype, int palid)
|
2019-10-18 09:37:07 +00:00
|
|
|
{
|
|
|
|
if (textype == TT_INDEXED) palid = -1;
|
2020-05-29 13:55:08 +00:00
|
|
|
auto phwtex = tex->SystemTextures.GetHardwareTexture(palid, false);
|
2020-05-28 23:03:01 +00:00
|
|
|
if (phwtex) return (OpenGLRenderer::FHardwareTexture*)phwtex;
|
2019-10-18 09:37:07 +00:00
|
|
|
|
2020-05-29 13:55:08 +00:00
|
|
|
auto hwtex = static_cast<OpenGLRenderer::FHardwareTexture*>(screen->CreateHardwareTexture(textype == TT_INDEXED? 1:4));
|
|
|
|
if (hwtex) tex->SystemTextures.AddHardwareTexture(palid, false, hwtex);
|
2019-10-18 09:37:07 +00:00
|
|
|
return hwtex;
|
2019-10-17 22:20:27 +00:00
|
|
|
}
|
2019-10-17 19:44:34 +00:00
|
|
|
|
2020-05-29 22:30:56 +00:00
|
|
|
bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int method, int sampleroverride)
|
2020-05-29 19:53:28 +00:00
|
|
|
{
|
|
|
|
TexturePick pick;
|
|
|
|
if (!PickTexture(picnum, tex, paletteid, pick)) return false;
|
|
|
|
|
|
|
|
GLInterface.SetPalette(GetTranslationType(pick.translation & 0x7fffffff) - Translation_Remap);
|
|
|
|
GLInterface.SetPalswap(GetTranslationIndex(pick.translation));
|
|
|
|
GLInterface.SetBasepalTint(pick.basepalTint);
|
2020-01-11 21:18:06 +00:00
|
|
|
|
2020-05-29 19:53:28 +00:00
|
|
|
bool texbound[3] = {};
|
|
|
|
//int MatrixChange = 0;
|
|
|
|
//VSMatrix texmat;
|
|
|
|
|
|
|
|
// This is intentionally the same value for both parameters. The shader does not use the same uniform for modulation and overlay colors.
|
|
|
|
GLInterface.SetTinting(pick.tintFlags, pick.tintColor, pick.tintColor);
|
2020-01-11 21:18:06 +00:00
|
|
|
|
2019-10-17 22:20:27 +00:00
|
|
|
// Load the main texture
|
2020-05-29 13:55:08 +00:00
|
|
|
|
2020-05-29 19:53:28 +00:00
|
|
|
int TextureType = (pick.translation & 0x80000000) ? TT_INDEXED : TT_TRUECOLOR;
|
|
|
|
int lookuppal = pick.translation & 0x7fffffff;
|
|
|
|
int bindflags = 0;
|
|
|
|
|
2020-05-29 13:55:08 +00:00
|
|
|
auto mtex = LoadTexture(tex->GetTexture(), TextureType, lookuppal);
|
2019-10-17 22:20:27 +00:00
|
|
|
if (mtex)
|
|
|
|
{
|
2019-10-19 18:25:58 +00:00
|
|
|
auto sampler = (method & DAMETH_CLAMPED) ? (sampleroverride != -1 ? sampleroverride : SamplerClampXY) : SamplerRepeat;
|
2019-10-19 22:31:27 +00:00
|
|
|
if (TextureType == TT_INDEXED)
|
|
|
|
{
|
|
|
|
sampler = sampler + SamplerNoFilterRepeat - SamplerRepeat;
|
2020-05-29 19:53:28 +00:00
|
|
|
bindflags = CTF_Indexed;
|
2019-10-19 22:31:27 +00:00
|
|
|
}
|
2020-05-28 21:48:50 +00:00
|
|
|
else if (tex->isHardwareCanvas())
|
|
|
|
{
|
|
|
|
sampler = CLAMP_CAMTEX;
|
|
|
|
}
|
2019-12-30 19:44:37 +00:00
|
|
|
UseDetailMapping(false);
|
|
|
|
UseGlowMapping(false);
|
2019-11-10 18:42:26 +00:00
|
|
|
UseBrightmaps(false);
|
2019-10-17 19:44:34 +00:00
|
|
|
|
2020-05-29 13:55:08 +00:00
|
|
|
mtex->BindOrCreate(tex->GetTexture(), 0, sampler, lookuppal, bindflags);
|
2019-10-17 22:20:27 +00:00
|
|
|
BindTexture(0, mtex, sampler);
|
2020-01-18 21:41:08 +00:00
|
|
|
// Needs a) testing and b) verification for correctness. This doesn't look like it makes sense.
|
2020-05-29 19:53:28 +00:00
|
|
|
#if 0
|
2020-01-18 21:41:08 +00:00
|
|
|
if (rep && (rep->scale.x != 1.0f || rep->scale.y != 1.0f))
|
2019-10-17 22:20:27 +00:00
|
|
|
{
|
2020-01-18 21:41:08 +00:00
|
|
|
//texmat.loadIdentity();
|
|
|
|
//texmat.scale(rep->scale.x, rep->scale.y, 1.0f);
|
|
|
|
//GLInterface.SetMatrix(Matrix_Texture, &texmat);
|
2019-10-17 22:20:27 +00:00
|
|
|
}
|
2020-05-29 19:53:28 +00:00
|
|
|
#endif
|
2019-10-17 19:44:34 +00:00
|
|
|
|
2019-10-17 22:20:27 +00:00
|
|
|
// Also load additional layers needed for this texture.
|
2020-05-29 21:33:26 +00:00
|
|
|
if (hw_detailmapping)
|
2019-10-17 22:20:27 +00:00
|
|
|
{
|
2020-05-29 21:33:26 +00:00
|
|
|
auto det = tex->GetDetailmap();
|
|
|
|
auto detscale = tex->GetDetailScale();
|
2019-10-18 12:04:32 +00:00
|
|
|
if (det)
|
|
|
|
{
|
2020-05-29 21:33:26 +00:00
|
|
|
auto htex = LoadTexture(det, TT_TRUECOLOR, 0);
|
2019-10-17 22:20:27 +00:00
|
|
|
UseDetailMapping(true);
|
2020-05-29 21:33:26 +00:00
|
|
|
htex->BindOrCreate(det, 3, CLAMP_NONE, 0, 0);
|
2019-10-17 22:20:27 +00:00
|
|
|
BindTexture(3, htex, SamplerRepeat);
|
2019-12-30 19:44:37 +00:00
|
|
|
texbound[0] = true;
|
2019-10-17 22:20:27 +00:00
|
|
|
|
2020-05-29 21:33:26 +00:00
|
|
|
/* todo:
|
|
|
|
GLInterface.SetDetailScale(detscale);
|
2020-01-18 21:41:08 +00:00
|
|
|
*/
|
2019-10-17 22:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-29 21:33:26 +00:00
|
|
|
if (hw_glowmapping)
|
2019-10-17 22:20:27 +00:00
|
|
|
{
|
2020-05-29 21:33:26 +00:00
|
|
|
auto glow = tex->GetGlowmap();
|
2019-10-18 12:04:32 +00:00
|
|
|
if (glow)
|
|
|
|
{
|
2020-05-29 21:33:26 +00:00
|
|
|
auto htex = LoadTexture(glow, TT_TRUECOLOR, 0);
|
2019-10-17 22:20:27 +00:00
|
|
|
UseGlowMapping(true);
|
2020-05-29 21:33:26 +00:00
|
|
|
htex->BindOrCreate(glow, 4, sampler, 0, CTF_Upscale);
|
2019-10-17 22:20:27 +00:00
|
|
|
BindTexture(4, htex, SamplerRepeat);
|
2019-12-30 19:44:37 +00:00
|
|
|
texbound[1] = true;
|
2019-10-17 22:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-29 21:33:26 +00:00
|
|
|
|
|
|
|
if (!(globalflags & GLOBAL_NO_GL_FULLBRIGHT))
|
2019-10-17 22:20:27 +00:00
|
|
|
{
|
2020-05-29 21:33:26 +00:00
|
|
|
auto btex = tex->GetBrightmap();
|
|
|
|
if (btex)
|
2019-10-18 09:37:07 +00:00
|
|
|
{
|
2020-05-29 21:33:26 +00:00
|
|
|
auto htex = LoadTexture(btex, TT_TRUECOLOR, lookuppal);
|
|
|
|
if (htex != nullptr)
|
2019-10-18 09:37:07 +00:00
|
|
|
{
|
2019-11-10 18:42:26 +00:00
|
|
|
UseBrightmaps(true);
|
2020-05-29 21:33:26 +00:00
|
|
|
htex->BindOrCreate(btex, 5, sampler, 0, CTF_Upscale);
|
|
|
|
BindTexture(5, htex, sampler);
|
2019-12-30 19:44:37 +00:00
|
|
|
texbound[2] = true;
|
2019-10-18 09:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-17 22:20:27 +00:00
|
|
|
}
|
2019-12-30 19:44:37 +00:00
|
|
|
if (!texbound[0]) UnbindTexture(3);
|
|
|
|
if (!texbound[1]) UnbindTexture(4);
|
|
|
|
if (!texbound[2]) UnbindTexture(5);
|
2020-05-29 21:33:26 +00:00
|
|
|
|
2019-10-17 22:20:27 +00:00
|
|
|
}
|
2019-10-18 17:06:57 +00:00
|
|
|
else return false;
|
2019-10-17 19:44:34 +00:00
|
|
|
|
2020-05-29 21:33:26 +00:00
|
|
|
GLInterface.SetAlphaThreshold(tex->alphaThreshold);
|
2019-10-18 17:06:57 +00:00
|
|
|
return true;
|
2019-10-17 19:44:34 +00:00
|
|
|
}
|
2017-06-27 02:24:34 +00:00
|
|
|
|
2013-05-15 02:18:27 +00:00
|
|
|
|
2019-11-05 22:35:38 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
2020-05-29 13:55:08 +00:00
|
|
|
// stand-ins for the texture system. Nothing of this is used right now, but needs to be present to satisfy the linker
|
2019-11-05 22:35:38 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2020-05-24 19:19:33 +00:00
|
|
|
int PalCheck(int tex)
|
|
|
|
{
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitBuildTiles()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TArray<UserShaderDesc> usershaders;
|