Commit 47e24d2b authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: clean up r_persistentstreambuffer so you can turn it on and off...

engine: clean up r_persistentstreambuffer so you can turn it on and off without having to restart anything
parent 839c1924
......@@ -62,6 +62,7 @@ void polymost_usePaletteIndexing(char usePaletteIndexing);
float* multiplyMatrix4f(float m0[4*4], const float m1[4*4]);
void polymost_initdrawpoly(void);
void polymost_glinit(void);
void polymost_glreset(void);
......@@ -116,6 +117,7 @@ extern int32_t r_yshearing;
extern int32_t r_persistentStreamBuffer;
extern int32_t polymostcenterhoriz;
extern GLuint drawpolyVertsID;
// Compare with polymer_eligible_for_artmap()
static FORCE_INLINE int32_t eligible_for_tileshades(int32_t const picnum, int32_t const pal)
......
......@@ -764,7 +764,6 @@ int32_t polymer_init(void)
}
buildgl_resetStateAccounting();
// clean up existing stuff since it will be initialized again if we're re-entering here
polymer_uninit();
......@@ -848,6 +847,7 @@ int32_t polymer_init(void)
}
buildgl_resetSamplerObjects();
polymost_initdrawpoly();
if (pr_verbosity >= 1) OSD_Printf("PR : Initialization complete in %d ms.\n", timerGetTicks()-t);
......@@ -1456,11 +1456,16 @@ void polymer_inb4rotatesprite(int16_t tilenum, char pal, int8_t s
polymer_getbuildmaterial(&rotatespritematerial, tilenum, pal, shade, 0, method);
rotatespritematerialbits = polymer_bindmaterial(&rotatespritematerial, NULL, 0);
buildgl_bindSamplerObject(0, PTH_CLAMPED | ((rotatespritematerialbits & prprogrambits[PR_BIT_ART_MAP].bit) ? PTH_INDEXED : 0));
buildgl_bindBuffer(GL_ARRAY_BUFFER, drawpolyVertsID);
glVertexPointer(3, GL_FLOAT, 5*sizeof(float), 0);
glTexCoordPointer(2, GL_FLOAT, 5*sizeof(float), (GLvoid*) (3*sizeof(float)));
}
void polymer_postrotatesprite(void)
{
polymer_unbindmaterial(rotatespritematerialbits);
buildgl_bindBuffer(GL_ARRAY_BUFFER, 0);
}
static void polymer_setupdiffusemodulation(_prplane *plane, GLubyte modulation, const GLubyte *data)
......
......@@ -108,9 +108,9 @@ static int32_t drawpoly_srepeat = 0, drawpoly_trepeat = 0;
#define BUFFER_OFFSET(bytes) (GLintptr) ((GLubyte*) NULL + (bytes))
// these cvars are never used directly in rendering -- only when glinit() is called/renderer reset
// We do this because we don't want to accidentally overshoot our existing buffer's bounds
int32_t persistentStreamBuffer = r_persistentStreamBuffer;
int32_t drawpolyVertsBufferLength = r_drawpolyVertsBufferLength;
static GLuint drawpolyVertsID = 0;
static int32_t persistentStreamBuffer = r_persistentStreamBuffer;
static int32_t drawpolyVertsBufferLength = r_drawpolyVertsBufferLength;
GLuint drawpolyVertsID = 0;
static GLint drawpolyVertsOffset = 0;
static int32_t drawpolyVertsSubBufferIndex = 0;
static GLsync drawpolyVertsSync[3] = { 0 };
......@@ -549,6 +549,7 @@ void polymost_glreset()
// texcache_freeptrs();
texcache_syncmemcache();
polymost_initdrawpoly();
#ifdef DEBUGGINGAIDS
OSD_Printf("polymost_glreset()\n");
......@@ -884,23 +885,9 @@ static void polymost_bindPth(pthtyp const * const pPth)
// one-time initialization of OpenGL for polymost
void polymost_clearOrnamentSprites(void);
void polymost_glinit()
{
buildgl_resetStateAccounting();
glHint(GL_FOG_HINT, GL_NICEST);
glFogi(GL_FOG_MODE, (r_usenewshading < 2) ? GL_EXP2 : GL_LINEAR);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (glinfo.depthclamp)
buildgl_setEnabled(GL_DEPTH_CLAMP);
//glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
//glEnable(GL_LINE_SMOOTH);
void polymost_initdrawpoly(void)
{
#ifdef USE_GLEXT
if (r_persistentStreamBuffer && ((!glinfo.bufferstorage) || (!glinfo.sync)))
{
......@@ -909,33 +896,31 @@ void polymost_glinit()
}
#endif
//POGOTODO: require a max texture size >= 2048
persistentStreamBuffer = r_persistentStreamBuffer;
drawpolyVertsBufferLength = r_drawpolyVertsBufferLength;
persistentStreamBuffer = r_persistentStreamBuffer;
drawpolyVertsOffset = 0;
drawpolyVertsSubBufferIndex = 0;
if (!glIsBuffer(drawpolyVertsID))
glGenBuffers(1, &drawpolyVertsID);
if (glIsBuffer(drawpolyVertsID))
glDeleteBuffers(1, &drawpolyVertsID);
glGenBuffers(1, &drawpolyVertsID);
// reset the sync objects, as old ones we had from any last GL context are gone now
for (int i=0; i<ARRAY_SSIZE(drawpolyVertsSync); i++)
if (glIsSync(drawpolyVertsSync[i]))
glDeleteSync(drawpolyVertsSync[i]);
Bmemset(drawpolyVertsSync, 0, sizeof(drawpolyVertsSync));
buildgl_bindBuffer(GL_ARRAY_BUFFER, drawpolyVertsID);
if (persistentStreamBuffer)
{
// reset the sync objects, as old ones we had from any last GL context are gone now
for (int i=0;i<ARRAY_SSIZE(drawpolyVertsSync);i++)
if (glIsSync(drawpolyVertsSync[i]))
glDeleteSync(drawpolyVertsSync[i]);
Bmemset(drawpolyVertsSync, 0, sizeof(drawpolyVertsSync));
GLbitfield flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
// we want to triple-buffer to avoid having to wait for the buffer to become available again,
// so triple the buffer size we expect to use
if (drawpolyVerts != defaultDrawpolyVertsArray)
glUnmapBuffer(GL_ARRAY_BUFFER);
glBufferStorage(GL_ARRAY_BUFFER, 3*drawpolyVertsBufferLength*sizeof(float)*5, NULL, flags);
drawpolyVerts = (float*) glMapBufferRange(GL_ARRAY_BUFFER, 0, 3*drawpolyVertsBufferLength*sizeof(float)*5, flags);
}
......@@ -944,8 +929,30 @@ void polymost_glinit()
drawpolyVerts = defaultDrawpolyVertsArray;
glBufferData(GL_ARRAY_BUFFER, drawpolyVertsBufferLength*sizeof(float)*5, NULL, GL_STREAM_DRAW);
}
buildgl_bindBuffer(GL_ARRAY_BUFFER, 0);
}
void polymost_glinit()
{
buildgl_resetStateAccounting();
glHint(GL_FOG_HINT, GL_NICEST);
glFogi(GL_FOG_MODE, (r_usenewshading < 2) ? GL_EXP2 : GL_LINEAR);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (glinfo.depthclamp)
buildgl_setEnabled(GL_DEPTH_CLAMP);
//glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
//glEnable(GL_LINE_SMOOTH);
polymost_initdrawpoly();
//POGOTODO: require a max texture size >= 2048
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &tilesheetSize);
#if (defined _MSC_VER) || (!defined BITNESS64)
if (tilesheetSize > 8192)
......@@ -9062,7 +9069,6 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
{
pr_normalmapping = 0;
polymer_inb4rotatesprite(picnum, dapalnum, dashade, method);
polymost_resetVertexPointers();
# ifdef USE_GLEXT
r_detailmapping = 0;
r_glowmapping = 0;
......@@ -9907,7 +9913,7 @@ void polymost_initosdfuncs(void)
{ "r_skyzbufferhack", "enable/disable polymost sky z-buffer hack", (void*)& r_skyzbufferhack, CVAR_BOOL, 0, 1 },
#ifdef USE_GLEXT
{ "r_vbocount","sets the number of Vertex Buffer Objects to use when drawing models",(void *) &r_vbocount, CVAR_INT, 1, 256 },
{ "r_persistentStreamBuffer","enable/disable persistent stream buffering (requires renderer restart)",(void *) &r_persistentStreamBuffer, CVAR_BOOL, 0, 1 },
{ "r_persistentStreamBuffer","enable/disable persistent stream buffering (requires renderer restart)",(void *) &r_persistentStreamBuffer, CVAR_BOOL | CVAR_RESTARTVID, 0, 1 },
{ "r_drawpolyVertsBufferLength","sets the size of the vertex buffer for polymost's streaming VBO rendering (requires renderer restart)",(void *) &r_drawpolyVertsBufferLength, CVAR_INT, MAX_DRAWPOLY_VERTS, 1000000 },
#endif
#ifdef POLYMER
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment