mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-06-08 01:22:02 +00:00
rework ScreenTransition to use VBO
This commit is contained in:
parent
854afdda3f
commit
7b7681ffb6
3 changed files with 40 additions and 16 deletions
|
@ -4161,6 +4161,7 @@ void AquariaScreenTransition::capture()
|
||||||
glReadBuffer(GL_BACK);
|
glReadBuffer(GL_BACK);
|
||||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
|
||||||
|
|
||||||
|
updateVBO();
|
||||||
|
|
||||||
dsq->cursor->alpha = oldAlpha;
|
dsq->cursor->alpha = oldAlpha;
|
||||||
dsq->renderExternal();
|
dsq->renderExternal();
|
||||||
|
|
|
@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "RenderBase.h"
|
#include "RenderBase.h"
|
||||||
|
|
||||||
ScreenTransition::ScreenTransition() : RenderObject()
|
ScreenTransition::ScreenTransition() : RenderObject()
|
||||||
|
, vbo(GPUBUF_VERTEXBUF | GPUBUF_DYNAMIC)
|
||||||
{
|
{
|
||||||
screen_texture = 0;
|
screen_texture = 0;
|
||||||
cull = false;
|
cull = false;
|
||||||
|
@ -55,6 +56,8 @@ void ScreenTransition::createTexture()
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_NEAREST); //GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_NEAREST); //GL_NEAREST);
|
||||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB, textureWidth, textureHeight, 0 , GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB, textureWidth, textureHeight, 0 , GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||||
glBindTexture(GL_TEXTURE_2D,0);
|
glBindTexture(GL_TEXTURE_2D,0);
|
||||||
|
|
||||||
|
updateVBO();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenTransition::destroyTexture()
|
void ScreenTransition::destroyTexture()
|
||||||
|
@ -66,6 +69,35 @@ void ScreenTransition::destroyTexture()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScreenTransition::updateVBO()
|
||||||
|
{
|
||||||
|
const float width2 = float(width)/2;
|
||||||
|
const float height2 = float(height)/2;
|
||||||
|
|
||||||
|
const float pw = float(windowWidth)/float(textureWidth);
|
||||||
|
const float ph = float(windowHeight)/float(textureHeight);
|
||||||
|
|
||||||
|
size_t bytes = 4 * (2+2) * sizeof(float);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
float *p = (float*)vbo.beginWrite(GPUBUFTYPE_VEC2_TC, bytes, GPUACCESS_DEFAULT);
|
||||||
|
|
||||||
|
*p++ = width2; *p++ = height2;
|
||||||
|
*p++ = pw; *p++ = 0;
|
||||||
|
|
||||||
|
*p++ = -width2; *p++ = height2;
|
||||||
|
*p++ = 0; *p++ = 0;
|
||||||
|
|
||||||
|
*p++ = width2; *p++ = -height2;
|
||||||
|
*p++ = pw; *p++ = ph;
|
||||||
|
|
||||||
|
*p++ = -width2; *p++ = -height2;
|
||||||
|
*p++ = 0; *p++ = ph;
|
||||||
|
|
||||||
|
}
|
||||||
|
while(!vbo.commitWrite());
|
||||||
|
}
|
||||||
|
|
||||||
void ScreenTransition::unloadDevice()
|
void ScreenTransition::unloadDevice()
|
||||||
{
|
{
|
||||||
RenderObject::unloadDevice();
|
RenderObject::unloadDevice();
|
||||||
|
@ -116,24 +148,10 @@ void ScreenTransition::onRender(const RenderState& rs) const
|
||||||
{
|
{
|
||||||
if (alpha.x == 0) return;
|
if (alpha.x == 0) return;
|
||||||
|
|
||||||
float width2 = float(width)/2;
|
|
||||||
float height2 = float(height)/2;
|
|
||||||
|
|
||||||
const float pw = float(windowWidth)/float(textureWidth);
|
|
||||||
const float ph = float(windowHeight)/float(textureHeight);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, screen_texture);
|
glBindTexture(GL_TEXTURE_2D, screen_texture);
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
vbo.apply();
|
||||||
glTexCoord2f(0, 0);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
glVertex3f(-width2, height2, 0.0);
|
|
||||||
glTexCoord2f(pw, 0);
|
|
||||||
glVertex3f( width2, height2, 0.0);
|
|
||||||
glTexCoord2f(pw, ph);
|
|
||||||
glVertex3f( width2, -height2, 0.0);
|
|
||||||
glTexCoord2f(0, ph);
|
|
||||||
glVertex3f(-width2, -height2, 0.0);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#define SCREENTRANSITION_H
|
#define SCREENTRANSITION_H
|
||||||
|
|
||||||
#include "RenderObject.h"
|
#include "RenderObject.h"
|
||||||
|
#include "VertexBuffer.h"
|
||||||
|
|
||||||
class ScreenTransition : public RenderObject
|
class ScreenTransition : public RenderObject
|
||||||
{
|
{
|
||||||
|
@ -36,6 +37,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void createTexture();
|
void createTexture();
|
||||||
void destroyTexture();
|
void destroyTexture();
|
||||||
|
void updateVBO();
|
||||||
int textureWidth, textureHeight;
|
int textureWidth, textureHeight;
|
||||||
int windowWidth, windowHeight;
|
int windowWidth, windowHeight;
|
||||||
void onRender(const RenderState& rs) const OVERRIDE;
|
void onRender(const RenderState& rs) const OVERRIDE;
|
||||||
|
@ -43,6 +45,9 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
unsigned screen_texture;
|
unsigned screen_texture;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DynamicGPUBuffer vbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue