mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-02-23 11:51:23 +00:00
- finished the palswap handling in the palette manager.
This commit is contained in:
parent
3b463bc38e
commit
dfaa162bb2
5 changed files with 52 additions and 85 deletions
|
@ -64,7 +64,23 @@ unsigned int FHardwareTexture::CreateTexture(int w, int h, bool eightbit, bool m
|
||||||
//
|
//
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
unsigned int FHardwareTexture::LoadTexture(unsigned char * buffer)
|
unsigned int FHardwareTexture::LoadTexture(const unsigned char * buffer)
|
||||||
|
{
|
||||||
|
return LoadTexturePart(buffer, 0, 0, mWidth, mHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int FHardwareTexture::LoadTexture(FBitmap& bmp)
|
||||||
|
{
|
||||||
|
return LoadTexture(bmp.GetPixels());
|
||||||
|
}
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//
|
||||||
|
// Loads the texture image into the hardware
|
||||||
|
//
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
unsigned int FHardwareTexture::LoadTexturePart(const unsigned char* buffer, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
if (glTexID == 0) return 0;
|
if (glTexID == 0) return 0;
|
||||||
|
|
||||||
|
@ -76,7 +92,7 @@ unsigned int FHardwareTexture::LoadTexture(unsigned char * buffer)
|
||||||
|
|
||||||
if (glTextureBytes < 4) glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
if (glTextureBytes < 4) glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mWidth, mHeight, srcformat, GL_UNSIGNED_BYTE, buffer);
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, srcformat, GL_UNSIGNED_BYTE, buffer);
|
||||||
if (mipmapped) glGenerateMipmap(GL_TEXTURE_2D);
|
if (mipmapped) glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
@ -85,11 +101,6 @@ unsigned int FHardwareTexture::LoadTexture(unsigned char * buffer)
|
||||||
return glTexID;
|
return glTexID;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int FHardwareTexture::LoadTexture(FBitmap& bmp)
|
|
||||||
{
|
|
||||||
return LoadTexture(bmp.GetPixels());
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// Destroys the texture
|
// Destroys the texture
|
||||||
|
|
|
@ -27,7 +27,8 @@ public:
|
||||||
//bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags);
|
//bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags);
|
||||||
|
|
||||||
unsigned int CreateTexture(int w, int h, bool eightbit, bool mipmapped);
|
unsigned int CreateTexture(int w, int h, bool eightbit, bool mipmapped);
|
||||||
unsigned int LoadTexture(unsigned char * buffer);
|
unsigned int LoadTexture(const unsigned char * buffer);
|
||||||
|
unsigned int LoadTexturePart(const unsigned char* buffer, int x, int y, int w, int h);
|
||||||
unsigned int LoadTexture(FBitmap &bmp);
|
unsigned int LoadTexture(FBitmap &bmp);
|
||||||
unsigned int GetTextureHandle();
|
unsigned int GetTextureHandle();
|
||||||
int GetSampler() { return mSampler; }
|
int GetSampler() { return mSampler; }
|
||||||
|
|
|
@ -35,10 +35,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "m_crc32.h"
|
#include "m_crc32.h"
|
||||||
#include "glad/glad.h"
|
|
||||||
#include "glbackend.h"
|
#include "glbackend.h"
|
||||||
#include "gl_samplers.h"
|
|
||||||
#include "gl_shader.h"
|
|
||||||
|
|
||||||
#include "baselayer.h"
|
#include "baselayer.h"
|
||||||
#include "resourcefile.h"
|
#include "resourcefile.h"
|
||||||
|
@ -214,13 +211,28 @@ void PaletteManager::BindPalette(int index)
|
||||||
|
|
||||||
void PaletteManager::SetPalswapData(int index, const uint8_t* data, int numshades_)
|
void PaletteManager::SetPalswapData(int index, const uint8_t* data, int numshades_)
|
||||||
{
|
{
|
||||||
// New palettes may only be added if declared transient or on startup.
|
|
||||||
// Otherwise this would require a renderer reset to flush out the textures affected by the change.
|
|
||||||
|
|
||||||
if (index < 0 || index > 255) return; // invalid index - ignore.
|
if (index < 0 || index > 255) return; // invalid index - ignore.
|
||||||
numshades = numshades_;
|
numshades = numshades_;
|
||||||
palswapmap[index] = FindPalswap(data);
|
palswapmap[index] = FindPalswap(data);
|
||||||
|
|
||||||
|
if (palswapTexture == nullptr)
|
||||||
|
{
|
||||||
|
palswapTexture = inst->NewTexture();
|
||||||
|
palswapTexture->CreateTexture(PALSWAP_TEXTURE_SIZE, PALSWAP_TEXTURE_SIZE, true, false);
|
||||||
|
palswapTexture->SetSampler(Sampler2DNoFilter);
|
||||||
|
}
|
||||||
|
else inst->UnbindTexture(1); // Unbind for updating.
|
||||||
|
|
||||||
|
int32_t column = index % (PALSWAP_TEXTURE_SIZE / 256);
|
||||||
|
int32_t row = index / (PALSWAP_TEXTURE_SIZE / 256);
|
||||||
|
int32_t rowOffset = (numshades + 1) * row;
|
||||||
|
if (rowOffset > PALSWAP_TEXTURE_SIZE)
|
||||||
|
{
|
||||||
|
OSD_Printf("Polymost: palswaps are too large for palswap tilesheet!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
palswapTexture->LoadTexturePart(data, 256 * column, rowOffset, 256, numshades + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
@ -231,7 +243,6 @@ void PaletteManager::SetPalswapData(int index, const uint8_t* data, int numshade
|
||||||
|
|
||||||
void PaletteManager::UpdatePalswaps(int width, int height)
|
void PaletteManager::UpdatePalswaps(int width, int height)
|
||||||
{
|
{
|
||||||
if (palswapTexture) delete palswapTexture;
|
|
||||||
for (auto& pal : palettes)
|
for (auto& pal : palettes)
|
||||||
{
|
{
|
||||||
pal.shadesdone = false;
|
pal.shadesdone = false;
|
||||||
|
@ -245,72 +256,5 @@ void PaletteManager::UpdatePalswaps(int width, int height)
|
||||||
(height - 1) * (1.f / PALSWAP_TEXTURE_SIZE) };
|
(height - 1) * (1.f / PALSWAP_TEXTURE_SIZE) };
|
||||||
|
|
||||||
inst->SetPalswapSize(&polymost1PalswapInnerSize.x);
|
inst->SetPalswapSize(&polymost1PalswapInnerSize.x);
|
||||||
|
inst->BindTexture(1, palswapTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GLInstance::SetPalswap(int index)
|
|
||||||
{
|
|
||||||
float v1 = index * renderState.PalswapSize[0];
|
|
||||||
float v2 = floorf(v1);
|
|
||||||
renderState.PalswapPos[0] = v1 - v2 + (0.5f / PALSWAP_TEXTURE_SIZE);
|
|
||||||
renderState.PalswapPos[1] = v2 * renderState.PalswapSize[1] + (0.5f / PALSWAP_TEXTURE_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
static void polymost_setPalswapSize(uint32_t width, uint32_t height)
|
|
||||||
{
|
|
||||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// No point porting this, it's too much work for a short lived solution.
|
|
||||||
#if 0
|
|
||||||
char allocateTexture = !palswapTextureID;
|
|
||||||
if (allocateTexture)
|
|
||||||
{
|
|
||||||
G etTextureHandle(&palswapTextureID);
|
|
||||||
}
|
|
||||||
g lBindTexture(GL _TEXTURE_2D, palswapTextureID);
|
|
||||||
if (allocateTexture)
|
|
||||||
{
|
|
||||||
g lTexParameteri(GL _TEXTURE_2D, GL _TEXTURE_BASE_LEVEL, 0);
|
|
||||||
g lTexParameteri(GL _TEXTURE_2D, GL _TEXTURE_MAX_LEVEL, 0);
|
|
||||||
g lTexParameteri(GL _TEXTURE_2D, GL _TEXTURE_MAG_FILTER, GL _NEAREST);
|
|
||||||
g lTexParameteri(GL _TEXTURE_2D, GL _TEXTURE_MIN_FILTER, GL _NEAREST);
|
|
||||||
g lTexParameteri(GL _TEXTURE_2D, GL _TEXTURE_MAX_ANISOTROPY_EXT, 1);
|
|
||||||
g lTexParameteri(GL _TEXTURE_2D, GL _TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE);
|
|
||||||
g lTexParameteri(GL _TEXTURE_2D, GL _TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE);
|
|
||||||
g lTexImage2D(GL _TEXTURE_2D, 0, GL _RED, PALSWAP_TEXTURE_SIZE, PALSWAP_TEXTURE_SIZE, 0, GL _RED, GL _UNSIGNED_BYTE, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t column = palookupnum % (PALSWAP_TEXTURE_SIZE / 256);
|
|
||||||
int32_t row = palookupnum / (PALSWAP_TEXTURE_SIZE / 256);
|
|
||||||
int32_t rowOffset = (numshades + 1) * row;
|
|
||||||
if (rowOffset > PALSWAP_TEXTURE_SIZE)
|
|
||||||
{
|
|
||||||
OSD_Printf("Polymost: palswaps are too large for palswap tilesheet!\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g lTexSubImage2D(GL _TEXTURE_2D, 0, 256 * column, rowOffset, 256, numshades + 1, GL _RED, GL _UNSIGNED_BYTE, palookup[palookupnum]);
|
|
||||||
|
|
||||||
polymost_setPalswapSize(256, numshades + 1);
|
|
||||||
|
|
||||||
static void polymost_updatePalette()
|
|
||||||
{
|
|
||||||
if (videoGetRenderMode() != REND_POLYMOST)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
polymost_setPalswap(globalpal);
|
|
||||||
polymost_setShade(globalshade);
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -438,6 +438,16 @@ void GLInstance::SetPalette(int index)
|
||||||
palmanager.BindPalette(index);
|
palmanager.BindPalette(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GLInstance::SetPalswap(int index)
|
||||||
|
{
|
||||||
|
float v1 = index * renderState.PalswapSize[0];
|
||||||
|
float v2 = floorf(v1);
|
||||||
|
renderState.PalswapPos[0] = v1 - v2 + (0.5f / PALSWAP_TEXTURE_SIZE);
|
||||||
|
renderState.PalswapPos[1] = v2 * renderState.PalswapSize[1] + (0.5f / PALSWAP_TEXTURE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PolymostRenderState::Apply(PolymostShader* shader)
|
void PolymostRenderState::Apply(PolymostShader* shader)
|
||||||
{
|
{
|
||||||
shader->Clamp.Set(Clamp);
|
shader->Clamp.Set(Clamp);
|
||||||
|
|
|
@ -22,6 +22,7 @@ struct PaletteData
|
||||||
PalEntry colors[256];
|
PalEntry colors[256];
|
||||||
float shades[512]; // two values (addshade and mulshade for each palswap.)
|
float shades[512]; // two values (addshade and mulshade for each palswap.)
|
||||||
bool shadesdone;
|
bool shadesdone;
|
||||||
|
int whiteindex, blackindex;
|
||||||
FHardwareTexture* paltexture;
|
FHardwareTexture* paltexture;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue