- added a software scene drawer to the GL renderer.
It still looks like shit and only works on the modern render path but at least the basics are working.
This commit is contained in:
parent
d474b849a5
commit
b34d7f9e08
32 changed files with 564 additions and 297 deletions
|
|
@ -177,11 +177,15 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
|||
FGLDebug::LabelObject(GL_TEXTURE, glTex->glTexID, name);
|
||||
lastbound[texunit] = glTex->glTexID;
|
||||
|
||||
if (!buffer)
|
||||
rw = GetTexDimension(w);
|
||||
rh = GetTexDimension(h);
|
||||
if (glBufferID > 0)
|
||||
{
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
buffer = nullptr;
|
||||
}
|
||||
else if (!buffer)
|
||||
{
|
||||
rw = GetTexDimension (w);
|
||||
rh = GetTexDimension (h);
|
||||
|
||||
// The texture must at least be initialized if no data is present.
|
||||
glTex->mipmapped = false;
|
||||
buffer=(unsigned char *)calloc(4,rw * (rh+1));
|
||||
|
|
@ -190,9 +194,6 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
|||
}
|
||||
else
|
||||
{
|
||||
rw = GetTexDimension (w);
|
||||
rh = GetTexDimension (h);
|
||||
|
||||
if (rw < w || rh < h)
|
||||
{
|
||||
// The texture is larger than what the hardware can handle so scale it down.
|
||||
|
|
@ -208,9 +209,42 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
|||
// store the physical size.
|
||||
texwidth = rw;
|
||||
texheight = rh;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, texformat, rw, rh, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
if (deletebuffer) free(buffer);
|
||||
int sourcetype;
|
||||
if (glTextureBytes > 0)
|
||||
{
|
||||
if (glTextureBytes < 4) glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
if (gl.legacyMode)
|
||||
{
|
||||
// Do not use 2 and 3 here. They won't do anything useful!!!
|
||||
static const int ITypes[] = { GL_LUMINANCE8, GL_LUMINANCE8_ALPHA8, GL_RGB8, GL_RGBA8 };
|
||||
static const int STypes[] = { GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGR, GL_BGRA };
|
||||
|
||||
texformat = ITypes[glTextureBytes - 1];
|
||||
sourcetype = STypes[glTextureBytes - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
static const int ITypes[] = { GL_R8, GL_RG8, GL_RGB8, GL_RGBA8 };
|
||||
static const int STypes[] = { GL_RED, GL_RG, GL_BGR, GL_BGRA };
|
||||
|
||||
texformat = ITypes[glTextureBytes - 1];
|
||||
sourcetype = STypes[glTextureBytes - 1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sourcetype = GL_BGRA;
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, texformat, rw, rh, 0, sourcetype, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
if (deletebuffer && buffer) free(buffer);
|
||||
else if (glBufferID)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
}
|
||||
|
||||
if (mipmap && TexFilter[gl_texture_filter].mipmapping)
|
||||
{
|
||||
|
|
@ -223,6 +257,33 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
|||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
void FHardwareTexture::AllocateBuffer(int w, int h, int texelsize)
|
||||
{
|
||||
int rw = GetTexDimension(w);
|
||||
int rh = GetTexDimension(h);
|
||||
if (texelsize < 1 || texelsize > 4) texelsize = 4;
|
||||
glTextureBytes = texelsize;
|
||||
if (rw == w || rh == h)
|
||||
{
|
||||
glGenBuffers(1, &glBufferID);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, glBufferID);
|
||||
glBufferData(GL_PIXEL_UNPACK_BUFFER, w*h*texelsize, nullptr, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t *FHardwareTexture::MapBuffer()
|
||||
{
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, glBufferID);
|
||||
return (uint8_t*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Creates a texture
|
||||
|
|
@ -313,6 +374,7 @@ void FHardwareTexture::CleanUnused(SpriteHits &usedtranslations)
|
|||
FHardwareTexture::~FHardwareTexture()
|
||||
{
|
||||
Clean(true);
|
||||
glDeleteBuffers(1, &glBufferID);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue