Make the video display only upload texture data when the frame has changed rather than every time Render is called.

Originally committed to SVN as r3726.
This commit is contained in:
Thomas Goyne 2009-10-20 19:07:18 +00:00
parent c72ac65d0f
commit df5ada1006
3 changed files with 22 additions and 9 deletions

View file

@ -193,6 +193,7 @@ void VideoDisplay::SetFrame(int frameNumber) {
if (IsShownOnScreen() && visual) visual->Refresh(); if (IsShownOnScreen() && visual) visual->Refresh();
// Render the new frame // Render the new frame
videoOut->InvalidateFrame();
Render(frameNumber); Render(frameNumber);
currentFrame = frameNumber; currentFrame = frameNumber;
@ -274,7 +275,7 @@ void VideoDisplay::Render(int frameNumber) try {
glDisable(GL_BLEND); glDisable(GL_BLEND);
if (glGetError()) throw _T("Error disabling blending."); if (glGetError()) throw _T("Error disabling blending.");
videoOut->DisplayFrame(context->GetFrame(frameNumber), sw, sh); videoOut->DisplayFrame(context->GetFrame(frameNumber), frameNumber, sw, sh);
DrawTVEffects(); DrawTVEffects();

View file

@ -111,7 +111,8 @@ VideoOutGL::VideoOutGL()
textureList(), textureList(),
textureCount(0), textureCount(0),
textureRows(0), textureRows(0),
textureCols(0) textureCols(0),
lastFrame(-1)
{ } { }
/// @brief Runtime detection of required OpenGL capabilities /// @brief Runtime detection of required OpenGL capabilities
@ -218,9 +219,8 @@ void VideoOutGL::InitTextures(int width, int height, GLenum format, int bpp) {
ti.texTop = 1.0f / (2 * h); ti.texTop = 1.0f / (2 * h);
} }
// Calculate what percent of the texture is actually used ti.texRight = 1.0f - ti.texLeft;
ti.texRight = float(ti.sourceW) / w - ti.texLeft; ti.texBottom = 1.0f - ti.texTop;
ti.texBottom = float(ti.sourceH) / h - ti.texTop;
// destW/H is the percent of the output which this texture covers // destW/H is the percent of the output which this texture covers
ti.destW = float(w) / width; ti.destW = float(w) / width;
@ -259,9 +259,11 @@ void VideoOutGL::InitTextures(int width, int height, GLenum format, int bpp) {
frameFormat = format; frameFormat = format;
} }
void VideoOutGL::DisplayFrame(AegiVideoFrame frame, int sw, int sh) { void VideoOutGL::DisplayFrame(AegiVideoFrame frame, int frameNumber, int sw, int sh) {
if (frame.h == 0 || frame.w == 0) return; if (frame.h == 0 || frame.w == 0) return;
if (frameNumber == -1) frameNumber = lastFrame;
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glEnable(GL_TEXTURE_2d)", err); if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glEnable(GL_TEXTURE_2d)", err);
@ -283,8 +285,10 @@ void VideoOutGL::DisplayFrame(AegiVideoFrame frame, int sw, int sh) {
glBindTexture(GL_TEXTURE_2D, ti.textureID); glBindTexture(GL_TEXTURE_2D, ti.textureID);
if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glBindTexture", err); if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glBindTexture", err);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ti.sourceW, ti.sourceH, format, GL_UNSIGNED_BYTE, frame.data[0] + ti.dataOffset); if (lastFrame != frameNumber) {
if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glTexSubImage2D", err); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ti.sourceW, ti.sourceH, format, GL_UNSIGNED_BYTE, frame.data[0] + ti.dataOffset);
if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glTexSubImage2D", err);
}
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glColor4f", err); if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glColor4f", err);
@ -313,6 +317,8 @@ void VideoOutGL::DisplayFrame(AegiVideoFrame frame, int sw, int sh) {
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glDisable(GL_TEXTURE_2d)", err); if (GLenum err = glGetError()) throw VideoOutOpenGLException(L"glDisable(GL_TEXTURE_2d)", err);
lastFrame = frameNumber;
} }
VideoOutGL::~VideoOutGL() { VideoOutGL::~VideoOutGL() {

View file

@ -74,6 +74,8 @@ private:
int textureRows; int textureRows;
/// The number of columns of textures /// The number of columns of textures
int textureCols; int textureCols;
/// The frame currently displayed
int lastFrame;
void DetectOpenGLCapabilities(); void DetectOpenGLCapabilities();
void InitTextures(int width, int height, GLenum format, int bpp); void InitTextures(int width, int height, GLenum format, int bpp);
@ -83,9 +85,13 @@ private:
public: public:
/// @brief Render a frame /// @brief Render a frame
/// @param frame The frame to be displayed /// @param frame The frame to be displayed
/// @param frameNumber The frame number of the frame to be displayed
/// @param sw The current script width /// @param sw The current script width
/// @param sh The current script height /// @param sh The current script height
void DisplayFrame(AegiVideoFrame frame, int sw, int sh); void DisplayFrame(AegiVideoFrame frame, int frameNumber, int sw, int sh);
/// @brief Force the redisplay of the frame the next time DisplayFrame is called even if the frame number has not changed
void InvalidateFrame() { lastFrame = -1; }
/// @brief Constructor /// @brief Constructor
VideoOutGL(); VideoOutGL();