Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit fa7454c00a1d847060a1f1b1518fc2efc6fd5ac8 1 parent b235b4e
@perim perim authored
View
8 data/base/script/rules.js
@@ -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
View
5 data/mp/multiplay/skirmish/rules.js
@@ -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++)
{
View
28 lib/ivis_opengl/piefunc.cpp
@@ -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();
}
View
1  lib/ivis_opengl/piefunc.h
@@ -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
83 lib/ivis_opengl/screen.cpp
@@ -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
8 lib/ivis_opengl/tex.cpp
@@ -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
2  lib/ivis_opengl/tex.h
@@ -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);
View
58 lib/sequence/sequence.cpp
@@ -62,6 +62,7 @@
#include "timer.h"
#include "lib/framework/math_ext.h"
#include "lib/ivis_opengl/piestate.h"
+#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/sound/audio.h"
#include "lib/sound/openal_error.h"
#include "lib/sound/mixer.h"
@@ -146,7 +147,7 @@ static int dropped = 0;
// Screen dimensions
#define NUM_VERTICES 4
-static GLuint buffers[VBO_COUNT];
+static GFX *videoGfx = NULL;
static GLfloat vertices[NUM_VERTICES][2];
static GLfloat Scrnvidpos[3];
@@ -256,7 +257,6 @@ static double getRelativeTime(void)
const GLfloat texture_width = 1024.0f;
const GLfloat texture_height = 1024.0f;
-static GLuint video_texture;
/** Allocates memory to hold the decoded video frame
*/
@@ -268,14 +268,12 @@ static void Allocate_videoFrame(void)
RGBAframe = (uint32_t *)malloc(size);
memset(RGBAframe, 0, size);
- glGenTextures(1, &video_texture);
}
static void deallocateVideoFrame(void)
{
if (RGBAframe)
free(RGBAframe);
- glDeleteTextures(1, &video_texture);
}
#ifndef __BIG_ENDIAN__
@@ -305,12 +303,6 @@ static void video_write(bool update)
const int height_factor = (use_scanlines ? 2 : 1);
yuv_buffer yuv;
- glErrors();
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, video_texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
if (update)
{
int rgb_offset = 0;
@@ -378,9 +370,7 @@ static void video_write(bool update)
rgb_offset += video_width;
}
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, video_width,
- video_height * height_factor, GL_RGBA, GL_UNSIGNED_BYTE, RGBAframe);
- glErrors();
+ videoGfx->updateTexture(RGBAframe, video_width, video_height * height_factor);
}
glDisable(GL_DEPTH_TEST);
@@ -389,21 +379,10 @@ static void video_write(bool update)
glPushMatrix();
glTranslatef(Scrnvidpos[0], Scrnvidpos[1], Scrnvidpos[2]);
- 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_FLOAT, 0, NULL);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
+ videoGfx->draw();
glPopMatrix();
glErrors();
-
- // 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_NONE);
}
// FIXME: perhaps we should use wz's routine for audio?
@@ -689,21 +668,22 @@ bool seq_Play(const char* filename)
}
/* open video */
- glGenBuffers(VBO_MINIMAL, buffers);
- glErrors();
+ videoGfx = new GFX(GL_TRIANGLE_STRIP, 2);
if (theora_p)
{
if (videodata.ti.frame_width > texture_width || videodata.ti.frame_height > texture_height)
{
debug(LOG_ERROR, "Video size too large, must be below %.gx%.g!",
texture_width, texture_height);
- glDeleteBuffers(VBO_MINIMAL, buffers);
+ delete videoGfx;
+ videoGfx = NULL;
return false;
}
if (videodata.ti.pixelformat != OC_PF_420)
{
debug(LOG_ERROR, "Video not in YUV420 format!");
- glDeleteBuffers(VBO_MINIMAL, buffers);
+ delete videoGfx;
+ videoGfx = NULL;
return false;
}
char *blackframe = (char *)calloc(1, texture_width * texture_height * 4);
@@ -713,27 +693,15 @@ bool seq_Play(const char* filename)
use_scanlines = SCANLINES_OFF;
Allocate_videoFrame();
-
- glBindTexture(GL_TEXTURE_2D, video_texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width, texture_height,
- 0, GL_RGBA, GL_UNSIGNED_BYTE, blackframe);
+ videoGfx->makeTexture(texture_width, texture_height, GL_LINEAR, GL_RGBA, blackframe);
free(blackframe);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
// when using scanlines we need to double the height
const int height_factor = (use_scanlines ? 2 : 1);
const GLfloat vtwidth = (float)videodata.ti.frame_width / texture_width;
const GLfloat vtheight = (float)videodata.ti.frame_height * height_factor / texture_height;
GLfloat texcoords[NUM_VERTICES * 2] = { 0.0f, 0.0f, vtwidth, 0.0f, 0.0f, vtheight, vtwidth, vtheight };
- 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();
+ videoGfx->buffers(NUM_VERTICES, vertices, texcoords);
}
/* on to the main decode loop. We assume in this example that audio
@@ -939,8 +907,8 @@ void seq_Shutdown()
debug(LOG_VIDEO, "movie is not playing");
return;
}
- glDeleteBuffers(VBO_MINIMAL, buffers);
- glErrors();
+ delete videoGfx;
+ videoGfx = NULL;
if (vorbis_p)
{
View
12 src/display3d.cpp
@@ -145,8 +145,7 @@ bool godMode;
bool showGateways = false;
bool showPath = false;
-/// The name of the texture page used to draw the skybox
-static char skyboxPageName[PATH_MAX] = "page-25";
+// Skybox data
static float wind = 0.0f;
static float windSpeed = 0.0f;
static float skybox_scale = 10000.0f;
@@ -305,11 +304,10 @@ static const int BLUEPRINT_OPACITY=120;
void setSkyBox(const char *page, float mywind, float myscale)
{
- sstrcpy(skyboxPageName, page);
windSpeed = mywind;
wind = 0.0f;
skybox_scale = myscale;
- pie_InitSkybox(iV_GetTexture(skyboxPageName));
+ pie_Skybox_Texture(page);
}
static inline void rotateSomething(int &x, int &y, uint16_t angle)
@@ -1098,7 +1096,8 @@ bool init3DView(void)
bRender3DOnly = false;
- setSkyBox("page-25", 0.0f, 10000.0f);
+ // default skybox, will override in script if not satisfactory
+ setSkyBox("texpages/page-25-sky-arizona.png", 0.0f, 10000.0f);
// distance is not saved, so initialise it now
distance = START_DISTANCE; // distance
@@ -3537,9 +3536,6 @@ static void renderSurroundings(void)
// rotate it
pie_MatRotY(DEG(wind));
- // Set the texture page
- pie_SetTexturePage(iV_GetTexture(skyboxPageName));
-
if(!gamePaused())
{
wind = wrapf(wind + graphicsTimeAdjustedIncrement(windSpeed), 360.0f);
View
12 src/qtscriptfuncs.cpp
@@ -3682,19 +3682,15 @@ static QScriptValue js_setWeather(QScriptContext *context, QScriptEngine *)
return QScriptValue();
}
-//-- \subsection{setSky(texture page, wind speed, skybox scale)}
-//-- Change the skybox. Default values are "page-25", 0.5, and 10000.0. Returns true on success. (3.2+ only)
+//-- \subsection{setSky(texture file, wind speed, skybox scale)}
+//-- Change the skybox. (3.2+ only)
static QScriptValue js_setSky(QScriptContext *context, QScriptEngine *)
{
QString page = context->argument(0).toString();
float wind = context->argument(1).toNumber();
float scale = context->argument(2).toNumber();
- bool found = iV_GetTexture(page.toUtf8().constData()) >= 0;
- if (found)
- {
- setSkyBox(page.toUtf8().constData(), wind, scale);
- }
- return QScriptValue(found);
+ setSkyBox(page.toUtf8().constData(), wind, scale);
+ return QScriptValue();
}
//-- \subsection{hackMarkTiles([label | x, y[, x2, y2]])}
Please sign in to comment.
Something went wrong with that request. Please try again.