Simplify, optimize. I'm staying over 150fps with my normal test clip,

in OpenGL, 16-bit textures.
This commit is contained in:
Glenn Maynard
2003-06-29 08:15:08 +00:00
parent 7951b5f3e7
commit 7034dbddc6
2 changed files with 20 additions and 40 deletions
@@ -47,7 +47,6 @@ MovieTexture_DShow::MovieTexture_DShow( RageTextureID ID ) :
buffer = NULL; buffer = NULL;
buffer_lock = SDL_CreateSemaphore(1); buffer_lock = SDL_CreateSemaphore(1);
buffer_finished = SDL_CreateSemaphore(0); buffer_finished = SDL_CreateSemaphore(0);
m_img = NULL;
Create(); Create();
CreateFrameRects(); CreateFrameRects();
@@ -100,7 +99,6 @@ MovieTexture_DShow::~MovieTexture_DShow()
LOG->Flush(); LOG->Flush();
if(m_uTexHandle) if(m_uTexHandle)
DISPLAY->DeleteTexture( m_uTexHandle ); DISPLAY->DeleteTexture( m_uTexHandle );
SDL_FreeSurface( m_img );
SDL_DestroySemaphore(buffer_lock); SDL_DestroySemaphore(buffer_lock);
SDL_DestroySemaphore(buffer_finished); SDL_DestroySemaphore(buffer_finished);
@@ -118,8 +116,6 @@ void MovieTexture_DShow::CheckFrame()
if(buffer == NULL) if(buffer == NULL)
return; return;
ASSERT( m_img );
VDCHECKPOINT; VDCHECKPOINT;
/* Just in case we were invalidated: */ /* Just in case we were invalidated: */
@@ -135,29 +131,22 @@ void MovieTexture_DShow::CheckFrame()
0x0000FF, 0x0000FF,
0x000000 ); 0x000000 );
/* We don't want to actually blend the alpha channel over the destination converted /* Optimization notes:
* surface; we want to simply blit it, so make sure SDL_SRCALPHA is not on. */ *
SDL_SetAlpha( fromDShow, 0, SDL_ALPHA_OPAQUE ); * With D3D, this surface can be anything; it'll convert it on the fly. If
* it happens to exactly match the texture, it'll copy a little faster.
SDL_Rect area; *
area.x = area.y = 0; * With OpenGL, it's best that this be a real, supported texture format, though
area.w = short(fromDShow->w); * it doesn't need to be that of the actual texture. If it isn't, it'll have
area.h = short(fromDShow->h); * to do a very slow conversion. Both RGB8 and BGR8 are both (usually) valid
* formats.
/* XXX: For high-resolution movies, it's much faster to convert a BGR8 surface */
* to RGB8 in place than to blit it to another surface, since it's much easier
* on the cache. It'd be even faster to try as hard as we can to not do a
* conversion at all; both OpenGL and D3D have BGR texture modes. */
SDL_BlitSurface(fromDShow, &area, m_img, &area);
VDCHECKPOINT; VDCHECKPOINT;
DISPLAY->UpdateTexture( DISPLAY->UpdateTexture(
m_uTexHandle, m_uTexHandle,
m_PixelFormat, fromDShow,
m_img,
0, 0, 0, 0,
m_iImageWidth, m_iImageHeight ); m_iImageWidth, m_iImageHeight );
// min(m_iSourceWidth,m_iTextureWidth), min(m_iSourceHeight,m_iTextureHeight) );
VDCHECKPOINT; VDCHECKPOINT;
SDL_FreeSurface( fromDShow ); SDL_FreeSurface( fromDShow );
@@ -330,43 +319,37 @@ void MovieTexture_DShow::CreateTexture()
* Some way to figure this out dynamically would be nice, but it's probably * Some way to figure this out dynamically would be nice, but it's probably
* impossible. (For example, 24-bit textures may even be cheaper on pure * impossible. (For example, 24-bit textures may even be cheaper on pure
* AGP cards; 16-bit requires a conversion.) */ * AGP cards; 16-bit requires a conversion.) */
PixelFormat pixfmt;
switch( TEXTUREMAN->GetTextureColorDepth() ) switch( TEXTUREMAN->GetTextureColorDepth() )
{ {
default: default:
ASSERT(0); ASSERT(0);
case 16: case 16:
if( DISPLAY->SupportsTextureFormat(FMT_RGB5) ) if( DISPLAY->SupportsTextureFormat(FMT_RGB5) )
m_PixelFormat = FMT_RGB5; pixfmt = FMT_RGB5;
else else
m_PixelFormat = FMT_RGBA4; // everything supports RGBA4 pixfmt = FMT_RGBA4; // everything supports RGBA4
break; break;
case 32: case 32:
if( DISPLAY->SupportsTextureFormat(FMT_RGB8) ) if( DISPLAY->SupportsTextureFormat(FMT_RGB8) )
m_PixelFormat = FMT_RGB8; pixfmt = FMT_RGB8;
else if( DISPLAY->SupportsTextureFormat(FMT_RGBA8) ) else if( DISPLAY->SupportsTextureFormat(FMT_RGBA8) )
m_PixelFormat = FMT_RGBA8; pixfmt = FMT_RGBA8;
else if( DISPLAY->SupportsTextureFormat(FMT_RGB5) ) else if( DISPLAY->SupportsTextureFormat(FMT_RGB5) )
m_PixelFormat = FMT_RGB5; pixfmt = FMT_RGB5;
else else
m_PixelFormat = FMT_RGBA4; // everything supports RGBA4 pixfmt = FMT_RGBA4; // everything supports RGBA4
break; break;
} }
const PixelFormatDesc *pfd = DISPLAY->GetPixelFormatDesc(m_PixelFormat); const PixelFormatDesc *pfd = DISPLAY->GetPixelFormatDesc(pixfmt);
SDL_Surface *img = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, m_iTextureWidth, m_iTextureHeight, SDL_Surface *img = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, m_iTextureWidth, m_iTextureHeight,
pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3]); pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3]);
m_uTexHandle = DISPLAY->CreateTexture( m_PixelFormat, img ); m_uTexHandle = DISPLAY->CreateTexture( pixfmt, img );
SDL_FreeSurface( img ); SDL_FreeSurface( img );
/* Have to free our frame holder because we might need a different
* PixelFormat than before. */
if( m_img )
SDL_FreeSurface( m_img );
m_img = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, m_iImageWidth, m_iImageHeight,
pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3]);
} }
bool MovieTexture_DShow::PlayMovie() bool MovieTexture_DShow::PlayMovie()
@@ -36,7 +36,6 @@ typedef char TCHAR, *PTCHAR;
#include "RageDisplay.h" #include "RageDisplay.h"
#include "RageTexture.h" #include "RageTexture.h"
#include "RageThreads.h" #include "RageThreads.h"
struct SDL_Surface;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -66,8 +65,6 @@ public:
private: private:
const char *buffer; const char *buffer;
SDL_sem *buffer_lock, *buffer_finished; SDL_sem *buffer_lock, *buffer_finished;
SDL_Surface* m_img; // last frame in PixelFormat that is being used by graphics card
PixelFormat m_PixelFormat; // format being used by graphics card
void Create(); void Create();