3#ifdef TOSHI_SKU_WINDOWS
37 [](
unsigned int size ) {
45 int iOutput = FSOUND_GetOutput();
47 if ( iOutput == FSOUND_OUTPUT_WINMM )
49 BinkSetSoundSystem( BinkOpenWaveOut, 0 );
51 else if ( iOutput == FSOUND_OUTPUT_DSOUND )
53 auto outHandle = FSOUND_GetOutputHandle();
57 BinkSetSoundSystem( BinkOpenDirectSound,
TREINTERPRETCAST(
int, outHandle ) );
71 if ( m_Bink->LastFrameNum == m_Bink->Frames )
81 BinkPause( m_Bink, 1 );
82 BinkSetSoundOnOff( m_Bink, 0 );
90 BinkPause( m_Bink, 0 );
91 BinkSetSoundOnOff( m_Bink, 1 );
96 auto iWaitRes = BinkWait( m_Bink );
100 if ( BinkDoFrame( m_Bink ) == 0 )
102 if ( !m_bVideoFitsBackBuffer || !m_pSurface )
106 if ( !CreateSurfaces() )
111 m_eFormat |= 0x80000000;
115 auto ppRenderSurface = &m_pSurface;
117 if ( m_bVideoFitsBackBuffer ||
121 if ( S_OK == ( *ppRenderSurface )->LockRect( &rect,
TNULL, 0 ) )
123 BinkCopyToBuffer( m_Bink, rect.pBits, rect.Pitch, m_Bink->Height, 0, 0, m_eFormat );
124 m_eFormat &= 0x7fffffff;
125 ( *ppRenderSurface )->UnlockRect();
127 if ( !m_bVideoFitsBackBuffer )
129 ( *ppRenderSurface )->Release();
130 ( *ppRenderSurface ) =
TNULL;
136 BinkNextFrame( m_Bink );
152 m_Bink = BinkOpen( m_szMoviePath, 0 );
154 if ( m_Bink !=
TNULL )
156 if ( !CreateSurfaces() )
169 return m_Bink !=
TNULL;
172TBOOL ABINKMoviePlayer::CreateSurfaces()
175 auto pDevice = pRender->GetDirect3DDevice();
177 IDirect3DSurface8* pSurface;
178 auto hRes = pDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pSurface );
182 D3DSURFACE_DESC desc;
183 hRes = pSurface->GetDesc( &desc );
187 switch ( desc.Format )
192 case D3DFMT_A8R8G8B8:
195 case D3DFMT_X8R8G8B8:
201 case D3DFMT_X1R5G5B5:
204 case D3DFMT_A1R5G5B5:
207 case D3DFMT_A4R4G4B4:
213 if ( desc.Width == m_Bink->Width && desc.Height == m_Bink->Height )
215 m_bVideoFitsBackBuffer =
TTRUE;
216 hRes = pDevice->CreateImageSurface( desc.Width, desc.Height, desc.Format, &m_pSurface );
220 m_bVideoFitsBackBuffer =
TFALSE;
221 CreateAGUISurfaces( desc.Width, desc.Height, desc.Format );
246 m_bPaused = a_bPause;
265 if ( m_bVideoFitsBackBuffer )
267 IDirect3DSurface8* pSurface;
268 auto hRes = pDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pSurface );
272 pDevice->CopyRects( m_pSurface,
TNULL, 0, pSurface,
TNULL );
280 pRender->BeginScene();
282 for (
TINT i = 0; i < m_iNumRects; i++ )
284 pRender->SetMaterial( m_pRects[ i ].pMaterial );
285 pRender->RenderRectangle( m_pRects[ i ].Pos1, m_pRects[ i ].Pos2, m_pRects[ i ].UV1, m_pRects[ i ].UV2 );
298TBOOL ABINKMoviePlayer::CreateAGUISurfaces(
TUINT a_uiWidth,
TUINT a_uiHeight, D3DFORMAT a_eFormat )
303 auto hRes = pDevice->GetDeviceCaps( &caps );
307 TUINT uiWidth = m_Bink->Width;
308 TUINT uiHeight = m_Bink->Height;
309 TUINT uiMaxTextureWidth = caps.MaxTextureWidth;
310 TUINT uiMaxTextureHeight = caps.MaxTextureHeight;
312 m_iNumRects = ( ( uiHeight - 1 ) + uiMaxTextureHeight ) / uiMaxTextureHeight * ( ( uiWidth - 1 ) + uiMaxTextureWidth ) / uiMaxTextureWidth;
313 m_pRects =
new Rect[ m_iNumRects ];
318 AGUI2::GetSingleton()->GetDimensions( fWidth, fHeight );
320 TFLOAT fScaleX = a_uiWidth / ( ( pDisplayParams->uiWidth / fWidth ) * m_Bink->Width );
321 TFLOAT fScaleY = a_uiHeight / ( ( pDisplayParams->uiHeight / fHeight ) * m_Bink->Height );
325 if ( a_eFormat == D3DFMT_A8R8G8B8 )
327 eFormat = TTEXTURERESOURCEFORMAT::R8G8B8A8;
329 else if ( a_eFormat == D3DFMT_X8R8G8B8 )
331 eFormat = TTEXTURERESOURCEFORMAT::R8G8B8;
333 else if ( a_eFormat == D3DFMT_A1R5G5B5 )
335 eFormat = TTEXTURERESOURCEFORMAT::R5G5B5A1;
346 TUINT uiRectIndex = 0;
348 TUINT uiLeftHeight = uiHeight;
349 while ( 0 <
TINT( uiLeftHeight ) )
352 uiWidth = m_Bink->Width;
355 TUINT uiLeftWidth = m_Bink->Width;
357 while ( 0 <
TINT( uiLeftWidth ) )
360 TBOOL bCreated = m_pRects[ uiRectIndex ].Create(
365 ( uiPosX + fVideoWidth * -0.5f ) * fScaleX,
366 ( uiPosY + fVideoHeight * -0.5f ) * fScaleY,
367 uiRectWidth * fScaleX,
368 uiRectHeight * fScaleY,
374 TASSERT(
TFALSE,
"ABINKMoviePlayer: Unable to create rectangle" );
380 uiPosX +=
TMath::Min( uiWidth, uiMaxTextureWidth );
382 uiLeftWidth -= uiRectWidth;
386 uiPosY += uiRectHeight;
387 uiLeftHeight -= uiRectHeight;
394void ABINKMoviePlayer::DestroySurfaces()
398 m_pSurface->Release();
407ABINKMoviePlayer::Rect::~Rect()
417 pTexture->DestroyResource();
431 Pos1 = { a_iRenderPos1X, a_iRenderPos1Y };
432 Pos2 = { a_iRenderPos1X + a_iRenderWidth, a_iRenderPos1Y + a_iRenderHeight };
438 if ( a_eFormat == TTEXTURERESOURCEFORMAT::Unknown )
442 else if ( a_eFormat == TTEXTURERESOURCEFORMAT::R8G8B8A8 || a_eFormat == TTEXTURERESOURCEFORMAT::R8G8B8 )
446 else if ( a_eFormat == TTEXTURERESOURCEFORMAT::R5G5B5A1 )
455 auto uiDataSize = iPixelSize * uiWidth * uiHeight;
456 pData =
new TUINT8[ uiDataSize ];
459 pTexture = pTexFactory->CreateEx( pData, uiDataSize, uiWidth, uiHeight, 1, a_eFormat, 4 );
465 UV1 = { 0.0f, 0.0f };
466 UV2 = {
TFLOAT( a_iWidth ) / uiWidth,
TFLOAT( a_iHeight ) / uiHeight };
void * TMalloc(TSIZE a_uiSize, Toshi::TMemory::MemBlock *a_pMemBlock, const TCHAR *a_szFileName, TINT a_iLineNum)
Allocates memory from a specific memory block.
void TFree(void *a_pMem)
Frees previously allocated memory.
@ SYSRESOURCE_TEXTUREFACTORY
#define TSTATICCAST(POINTERTYPE, VALUE)
#define TREINTERPRETCAST(TYPE, VALUE)
#define TOSHI_NAMESPACE_USING
#define TDEFINE_CLASS(...)
TSystemManager g_oSystemManager
TFORCEINLINE TFLOAT Abs(TFLOAT fVal)
constexpr TUINT RoundToNextPowerOfTwo(TUINT a_uiValue)
TFORCEINLINE const T & Min(const T &a, const T &b)
TFORCEINLINE IDirect3DDevice8 * GetDirect3DDevice() const
Gets the Direct3D device.
static TFORCEINLINE TRenderD3DInterface * Interface()
Gets the render interface singleton.
virtual DISPLAYPARAMS * GetCurrentDisplayParams() OVERRIDE
Gets the current display parameters.
T * GetSystemResource(SYSRESOURCE systemResource)
static TFORCEINLINE TRenderInterface * GetSingleton()
static void String8Format(TCHAR *str, TINT size, const TCHAR *format,...)
static AGUI2Renderer * GetRenderer()
void SetBlendState(TUINT a_eBlendState)
virtual AGUI2Material * CreateMaterial(const TCHAR *a_szTextureName)=0
virtual void DestroyMaterial(AGUI2Material *a_pMaterial)=0
virtual void Render(TFLOAT a_fDeltaTime) override
virtual void SetMovieFile(const TCHAR *a_szFile)
virtual TBOOL IsMoviePaused() override
virtual TBOOL IsMoviePlaying() override
virtual TBOOL OnCreate() override
virtual void StopMovie() override
virtual void PauseMovie(TBOOL a_bPause) override
virtual void OnDestroy() override
virtual TBOOL PlayMovie(const TCHAR *a_szFileName, TUINT32 a_Unk) override
virtual TBOOL OnUpdate(TFLOAT a_fDeltaTime) override