From 279b884cbb11eb335fe02b8129342c84ccd6e25d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 14 Feb 2003 05:56:24 +0000 Subject: [PATCH] simplify handle texture invalidation --- stepmania/src/RageMovieTexture.cpp | 31 +++++++++++++++++------------- stepmania/src/RageMovieTexture.h | 6 +++--- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/stepmania/src/RageMovieTexture.cpp b/stepmania/src/RageMovieTexture.cpp index 529555beb8..b58e8f36ca 100644 --- a/stepmania/src/RageMovieTexture.cpp +++ b/stepmania/src/RageMovieTexture.cpp @@ -100,6 +100,9 @@ void RageMovieTexture::Update(float fDeltaTime) buffer_changed = false; + /* Just in case we were invalidated: */ + CreateTexture(); + DISPLAY->SetTexture(this); glPixelStorei(GL_UNPACK_SWAP_BYTES, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -195,6 +198,17 @@ void RageMovieTexture::Create() m_iSourceWidth = pCTR->GetVidWidth(); m_iSourceHeight = pCTR->GetVidHeight(); + /* image size cannot exceed max size */ + m_iImageWidth = min( m_iSourceWidth, m_ActualID.iMaxSize ); + m_iImageHeight = min( m_iSourceHeight, m_ActualID.iMaxSize ); + + /* Texture dimensions need to be a power of two; jump to the next. */ + m_iTextureWidth = power_of_two(m_iImageWidth); + m_iTextureHeight = power_of_two(m_iImageHeight); + + if(buffer == NULL) + buffer = new char[m_iSourceWidth * m_iSourceHeight * 3]; + /* We've set up the movie, so we know the dimensions we need. Set * up the texture. */ CreateTexture(); @@ -211,19 +225,12 @@ void RageMovieTexture::NewData(char *data) memcpy(buffer, data, m_iSourceWidth * m_iSourceHeight * 3); } -bool RageMovieTexture::CreateTexture() +void RageMovieTexture::CreateTexture() { - /* image size cannot exceed max size */ - m_iImageWidth = min( m_iSourceWidth, m_ActualID.iMaxSize ); - m_iImageHeight = min( m_iSourceHeight, m_ActualID.iMaxSize ); + if(m_uGLTextureID) + return; - /* Texture dimensions need to be a power of two; jump to the next. */ - m_iTextureWidth = power_of_two(m_iImageWidth); - m_iTextureHeight = power_of_two(m_iImageHeight); - - buffer = new char[m_iSourceWidth * m_iSourceHeight * 3]; - if(!m_uGLTextureID) - glGenTextures(1, &m_uGLTextureID); + glGenTextures(1, &m_uGLTextureID); DISPLAY->SetTexture(this); @@ -231,8 +238,6 @@ bool RageMovieTexture::CreateTexture() string buf(m_iTextureWidth*m_iTextureHeight*3, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, m_iTextureWidth, m_iTextureHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, buf.data()); - - return true; } bool RageMovieTexture::PlayMovie() diff --git a/stepmania/src/RageMovieTexture.h b/stepmania/src/RageMovieTexture.h index 5e1bdd19da..3bddd30c6b 100644 --- a/stepmania/src/RageMovieTexture.h +++ b/stepmania/src/RageMovieTexture.h @@ -45,6 +45,8 @@ class RageMovieTexture : public RageTexture public: RageMovieTexture( RageTextureID ID ); virtual ~RageMovieTexture(); + /* only called by RageTextureManager::InvalidateTextures */ + void Invalidate() { m_uGLTextureID = 0; } void Update(float fDeltaTime); virtual void Reload(); @@ -60,15 +62,13 @@ public: void NewData(char *buffer); protected: - int m_iIndexFrontBuffer; // index of the buffer that should be rendered from - either 0 or 1 - char *buffer; bool buffer_changed; RageMutex buffer_mutex; void Create(); - bool CreateTexture(); + void CreateTexture(); bool PlayMovie(); void CheckMovieStatus();