Permalink
Browse files

Port all VBO drawing other than PIE model and terrain to GFX class. This

also fixes GPU memory leak bug when changing skybox, hence closing ticket:3842.
  • Loading branch information...
1 parent b235b4e commit fa7454c00a1d847060a1f1b1518fc2efc6fd5ac8 @perim perim committed Feb 17, 2013
@@ -2,6 +2,14 @@
//
// * Enable unit design and minimap only when an HQ exists
+function eventGameInit()
+{
+ if (tilesetType != "ARIZONA")
+ {
+ setSky("texpages/page-25-sky-urban.png", 0.5, 10000.0);
+ }
+}
+
function eventStartLevel()
{
// Disable by default
@@ -10,6 +10,11 @@ var lastHitTime = 0;
function eventGameInit()
{
+ if (tilesetType != "ARIZONA")
+ {
+ setSky("texpages/page-25-sky-urban.png", 0.5, 10000.0);
+ }
+
hackNetOff();
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
@@ -31,9 +31,10 @@
#include "lib/ivis_opengl/piestate.h"
#include "piematrix.h"
#include "lib/ivis_opengl/piemode.h"
+#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/ivis_opengl/pieclip.h"
-static GLuint skyboxbuffers[VBO_MINIMAL];
+static GFX *skyboxGfx = NULL;
#define VW_VERTICES 5
void pie_DrawViewingWindow(Vector3i *v, UDWORD x1, UDWORD y1, UDWORD x2, UDWORD y2, PIELIGHT colour)
@@ -119,17 +120,19 @@ void pie_Skybox_Init()
u + w * 8, v + h, u + w * 8, v };
GL_DEBUG("Initializing skybox");
- glGenBuffers(VBO_MINIMAL, skyboxbuffers);
- glBindBuffer(GL_ARRAY_BUFFER, skyboxbuffers[VBO_VERTEX]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vert), vert, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, skyboxbuffers[VBO_TEXCOORD]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(texc), texc, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
+ skyboxGfx = new GFX(GL_QUAD_STRIP, 3);
+ skyboxGfx->buffers(10, vert, texc);
+}
+
+void pie_Skybox_Texture(const char *filename)
+{
+ skyboxGfx->loadTexture(filename);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
}
void pie_Skybox_Shutdown()
{
- glDeleteBuffers(VBO_MINIMAL, skyboxbuffers);
+ delete skyboxGfx;
}
void pie_DrawSkybox(float scale)
@@ -155,14 +158,7 @@ void pie_DrawSkybox(float scale)
// Apply scale matrix
glScalef(scale, scale/2.0f, scale);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, skyboxbuffers[VBO_VERTEX]); glVertexPointer(3, GL_FLOAT, 0, NULL);
- glBindBuffer(GL_ARRAY_BUFFER, skyboxbuffers[VBO_TEXCOORD]); glTexCoordPointer(2, GL_FLOAT, 0, NULL);
- glDrawArrays(GL_QUAD_STRIP, 0, 10);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ skyboxGfx->draw();
glPopAttrib();
}
@@ -40,5 +40,6 @@ extern void pie_DrawViewingWindow( Vector3i *v, UDWORD x1, UDWORD y1, UDWORD x2,
void pie_DrawSkybox(float scale);
void pie_Skybox_Init();
void pie_Skybox_Shutdown();
+void pie_Skybox_Texture(const char *filename);
#endif // _piedef_h
View
@@ -52,9 +52,8 @@ int wz_texture_compression = 0;
static bool bBackDrop = false;
static char screendump_filename[PATH_MAX];
static bool screendump_required = false;
-static GLuint backDropTexture = 0;
-static GLuint buffers[VBO_COUNT];
+static GFX *backdropGfx = NULL;
static int preview_width = 0, preview_height = 0;
static Vector2i player_pos[MAX_PLAYERS];
@@ -184,9 +183,8 @@ bool screenInitialise()
pie_Skybox_Init();
- // Generate backdrop buffers
- glGenBuffers(VBO_MINIMAL, buffers);
- glGenTextures(1, &backDropTexture);
+ // Generate backdrop render
+ backdropGfx = new GFX(GL_TRIANGLE_STRIP, 2);
glErrors();
return true;
@@ -196,8 +194,7 @@ void screenShutDown(void)
{
pie_Skybox_Shutdown();
- glDeleteBuffers(VBO_MINIMAL, buffers);
- glDeleteTextures(1, &backDropTexture);
+ delete backdropGfx;
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@@ -265,39 +262,8 @@ void screen_EnableMissingFunctions()
void screen_SetBackDropFromFile(const char* filename)
{
- // HACK : We should use a resource handler here!
- const char *extension = strrchr(filename, '.');// determine the filetype
- iV_Image image;
-
- if(!extension)
- {
- debug(LOG_ERROR, "Image without extension: \"%s\"!", filename);
- return; // filename without extension... don't bother
- }
-
- // Make sure the current texture page is reloaded after we are finished
- // Otherwise WZ will think it is still loaded and not load it again
- pie_SetTexturePage(TEXPAGE_EXTERN);
-
- if (strcmp(extension, ".png") == 0)
- {
- if (iV_loadImage_PNG(filename, &image))
- {
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width, image.height,
- 0, iV_getPixelFormat(&image), GL_UNSIGNED_BYTE, image.bmp);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- iV_unloadImage(&image);
- screen_Upload(NULL);
- }
- }
- else
- {
- debug(LOG_ERROR, "Unknown extension \"%s\" for image \"%s\"!", extension, filename);
- }
+ backdropGfx->loadTexture(filename);
+ screen_Upload(NULL);
}
void screen_StopBackDrop(void)
@@ -319,22 +285,9 @@ void screen_Display()
{
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_OFF);
- // Make sure the current texture page is reloaded after we are finished
- // Otherwise WZ will think it is still loaded and not load it again
- pie_SetTexturePage(TEXPAGE_EXTERN);
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
-
// Draw backdrop
glColor3f(1, 1, 1);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_TEXCOORD]); glTexCoordPointer(2, GL_FLOAT, 0, NULL);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_VERTEX]); glVertexPointer(2, GL_INT, 0, NULL);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glErrors();
+ backdropGfx->draw();
if (mappreview)
{
@@ -376,8 +329,9 @@ void screen_Display()
//bitmap MUST be (BACKDROP_HACK_WIDTH * BACKDROP_HACK_HEIGHT) for now.
void screen_Upload(const char *newBackDropBmp)
{
- int x1 = 0, x2 = screenWidth, y1 = 0, y2 = screenHeight, scale = 0, w = 0, h = 0;
+ GLfloat x1 = 0, x2 = screenWidth, y1 = 0, y2 = screenHeight;
GLfloat tx = 1, ty = 1;
+ int scale = 0, w = 0, h = 0;
const float aspect = screenWidth / (float)screenHeight, backdropAspect = 4 / (float)3;
if (aspect < backdropAspect)
@@ -395,14 +349,7 @@ void screen_Upload(const char *newBackDropBmp)
if (newBackDropBmp) // preview
{
- pie_SetTexturePage(TEXPAGE_EXTERN);
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BACKDROP_HACK_WIDTH, BACKDROP_HACK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, newBackDropBmp);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ backdropGfx->makeTexture(BACKDROP_HACK_WIDTH, BACKDROP_HACK_HEIGHT, GL_NEAREST, GL_RGB, newBackDropBmp);
int s1 = screenWidth / preview_width;
int s2 = screenHeight / preview_height;
@@ -421,14 +368,8 @@ void screen_Upload(const char *newBackDropBmp)
// Generate coordinates and put them into VBOs
GLfloat texcoords[8] = { 0.0f, 0.0f, tx, 0.0, 0.0f, ty, tx, ty };
- GLint vertices[8] = { x1, y1, x2, y1, x1, y2, x2, y2 };
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_TEXCOORD]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_VERTEX]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- glErrors();
+ GLfloat vertices[8] = { x1, y1, x2, y1, x1, y2, x2, y2 };
+ backdropGfx->buffers(4, vertices, texcoords);
}
void screen_enableMapPreview(int width, int height, Vector2i *playerpositions)
View
@@ -184,14 +184,6 @@ int pie_AddTexPage(iV_Image *s, const char* filename, int slot, int maxTextureSi
return page;
}
-
-void pie_InitSkybox(SDWORD pageNum)
-{
- pie_SetTexturePage(pageNum);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-}
-
-
/*!
* Turns filename into a pagename if possible
* \param[in,out] filename Filename to pagify
View
@@ -44,8 +44,6 @@ extern int pie_ReplaceTexPage(iV_Image *s, const char *texPage, int maxTextureSi
extern int pie_AddTexPage(iV_Image *s, const char *filename, int slot, int maxTextureSize, bool useMipmaping);
extern void pie_TexInit(void);
-extern void pie_InitSkybox(SDWORD pageNum);
-
extern void pie_MakeTexPageName(char * filename);
extern void pie_MakeTexPageTCMaskName(char * filename);
Oops, something went wrong.

0 comments on commit fa7454c

Please sign in to comment.