Framebuffer uses vertex arrays for tile rendering
This commit is contained in:
parent
277617ed88
commit
70b9959799
|
@ -12,6 +12,7 @@
|
|||
#include "Glide.h"
|
||||
#include "GlideApplication.h"
|
||||
#include "GlideSettings.h"
|
||||
#include "GLRender.h"
|
||||
#include "GLRenderUpdateState.h"
|
||||
#include "GLColorAlphaCombineEnvTables.h"
|
||||
|
||||
|
@ -84,7 +85,7 @@ bool Framebuffer::initialise_buffers(BufferStruct* framebuffer, BufferStruct* te
|
|||
GLfloat zero = 0.0f;
|
||||
if (m_use_client_storage)
|
||||
{
|
||||
glGenTextures( m_max_client_storage_textures, &m_tex_name[0]);
|
||||
glGenTextures(m_max_client_storage_textures, &m_tex_name[0]);
|
||||
for(int i = 0; i < m_max_client_storage_textures; i++)
|
||||
{
|
||||
glPrioritizeTextures(1, &m_tex_name[i], &zero);
|
||||
|
@ -103,7 +104,7 @@ bool Framebuffer::initialise_buffers(BufferStruct* framebuffer, BufferStruct* te
|
|||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
}
|
||||
// If a game has it's own tilesize table, use
|
||||
// If a game has its own tilesize table, use
|
||||
// the largest tiles for opaque renderings
|
||||
GLint y_step = y_tile == 0 ? m_y_step_start_opaque : m_y_step_start;
|
||||
// init default/opaque tilesize table
|
||||
|
@ -248,7 +249,15 @@ bool Framebuffer::end_write(FxU32 alpha, GLfloat depth, bool pixelpipeline)
|
|||
// to determine if a tile contains any pixels to be rendered.
|
||||
if (m_glAlpha == 0) return false;
|
||||
set_gl_state(pixelpipeline);
|
||||
draw(m_custom_tilesizes ? m_custom_tilesizes : m_tilesizes, pixelpipeline);
|
||||
const tilesize* tilesizes = m_custom_tilesizes ? m_custom_tilesizes : m_tilesizes;
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
drawCompiledVertexArrays(tilesizes, pixelpipeline);
|
||||
}
|
||||
else
|
||||
{
|
||||
draw(tilesizes, pixelpipeline);
|
||||
}
|
||||
restore_gl_state(pixelpipeline);
|
||||
return true;
|
||||
}
|
||||
|
@ -437,7 +446,7 @@ void Framebuffer::set_gl_state(bool pixelpipeline)
|
|||
{
|
||||
glClientActiveTextureARB(OpenGL.FogTextureUnit);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, NULL);
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
@ -456,18 +465,53 @@ void Framebuffer::set_gl_state(bool pixelpipeline)
|
|||
if (disable_coloralpha_texture_unit_2)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit2);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit2);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
// On MacOS9 (Classic?) the texcoord pointer needs to be reset
|
||||
// to the default value when glLockArrays/glUnlockArrays is used
|
||||
glTexCoordPointer( 4, GL_FLOAT, 0, NULL );
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
if (disable_fog_texture_unit || disable_coloralpha_texture_unit_2) glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
if (disable_fog_texture_unit || disable_coloralpha_texture_unit_2)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
}
|
||||
}
|
||||
if (!OpenGL.ColorAlphaUnitColorEnabledState[0] && !OpenGL.ColorAlphaUnitAlphaEnabledState[0])
|
||||
{
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, &OGLRender.TTexture[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (disable_fog_texture_unit) glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
if (OpenGL.Texture == false) glEnable(GL_TEXTURE_2D);
|
||||
if (disable_fog_texture_unit)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
}
|
||||
}
|
||||
if (OpenGL.Texture == false)
|
||||
{
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, &OGLRender.TTexture[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glReportError();
|
||||
|
@ -591,11 +635,7 @@ void Framebuffer::restore_gl_state(bool pixelpipeline)
|
|||
{
|
||||
glClientActiveTextureARB(OpenGL.FogTextureUnit);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
}
|
||||
if (OpenGL.ColorAlphaUnit2 == 0)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glTexCoordPointer(1, GL_FLOAT, 0, &OGLRender.TFog[0]);
|
||||
}
|
||||
}
|
||||
if (OpenGL.Fog &&
|
||||
|
@ -613,10 +653,28 @@ void Framebuffer::restore_gl_state(bool pixelpipeline)
|
|||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit2);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit2);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, &OGLRender.TTexture[0]);
|
||||
}
|
||||
}
|
||||
if (enable_fog_texture_unit || enable_coloralpha_texture_unit_2)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
}
|
||||
}
|
||||
if (enable_fog_texture_unit || enable_coloralpha_texture_unit_2) glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
if (!OpenGL.ColorAlphaUnitColorEnabledState[0] && !OpenGL.ColorAlphaUnitAlphaEnabledState[0])
|
||||
{
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer( 4, GL_FLOAT, 0, NULL );
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
// Restore the previous texture environment
|
||||
|
@ -624,8 +682,21 @@ void Framebuffer::restore_gl_state(bool pixelpipeline)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (enable_fog_texture_unit)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
}
|
||||
}
|
||||
if (OpenGL.Texture == false)
|
||||
{
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer( 4, GL_FLOAT, 0, NULL );
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
// Restore the previous texture environment
|
||||
|
@ -639,9 +710,9 @@ void Framebuffer::restore_gl_state(bool pixelpipeline)
|
|||
|
||||
glReportError();
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1);
|
||||
VERIFY_TEXTURE_ENABLED_STATE();
|
||||
}
|
||||
|
||||
|
||||
bool Framebuffer::draw(const tilesize* tilesizetable, bool pixelpipeline)
|
||||
{
|
||||
#ifdef OGL_FRAMEBUFFER
|
||||
|
@ -767,7 +838,165 @@ bool Framebuffer::draw(const tilesize* tilesizetable, bool pixelpipeline)
|
|||
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE , false);
|
||||
glReportError();
|
||||
}
|
||||
s_Framebuffer.SetRenderBufferChanged();
|
||||
return y == m_height && x == m_width;
|
||||
}
|
||||
|
||||
bool Framebuffer::drawCompiledVertexArrays(const tilesize* tilesizetable, bool pixelpipeline)
|
||||
{
|
||||
#ifdef OGL_FRAMEBUFFER
|
||||
GlideMsg( "Framebuffer::draw(---, %d)\n", pixelpipeline);
|
||||
#endif
|
||||
|
||||
glReportErrors("Framebuffer::draw()");
|
||||
|
||||
// Compute the coordinates
|
||||
const int framebuffertrianglesstart = OGLRender.FrameBufferTrianglesStart;
|
||||
TColorStruct* pC = &OGLRender.TColor[framebuffertrianglesstart];
|
||||
TVertexStruct* pV = &OGLRender.TVertex[framebuffertrianglesstart];
|
||||
TTextureStruct* pTS = &OGLRender.TTexture[framebuffertrianglesstart];
|
||||
int n = 0;
|
||||
GLint x;
|
||||
GLint y;
|
||||
GLint x_step;
|
||||
GLint y_step;
|
||||
y = 0;
|
||||
for(int w = 0; y < m_height && w < MaxTiles; w++, y += y_step)
|
||||
{
|
||||
y_step = tilesizetable[w].y;
|
||||
x = 0;
|
||||
for(int v = 0; x < m_width && v < MaxTiles; v++, x += x_step)
|
||||
{
|
||||
x_step = tilesizetable[w].x[v];
|
||||
// Write coordinates counter clockwise into render buffers
|
||||
pC->ar = pC->ag = pC->ab =
|
||||
pC->br = pC->bg = pC->bb =
|
||||
pC->cr = pC->cg = pC->cb =
|
||||
pC->aa = pC->ba = pC->ca = 1.0;
|
||||
pV->ax = x;
|
||||
pV->ay = y;
|
||||
pV->az = m_glDepth;
|
||||
pV->bx = x + x_step;
|
||||
pV->by = y;
|
||||
pV->bz = m_glDepth;
|
||||
pV->cx = x + x_step;
|
||||
pV->cy = y + y_step;
|
||||
pV->cz = m_glDepth;
|
||||
pTS->as = 0.0;
|
||||
pTS->at = 0.0;
|
||||
pTS->bs = 1.0;
|
||||
pTS->bt = 0.0;
|
||||
pTS->cs = 1.0;
|
||||
pTS->ct = 1.0;
|
||||
pTS->aq = pTS->bq = pTS->cq = 0.0f;
|
||||
pTS->aoow = pTS->boow = pTS->coow = 1.0;
|
||||
pC++; pV++; pTS++; n++;
|
||||
|
||||
pC->ar = pC->ag = pC->ab =
|
||||
pC->br = pC->bg = pC->bb =
|
||||
pC->cr = pC->cg = pC->cb =
|
||||
pC->aa = pC->ba = pC->ca = 1.0;
|
||||
pV->ax = x + x_step;
|
||||
pV->ay = y + y_step;
|
||||
pV->az = m_glDepth;
|
||||
pV->bx = x;
|
||||
pV->by = y + y_step;
|
||||
pV->bz = m_glDepth;
|
||||
pV->cx = x;
|
||||
pV->cy = y;
|
||||
pV->cz = m_glDepth;
|
||||
pTS->as = 1.0;
|
||||
pTS->at = 1.0;
|
||||
pTS->bs = 0.0;
|
||||
pTS->bt = 1.0;
|
||||
pTS->cs = 0.0;
|
||||
pTS->ct = 0.0;
|
||||
pTS->aq = pTS->bq = pTS->cq = 0.0f;
|
||||
pTS->aoow = pTS->boow = pTS->coow = 1.0;
|
||||
pC++; pV++; pTS++; n++;
|
||||
}
|
||||
}
|
||||
if (m_use_client_storage)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, true);
|
||||
glReportError();
|
||||
}
|
||||
// Finish rendering
|
||||
RenderUnlockArrays();
|
||||
// Transfer coords to VRAM
|
||||
glLockArraysEXT(framebuffertrianglesstart * 3 , n * 3);
|
||||
OGLRender.BufferLocked = true;
|
||||
const bool init_second_textureunit = pixelpipeline && OpenGL.ColorAlphaUnit2;
|
||||
int texturenameindex = 0;
|
||||
FxU32* texbuffer = reinterpret_cast<FxU32*>(m_texbuffer->Address);
|
||||
// Render the tiles
|
||||
y = 0;
|
||||
n = 0;
|
||||
for(int w = 0; y < m_height && w < MaxTiles; w++, y += y_step)
|
||||
{
|
||||
y_step = tilesizetable[w].y;
|
||||
x = 0;
|
||||
for(int v = 0; x < m_width && v < MaxTiles; v++, x += x_step)
|
||||
{
|
||||
x_step = tilesizetable[w].x[v];
|
||||
// Use the same name for each texture in order to maintain the size
|
||||
// and avoid vram memory reallocation
|
||||
GLint texturename;
|
||||
if (m_use_client_storage)
|
||||
{
|
||||
// Multiple textures are used to keep the gl pipeline busy
|
||||
texturename = m_tex_name[texturenameindex];
|
||||
if (texturenameindex == m_max_client_storage_textures -1)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE , false);
|
||||
glReportError();
|
||||
}
|
||||
else if (texturenameindex < m_max_client_storage_textures -1)
|
||||
{
|
||||
texturenameindex++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Without GL_UNPACK_CLIENT_STORAGE_APPLE, just one texture is used
|
||||
// in orde to minimise memory usage
|
||||
// @todo: Could be further optimised by using multiple texture names
|
||||
// (like if CLIENT_STORAGE_APPLE is present) and deleting obsolete
|
||||
// textures > texturenameindex after rendering the current framebuffer.
|
||||
texturename = m_tex_name[0];
|
||||
}
|
||||
if (createTextureData(texbuffer, x, y, x_step, y_step))
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texturename);
|
||||
#ifdef DEBUG_TILE_RENDERING
|
||||
((long*) texbuffer)[0] = 0x00ff00ff;
|
||||
((long*) texbuffer)[x_step * y_step - 1] = 0x00ff00ff;
|
||||
#endif
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, m_glInternalFormat, x_step, y_step, 0, m_glFormat, m_glType, texbuffer);
|
||||
glReportError();
|
||||
if (init_second_textureunit)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit2);
|
||||
glBindTexture(GL_TEXTURE_2D, texturename);
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glReportError();
|
||||
}
|
||||
// use the next texbuffer location
|
||||
if (m_use_client_storage && texturenameindex != m_max_client_storage_textures -1)
|
||||
{
|
||||
texbuffer += x_step * y_step;
|
||||
}
|
||||
// Draw the tile
|
||||
glDrawArrays(GL_TRIANGLES, framebuffertrianglesstart * 3 + n, 6);
|
||||
}
|
||||
n += 6;
|
||||
}
|
||||
}
|
||||
if (m_use_client_storage && texturenameindex < m_max_client_storage_textures - 1)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE , false);
|
||||
glReportError();
|
||||
}
|
||||
s_Framebuffer.SetRenderBufferChanged();
|
||||
return y == m_height && x == m_width;
|
||||
}
|
||||
|
@ -803,6 +1032,7 @@ inline bool Framebuffer::Convert565Kto8888(FxU16* buffer1, register FxU32* buffe
|
|||
return false;
|
||||
create_8888_texture:
|
||||
const register unsigned long alpha = m_glAlpha;
|
||||
const register unsigned long null = 0x00000000;
|
||||
const register unsigned long mask_pixel1 = 0xffff0000;
|
||||
const register unsigned long mask_pixel2 = 0x0000ffff;
|
||||
const register unsigned long mask_pixel1_r = 0xf8000000;
|
||||
|
@ -821,15 +1051,15 @@ create_8888_texture:
|
|||
pixel = *src;
|
||||
if (pixel == chromakey12)
|
||||
{
|
||||
*buffer2++ = 0;
|
||||
*buffer2++ = 0;
|
||||
*buffer2++ = null;
|
||||
*buffer2++ = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
*src = chromakey12;
|
||||
if ( (pixel & mask_pixel1) == chromakey1)
|
||||
{
|
||||
*buffer2++ = 0;
|
||||
*buffer2++ = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -840,7 +1070,7 @@ create_8888_texture:
|
|||
}
|
||||
if ( (pixel & mask_pixel2) == chromakey2)
|
||||
{
|
||||
*buffer2++ = 0;
|
||||
*buffer2++ = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -15,15 +15,6 @@ class Framebuffer
|
|||
public:
|
||||
Framebuffer();
|
||||
~Framebuffer();
|
||||
/*
|
||||
enum Format
|
||||
{
|
||||
None = -1,
|
||||
USHORT_565 = GL_UNSIGNED_SHORT_5_6_5,
|
||||
USHORT_5551_REV = GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
||||
UBYTE_8888
|
||||
};
|
||||
*/
|
||||
static const int MaxTiles = 12;
|
||||
struct tilesize {GLint y; GLint x[MaxTiles];};
|
||||
public:
|
||||
|
@ -39,18 +30,18 @@ public:
|
|||
protected:
|
||||
void Clear();
|
||||
bool draw(const tilesize* tilesizetable, bool pixelpipeline);
|
||||
bool drawCompiledVertexArrays(const tilesize* tilesizetable, bool pixelpipeline);
|
||||
void set_gl_state(bool pixelpipeline);
|
||||
void restore_gl_state(bool pixelpipeline);
|
||||
inline bool createTextureData(FxU32* texbuffer, FxU32 x, FxU32 y, FxU32 x_step, FxU32 y_step);
|
||||
inline bool Convert565Kto8888(FxU16* buffer1, FxU32* buffer2, register FxU32 width, register FxU32 height, register FxU32 stride);
|
||||
inline bool Convert1555Kto8888(FxU16* buffer1, register FxU32* buffer2, FxU32 register width, register FxU32 height, register FxU32 stride);
|
||||
inline bool ConvertARGB8888Kto8888(FxU32* buffer1, register FxU32* buffer2, FxU32 register width, register FxU32 height, register FxU32 stride);
|
||||
static const int m_max_client_storage_textures = 256;
|
||||
static const int m_max_client_storage_textures = MaxTiles * MaxTiles;
|
||||
GLuint m_tex_name[m_max_client_storage_textures];
|
||||
bool m_use_client_storage;
|
||||
bool m_must_clear_buffer;
|
||||
GrOriginLocation_t m_origin;
|
||||
// GrLfbWriteMode_t m_writemode;
|
||||
GLint m_glInternalFormat;
|
||||
GLint m_glFormat;
|
||||
GLint m_glType;
|
||||
|
@ -58,8 +49,6 @@ protected:
|
|||
bool m_format_valid;
|
||||
BufferStruct* m_framebuffer;
|
||||
BufferStruct* m_texbuffer;
|
||||
// FxU16* m_framebuffer;
|
||||
// void* m_texbuffer;
|
||||
FxU32 m_width;
|
||||
FxU32 m_height;
|
||||
GLint m_x_step_start;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "Glide.h"
|
||||
#include "GlideApplication.h"
|
||||
#include "GlideFrameBuffer.h"
|
||||
#include "GlideSettings.h"
|
||||
#include "GLextensions.h"
|
||||
#include "GLRender.h"
|
||||
|
@ -74,42 +75,45 @@ void RenderInitialize( void )
|
|||
glReportErrors("RenderInitialize");
|
||||
// initialise triagle buffers
|
||||
OGLRender.NumberOfTriangles = 0;
|
||||
OGLRender.TColor = (TColorStruct*) AllocBuffer( MAXTRIANGLES + 1, sizeof(TColorStruct));
|
||||
OGLRender.FrameBufferTrianglesStart = OGLRender.RenderBufferSize + 1;
|
||||
const int triangles = OGLRender.FrameBufferTrianglesStart + Framebuffer::MaxTiles * Framebuffer::MaxTiles;
|
||||
OGLRender.TColor = (TColorStruct*) AllocBuffer( triangles, sizeof(TColorStruct));
|
||||
if (OpenGL.ColorAlphaUnit2 == 0)
|
||||
{
|
||||
// This must be initialiased even if the secondary color extension is absent
|
||||
// (Because there are no additional checks later on)
|
||||
OGLRender.TColor2 = (TColorStruct*) AllocBuffer( MAXTRIANGLES + 1, sizeof(TColorStruct));
|
||||
OGLRender.TColor2 = (TColorStruct*) AllocBuffer( triangles, sizeof(TColorStruct));
|
||||
}
|
||||
else
|
||||
{
|
||||
OGLRender.TColor2 = NULL;
|
||||
}
|
||||
OGLRender.TTexture = (TTextureStruct*) AllocBuffer( MAXTRIANGLES + 1, sizeof(TTextureStruct));
|
||||
OGLRender.TVertex = (TVertexStruct*) AllocBuffer( MAXTRIANGLES + 1, sizeof(TVertexStruct));
|
||||
OGLRender.TFog = (TFogStruct*) AllocBuffer( MAXTRIANGLES + 1, sizeof(TFogStruct));
|
||||
OGLRender.TTexture = (TTextureStruct*) AllocBuffer(triangles, sizeof(TTextureStruct));
|
||||
OGLRender.TVertex = (TVertexStruct*) AllocBuffer(triangles, sizeof(TVertexStruct));
|
||||
OGLRender.TFog = (TFogStruct*) AllocBuffer(triangles, sizeof(TFogStruct));
|
||||
// Initialise compiled vertex arrays
|
||||
OGLRender.BufferLocked = false;
|
||||
OGLRender.BufferStart = 0;
|
||||
OGLRender.BufferLockedStart = MAXTRIANGLES;
|
||||
OGLRender.BufferLockedStart = OGLRender.RenderBufferSize;
|
||||
// fog is initially turned off
|
||||
OGLRender.UseEnvCombineFog = false;
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
// Initialise to start at the first element of the buffer
|
||||
glVertexPointer(3, GL_FLOAT, 4 * sizeof( GLfloat ), &OGLRender.TVertex[0]);
|
||||
glVertexPointer(3, GL_FLOAT, 4 * sizeof(GLfloat), &OGLRender.TVertex[0]);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glColorPointer(4, GL_FLOAT, 0, &OGLRender.TColor[0]);
|
||||
glEnableClientState( GL_COLOR_ARRAY );
|
||||
glReportError();
|
||||
if (InternalConfig.EXT_secondary_color && OpenGL.ColorAlphaUnit2 == NULL)
|
||||
{
|
||||
glEnableClientState( GL_SECONDARY_COLOR_ARRAY_EXT );
|
||||
glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
|
||||
glSecondaryColorPointerEXT(3, GL_FLOAT, 4 * sizeof(GLfloat), &OGLRender.TColor2[0]);
|
||||
glReportError();
|
||||
}
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
/*
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, &OGLRender.TTexture[0]);
|
||||
glReportError();
|
||||
|
@ -121,9 +125,6 @@ void RenderInitialize( void )
|
|||
glActiveTextureARB(OpenGL.ColorAlphaUnit1 + 1);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, &OGLRender.TTexture[0]);
|
||||
// @todo: if uncommented causes alpha blended
|
||||
// smoke in Carmaegeddon to disappear
|
||||
// glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glReportError();
|
||||
}
|
||||
// Setup as inverter only
|
||||
|
@ -135,6 +136,13 @@ void RenderInitialize( void )
|
|||
glTexCoordPointer(1, GL_FLOAT, 0, &OGLRender.TFog[0]);
|
||||
glReportError();
|
||||
}
|
||||
if ( InternalConfig.ARB_multitexture || InternalConfig.FogMode == OpenGLideFogEmulation_EnvCombine)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glReportError();
|
||||
}
|
||||
*/
|
||||
#ifdef OPENGLIDE_SYSTEM_HAS_FOGCOORD
|
||||
if (InternalConfig.FogMode == OpenGLideFogEmulation_FogCoord)
|
||||
{
|
||||
|
@ -143,13 +151,7 @@ void RenderInitialize( void )
|
|||
glReportError();
|
||||
}
|
||||
#endif
|
||||
if ( InternalConfig.ARB_multitexture || InternalConfig.FogMode == OpenGLideFogEmulation_EnvCombine)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glReportError();
|
||||
}
|
||||
|
||||
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1);
|
||||
}
|
||||
|
||||
|
@ -186,18 +188,6 @@ void RenderFree( void )
|
|||
FreeBuffer(OGLRender.TFog);
|
||||
}
|
||||
|
||||
inline void RenderUnlockArrays()
|
||||
{
|
||||
glReportErrors("RenderUnlockArrays");
|
||||
|
||||
if (OGLRender.BufferLocked)
|
||||
{
|
||||
glUnlockArraysEXT();
|
||||
glReportError();
|
||||
OGLRender.BufferLocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderDrawTriangles_ImmediateMode(bool use_two_tex)
|
||||
{
|
||||
glReportErrors("RenderDrawTriangles_ImmediateMode");
|
||||
|
@ -522,7 +512,7 @@ void RenderDrawTriangles( void )
|
|||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1 + 1);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, &OGLRender.TTexture[0]);
|
||||
}
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glReportError();
|
||||
|
@ -553,8 +543,8 @@ void RenderDrawTriangles( void )
|
|||
// Continue rendering in next buffer
|
||||
OGLRender.BufferStart += OGLRender.NumberOfTriangles;
|
||||
// choose the largest buffer
|
||||
if (OGLRender.BufferStart > MAXTRIANGLES / 2
|
||||
|| OGLRender.BufferStart >= MAXTRIANGLES -1)
|
||||
if (OGLRender.BufferStart > OGLRender.RenderBufferSize / 2
|
||||
|| OGLRender.BufferStart >= OGLRender.RenderBufferSize -1)
|
||||
{
|
||||
OGLRender.BufferStart = 0;
|
||||
}
|
||||
|
@ -648,11 +638,11 @@ void RenderDrawTriangles( void )
|
|||
glActiveTextureARB(OpenGL.ColorAlphaUnit1 + 1);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1 + 1);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer( 4, GL_FLOAT, 0, NULL);
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
}
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glReportError();
|
||||
}
|
||||
|
@ -699,7 +689,7 @@ void RenderAddLine( const GrVertex *a, const GrVertex *b, bool unsnap )
|
|||
RenderUpdateState();
|
||||
}
|
||||
|
||||
TColorStruct* pC = &OGLRender.TColor[ MAXTRIANGLES ];
|
||||
TColorStruct* pC = &OGLRender.TColor[OGLRender.RenderBufferSize];
|
||||
TColorStruct* pC2;
|
||||
if (OpenGL.ColorAlphaUnit2)
|
||||
{
|
||||
|
@ -727,7 +717,7 @@ void RenderAddLine( const GrVertex *a, const GrVertex *b, bool unsnap )
|
|||
}
|
||||
else
|
||||
{
|
||||
pC2 = &OGLRender.TColor2[ MAXTRIANGLES ];
|
||||
pC2 = &OGLRender.TColor2[OGLRender.RenderBufferSize];
|
||||
memset( pC2, 0, sizeof( TColorStruct ) );
|
||||
// Color Stuff, need to optimize it
|
||||
if ( Glide.ALocal )
|
||||
|
@ -1056,7 +1046,7 @@ void RenderAddLine( const GrVertex *a, const GrVertex *b, bool unsnap )
|
|||
}
|
||||
}
|
||||
|
||||
TVertexStruct* pV = &OGLRender.TVertex[ MAXTRIANGLES ];
|
||||
TVertexStruct* pV = &OGLRender.TVertex[OGLRender.RenderBufferSize];
|
||||
// Z-Buffering
|
||||
if ( ( Glide.State.DepthBufferMode == GR_DEPTHBUFFER_DISABLE ) ||
|
||||
( Glide.State.DepthBufferMode == GR_CMP_ALWAYS ) )
|
||||
|
@ -1112,7 +1102,7 @@ void RenderAddLine( const GrVertex *a, const GrVertex *b, bool unsnap )
|
|||
}
|
||||
|
||||
TTextureStruct* pTS;
|
||||
pTS = &OGLRender.TTexture[MAXTRIANGLES];
|
||||
pTS = &OGLRender.TTexture[OGLRender.RenderBufferSize];
|
||||
if ( OpenGL.Texture )
|
||||
{
|
||||
float hAspect = Textures->GetHAspect();
|
||||
|
@ -1165,7 +1155,7 @@ void RenderAddLine( const GrVertex *a, const GrVertex *b, bool unsnap )
|
|||
}
|
||||
|
||||
TFogStruct* pF;
|
||||
pF = &OGLRender.TFog[MAXTRIANGLES];
|
||||
pF = &OGLRender.TFog[OGLRender.RenderBufferSize];
|
||||
if (Glide.State.FogMode)
|
||||
{
|
||||
float af, bf;
|
||||
|
@ -1822,10 +1812,10 @@ void RenderAddTriangle( const GrVertex *a, const GrVertex *b, const GrVertex *c,
|
|||
// Finish drawing of current render buffer
|
||||
RenderUnlockArrays();
|
||||
OGLRender.BufferLocked = false;
|
||||
OGLRender.BufferLockedStart = MAXTRIANGLES;
|
||||
OGLRender.BufferLockedStart = OGLRender.RenderBufferSize;
|
||||
// Continue filling the buffer
|
||||
}
|
||||
else if (OGLRender.BufferStart + OGLRender.NumberOfTriangles >= MAXTRIANGLES - 1)
|
||||
else if (OGLRender.BufferStart + OGLRender.NumberOfTriangles >= OGLRender.RenderBufferSize - 1)
|
||||
{
|
||||
RenderDrawTriangles();
|
||||
}
|
||||
|
@ -1859,7 +1849,7 @@ void RenderAddPoint( const GrVertex *a, bool unsnap )
|
|||
RenderUpdateState();
|
||||
}
|
||||
|
||||
TColorStruct* pC = &OGLRender.TColor[ MAXTRIANGLES ];
|
||||
TColorStruct* pC = &OGLRender.TColor[OGLRender.RenderBufferSize];
|
||||
TColorStruct* pC2;
|
||||
if (OpenGL.ColorAlphaUnit2)
|
||||
{
|
||||
|
@ -1882,7 +1872,7 @@ void RenderAddPoint( const GrVertex *a, bool unsnap )
|
|||
}
|
||||
else
|
||||
{
|
||||
pC2 = &OGLRender.TColor2[ MAXTRIANGLES ];
|
||||
pC2 = &OGLRender.TColor2[OGLRender.RenderBufferSize];
|
||||
memset( pC2, 0, sizeof( TColorStruct ) );
|
||||
// Color Stuff, need to optimize it
|
||||
if ( Glide.ALocal )
|
||||
|
@ -2143,7 +2133,7 @@ void RenderAddPoint( const GrVertex *a, bool unsnap )
|
|||
}
|
||||
}
|
||||
|
||||
TVertexStruct* pV = &OGLRender.TVertex[ MAXTRIANGLES ];
|
||||
TVertexStruct* pV = &OGLRender.TVertex[OGLRender.RenderBufferSize];
|
||||
// Z-Buffering
|
||||
if ( ( Glide.State.DepthBufferMode == GR_DEPTHBUFFER_DISABLE ) ||
|
||||
( Glide.State.DepthBufferMode == GR_CMP_ALWAYS ) )
|
||||
|
@ -2190,8 +2180,7 @@ void RenderAddPoint( const GrVertex *a, bool unsnap )
|
|||
pV->ay = a->y;
|
||||
}
|
||||
|
||||
TTextureStruct* pTS;
|
||||
pTS = &OGLRender.TTexture[MAXTRIANGLES];
|
||||
TTextureStruct* pTS = &OGLRender.TTexture[OGLRender.RenderBufferSize];
|
||||
if ( OpenGL.Texture )
|
||||
{
|
||||
pTS->as = a->tmuvtx[0].sow * Textures->GetWAspect();
|
||||
|
@ -2219,8 +2208,7 @@ void RenderAddPoint( const GrVertex *a, bool unsnap )
|
|||
#endif
|
||||
}
|
||||
|
||||
TFogStruct* pF;
|
||||
pF = &OGLRender.TFog[ MAXTRIANGLES ];
|
||||
TFogStruct* pF = &OGLRender.TFog[OGLRender.RenderBufferSize];
|
||||
if(Glide.State.FogMode)
|
||||
{
|
||||
float af;
|
||||
|
|
|
@ -13,13 +13,6 @@
|
|||
#ifndef __GLRENDER_H__
|
||||
#define __GLRENDER_H__
|
||||
|
||||
//**************************************************************
|
||||
// Defines
|
||||
//**************************************************************
|
||||
|
||||
#define MAXTRIANGLES 500
|
||||
|
||||
|
||||
//**************************************************************
|
||||
// Structs
|
||||
//**************************************************************
|
||||
|
@ -73,6 +66,8 @@ struct TFogStruct
|
|||
|
||||
struct RenderStruct
|
||||
{
|
||||
static const int RenderBufferSize = 512;
|
||||
int FrameBufferTrianglesStart;
|
||||
TColorStruct *TColor;
|
||||
TColorStruct *TColor2;
|
||||
TVertexStruct *TVertex;
|
||||
|
@ -94,8 +89,6 @@ struct RenderStruct
|
|||
unsigned long OverallTriangles, OverallRenderTriangleCalls;
|
||||
unsigned long OverallLines;
|
||||
unsigned long OverallPoints;
|
||||
unsigned long OverallQuads;
|
||||
unsigned long OverallPolygons;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -120,6 +113,18 @@ extern RenderStruct OGLRender;
|
|||
void RenderInitialize( void );
|
||||
void RenderFree( void );
|
||||
|
||||
inline void RenderUnlockArrays()
|
||||
{
|
||||
glReportErrors("RenderUnlockArrays");
|
||||
|
||||
if (OGLRender.BufferLocked)
|
||||
{
|
||||
glUnlockArraysEXT();
|
||||
glReportError();
|
||||
OGLRender.BufferLocked = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Main Render variables
|
||||
// extern RenderStruct OGLRender;
|
||||
|
|
|
@ -887,7 +887,7 @@ void RenderUpdateState()
|
|||
active_texture_unit_not_coloralpha1 = true;
|
||||
glReportError();
|
||||
}
|
||||
|
||||
|
||||
if (s_bUpdateFogModeState)
|
||||
{
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.FogTextureUnit);
|
||||
|
@ -1011,6 +1011,7 @@ void RenderUpdateState()
|
|||
}
|
||||
}
|
||||
|
||||
// Means fog texture unit is active
|
||||
if (active_texture_unit_not_coloralpha1 == false &&
|
||||
(s_bUpdateColorInvertState || s_bUpdateAlphaInvertState))
|
||||
{
|
||||
|
@ -1096,8 +1097,6 @@ void RenderUpdateState()
|
|||
// AlphaCombine
|
||||
if (OpenGL.ChromaKey && OpenGL.Texture && !OpenGL.Blend)
|
||||
{
|
||||
// OpenGL.ColorAlphaUnitAlphaEnabledState[0] = true;
|
||||
// OpenGL.ColorAlphaUnitAlphaEnabledState[1] = false;
|
||||
OpenGL.ColorAlphaUnitAlphaEnabledState[unit_index] = (unit_index == 0) ? true : false;
|
||||
}
|
||||
else
|
||||
|
@ -1160,11 +1159,9 @@ void RenderUpdateState()
|
|||
glActiveTextureARB(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
if (set_active_texture_unit)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
}
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, NULL);
|
||||
active_texture_unit_client_state_not_coloralpha1 = (unit_index != 0);
|
||||
}
|
||||
active_texture_unit_not_coloralpha1 = (unit_index != 0);
|
||||
|
@ -1208,10 +1205,11 @@ void RenderUpdateState()
|
|||
#endif
|
||||
// Enable the texture unit
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
if (InternalConfig.EXT_compiled_vertex_array && set_active_texture_unit)
|
||||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1 + unit_index);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, &OGLRender.TTexture[0]);
|
||||
active_texture_unit_client_state_not_coloralpha1 = (unit_index != 0);
|
||||
}
|
||||
glReportError();
|
||||
|
@ -1358,7 +1356,7 @@ void RenderUpdateState()
|
|||
}
|
||||
else
|
||||
{
|
||||
CombineFunctionGLTextureUnit unit = OpenGL.AlphaCombineFunctions[a_function].ColorAlphaUnit[unit_index];
|
||||
const CombineFunctionGLTextureUnit unit = OpenGL.AlphaCombineFunctions[a_function].ColorAlphaUnit[unit_index];
|
||||
if (unit.Function == CF_Unused)
|
||||
{
|
||||
if (OpenGL.ChromaKey && OpenGL.Texture && OpenGL.Blend)
|
||||
|
@ -1471,7 +1469,7 @@ void RenderUpdateState()
|
|||
// Constant Color State
|
||||
if (s_bUpdateConstantColorValueState || s_bUpdateConstantColorValue4State)
|
||||
{
|
||||
GLfloat* color;
|
||||
const GLfloat* color;
|
||||
if (Glide.State.Delta0Mode)
|
||||
{
|
||||
if (reset_state) s_bUpdateConstantColorValue4State = false;
|
||||
|
@ -1500,18 +1498,19 @@ void RenderUpdateState()
|
|||
}
|
||||
else // OpenGL.ColorAlphaTectureUnit2 == 0
|
||||
{
|
||||
if (active_texture_unit_not_coloralpha1)
|
||||
{
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
active_texture_unit_not_coloralpha1 = false;
|
||||
}
|
||||
if (s_bUpdateTextureState)
|
||||
{
|
||||
s_bUpdateTextureState = false;
|
||||
if (active_texture_unit_client_state_not_coloralpha1)
|
||||
if (active_texture_unit_not_coloralpha1)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
active_texture_unit_client_state_not_coloralpha1 = false;
|
||||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
active_texture_unit_not_coloralpha1 = false;
|
||||
if (active_texture_unit_client_state_not_coloralpha1)
|
||||
{
|
||||
glClientActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
active_texture_unit_client_state_not_coloralpha1 = false;
|
||||
}
|
||||
glReportError();
|
||||
}
|
||||
if (OpenGL.Texture)
|
||||
{
|
||||
|
@ -1519,6 +1518,7 @@ void RenderUpdateState()
|
|||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, &OGLRender.TTexture[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1526,6 +1526,7 @@ void RenderUpdateState()
|
|||
if (InternalConfig.EXT_compiled_vertex_array)
|
||||
{
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(4, GL_FLOAT, 0, NULL);
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
@ -1573,7 +1574,7 @@ void RenderUpdateState()
|
|||
glActiveTextureARB(OpenGL.ColorAlphaUnit1);
|
||||
glReportError();
|
||||
}
|
||||
|
||||
|
||||
VERIFY_ACTIVE_TEXTURE_UNIT(OpenGL.ColorAlphaUnit1);
|
||||
VERIFY_TEXTURE_ENABLED_STATE();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue