raze-gles/source/build/src/glsurface.cpp
Christoph Oelckers bb4a19cf3a - added a few more texture formats to FHardwareTexture.
For brightmaps we do not need full RGBA8 data with mipmaps - RGBA2 without mipmaps is fully sufficient here and will save a lot of video memory.
2019-10-19 23:14:36 +02:00

87 lines
2 KiB
C++

/*
* glsurface.cpp
* A 32-bit rendering surface that can quickly blit 8-bit paletted buffers implemented in OpenGL.
*
* Copyright © 2018, Alex Dawson. All rights reserved.
*/
#include "glsurface.h"
#include "baselayer.h"
#include "build.h"
#include "tarray.h"
#include "../../glbackend/glbackend.h"
static TArray<uint8_t> buffer;
static FHardwareTexture* bufferTexture;
static vec2_t bufferRes;
static FHardwareTexture* paletteTexture;
bool glsurface_initialize(vec2_t bufferResolution)
{
if (buffer.Size())
glsurface_destroy();
bufferRes = bufferResolution;
buffer.Resize(bufferRes.x * bufferRes.y);
bufferTexture = GLInterface.NewTexture();
bufferTexture->CreateTexture(bufferRes.x, bufferRes.y, FHardwareTexture::Indexed, false);
glsurface_setPalette(curpalettefaded);
GLInterface.SetSurfaceShader();
return true;
}
void glsurface_destroy()
{
if (bufferTexture) delete bufferTexture;
bufferTexture = nullptr;
if (paletteTexture) delete paletteTexture;
paletteTexture = nullptr;
}
void glsurface_setPalette(void* pPalette)
{
if (!buffer.Size())
return;
if (!pPalette)
return;
if (!paletteTexture)
{
paletteTexture = GLInterface.NewTexture();
paletteTexture->CreateTexture(256, 1, FHardwareTexture::TrueColor, false);
}
paletteTexture->LoadTexture(palette);
GLInterface.BindTexture(1, paletteTexture, SamplerNoFilterClampXY);
}
void* glsurface_getBuffer()
{
return buffer.Data();
}
vec2_t glsurface_getBufferResolution()
{
return bufferRes;
}
void glsurface_blitBuffer()
{
if (!buffer.Size())
return;
bufferTexture->LoadTexture(buffer.Data());
GLInterface.BindTexture(0, bufferTexture, SamplerNoFilterClampXY);
auto data = GLInterface.AllocVertices(4);
auto vt = data.second;
vt[0].Set(-1.0f, 1.0f, 0.0f, 0.0f, 0.0f); //top-left
vt[1].Set(-1.0f, -1.0f, 0.0f, 0.0f, 1.0f); //bottom-left
vt[2].Set(1.0f, 1.0f, 0.0f, 1.0f, 0.0f); //top-right
vt[3].Set(1.0f, -1.0f, 0.0f, 1.0f, 1.0f); //bottom-right
GLInterface.Draw(DT_TRIANGLE_STRIP, data.first, 4);
}