Skip to content

Commit 20e71ad

Browse files
committed
ABINKMoviePlayer::RenderToFrameBuffer
1 parent be486cc commit 20e71ad

File tree

21 files changed

+236
-15
lines changed

21 files changed

+236
-15
lines changed

OpenJPOG/Source/ARenderer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ARenderer::ARenderer()
2424
m_pViewport = TNULL;
2525
m_fFarClip = 160.0f;
2626
m_pcScreenCaptureBuffer = TNULL;
27+
m_eCaptureState = CAPTURESTATE_CREATE;
2728
}
2829

2930
TBOOL ARenderer::OnCreate()
@@ -44,6 +45,9 @@ TBOOL ARenderer::OnUpdate(TFLOAT a_fDeltaTime)
4445
MoviePlayerState state = RenderMovie(a_fDeltaTime);
4546
if (state != MOVIEPLAYERSTATE_RUNNING) {
4647
// Render things
48+
if (m_eCaptureState != CAPTURESTATE_POLL) {
49+
50+
}
4751
}
4852
g_oTheApp.GetRootTask()->GetRenderInterface()->Update(a_fDeltaTime);
4953
return TTask::OnUpdate(a_fDeltaTime);

OpenJPOG/Source/GUI/AGUIMatLibPicture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class AGUIMatLibPicture : public AGUIPicture
66
{
7-
DECLARE_DYNAMIC(AGUIMatLibPicture, AGUIPicture);
7+
DECLARE_DYNAMIC(AGUIMatLibPicture);
88

99
public:
1010

OpenJPOG/Source/GUI/AGUIPicture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class AGUIPicture : public Toshi::TObject
77
{
8-
DECLARE_DYNAMIC(AGUIPicture, Toshi::TObject);
8+
DECLARE_DYNAMIC(AGUIPicture);
99

1010
public:
1111

OpenJPOG/Source/GUI/AGUISystem.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,22 @@ IMPLEMENT_DYNCREATE(AGUISystem, TTask)
1616
AGUISystem::AGUISystem()
1717
{
1818
m_pGUIInterface = TNULL;
19+
m_pDisplayContext = TNULL;
20+
m_pTextureFactory = TNULL;
21+
m_pFontFactory = TNULL;
22+
m_pGUIInterface = static_cast<TGUIInterface *>(TFindClass(TGUIInterface, TNULL)->CreateObject());
23+
m_pGUIInterface->SetKernelInterface(g_oTheApp.GetKernel());
24+
m_pTextureFactory = new AGUITextureFactory();
1925
}
2026

2127
// $JPOG: FUNCTION 0067bc30
2228
TBOOL AGUISystem::OnCreate()
2329
{
2430
auto pRenderer = g_oTheApp.GetRootTask()->GetRenderInterface();
2531
m_pNullResource = (TNullResource *)pRenderer->CreateResource(&TGetClass(TNullResource), TNULL, TNULL);
26-
// Why does it not find TSpriteShaderHAL?
27-
//m_pSpriteShader = (TSpriteShader *)pRenderer->CreateResource(TFindClass(TSpriteShaderHAL, TNULL), "SHSPRITE", pRenderer->GetSystemResource(TRenderInterface::SYSRESOURCE_SHADERS));
32+
TClass *pClass = &TGetClass(TSpriteShaderHAL);
33+
m_pSpriteShader = (TSpriteShader *)pRenderer->CreateResource(TFindClass(TSpriteShaderHAL, TNULL), "SHSPRITE", pRenderer->GetSystemResource(TRenderInterface::SYSRESOURCE_SHADERS));
34+
m_pSpriteShader->Create();
2835
m_pGUIInterface->Create();
2936
m_pDisplayContext = new PGUITRDisplayContext();
3037
m_pDisplayContext->Create(g_oTheApp.GetRootTask()->GetRenderInterface(), m_pTextureFactory, m_pFontFactory);

OpenJPOG/Source/GUI/AGUISystem.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "PGuiRenderer/PGUITRDisplayContext.h"
1010
#include "TSpriteShader/Include/TSpriteShader.h"
1111
#include "AGUIMatLibPicture.h"
12+
#include "AGUITextureFactory.h"
1213

1314
class AGUISystem : public Toshi::TTask
1415
{
@@ -33,17 +34,22 @@ class AGUISystem : public Toshi::TTask
3334
{
3435
return m_pScreen;
3536
}
37+
// $JPOG: FUNCTION 0046e3a0
38+
Toshi::TSpriteShader *GetShader()
39+
{
40+
return m_pSpriteShader;
41+
}
3642

3743
static AGUISystem *TOSHI_API GetGUISystem();
3844

3945
protected:
4046
static TBOOL OnScreenPaint(AGUISystem *a_pGUISystem, Toshi::TGUIScreen *a_pScreen, Toshi::TGUIScreenPaintEvent *a_pEvent);
4147

4248
private:
43-
Toshi::TGUIInterface *m_pGUIInterface; // 0x24
49+
Toshi::TManagedPtr<Toshi::TGUIInterface> m_pGUIInterface; // 0x24
4450
Toshi::TGUIScreen *m_pScreen; // 0x28
4551
PGUITRDisplayContext *m_pDisplayContext; // 0xA4
46-
PGUITRTextureFactory *m_pTextureFactory; // 0xA8
52+
AGUITextureFactory *m_pTextureFactory; // 0xA8
4753
PGUITRFontFactory *m_pFontFactory; // 0xAC
4854
Toshi::TListener<Toshi::TGUIScreen, Toshi::TGUIScreenPaintEvent, AGUISystem> m_oPaintListener; // 0x118
4955
Toshi::TNullResource *m_pNullResource; // 0x140
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "AGUITextureFactory.h"
2+
3+
IMPLEMENT_DYNCREATE(AGUITextureFactory, PGUITRTextureFactory)
4+
5+
Toshi::TTextureResource *AGUITextureFactory::LoadTTexture(const Toshi::TPCString &a_sFileName, int &a_iWidth, int &a_iHeight)
6+
{
7+
return PGUITRTextureFactory::LoadTTexture(a_sFileName, a_iWidth, a_iHeight);
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include "PGUIRenderer/PGUITRTextureFactory.h"
3+
4+
class AGUITextureFactory : public PGUITRTextureFactory
5+
{
6+
DECLARE_DYNAMIC(AGUISystem)
7+
8+
public:
9+
virtual Toshi::TTextureResource *LoadTTexture(const Toshi::TPCString &a_sFileName, int &a_iWidth, int &a_iHeight);
10+
};

OpenJPOG/Source/Movie/ABINKMoviePlayer.cpp

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "main.h"
33
#include "TKernel/TManagedPointer.h"
44
#include "TRenderD3D/TRenderD3DInterface.h"
5+
#include "TRenderD3D/TTextureResourceD3D.h"
56

67
//-----------------------------------------------------------------------------
78
// Enables memory debugging.
@@ -131,11 +132,14 @@ TBOOL ABINKMoviePlayer::StartMovie(TPCHAR a_szMovieName, TBOOL a_bUnk1, TPCHAR a
131132
TBOOL ABINKMoviePlayer::Update(TFLOAT a_fDeltaTime)
132133
{
133134
if (!m_bHasMovieStopped && m_hBink) {
135+
m_bRenderingTiles = TFALSE;
134136
BinkService(m_hBink);
135137
if (BinkWait(m_hBink)) {
138+
m_bDrawingFrame = TFALSE;
136139
BinkSleep(500);
137140
return TFALSE;
138141
}
142+
m_bDrawingFrame = TTRUE;
139143
RenderToFrameBuffer();
140144
}
141145
return TFALSE;
@@ -233,8 +237,62 @@ TBOOL ABINKMoviePlayer::InitializeVideoResource()
233237
size *= 256 * 256;
234238
TPVOID buffer = tmalloc(size);
235239
TSystem::MemSet(buffer, 0xFF, size);
236-
m_pTextures[2] = factory->CreateEx(buffer, size, 256, 256, 1, textureFormat, textureFormatSize);
237-
m_pTextures[2]->SetAddressModeMode(TTextureResource::ADDRESSMODE_CLAMP);
240+
TSpriteShader *pShader = AGUISystem::GetGUISystem()->GetShader();
241+
for (int i = 0; i < MAX_TILES; i++)
242+
{
243+
m_pTextures[i] = factory->CreateEx(buffer, size, 256, 256, 1, textureFormat, textureFormatSize);
244+
m_pTextures[i]->SetAddressModeMode(TTextureResource::ADDRESSMODE_CLAMP);
245+
m_pTextures[i]->Validate();
246+
247+
m_pMaterial = pShader->CreateMaterial(TNULL);
248+
m_pMaterial->Create();
249+
m_pMaterial->SetBlendMode(6);
250+
m_pMaterial->Validate();
251+
252+
m_aRects[i].pTexture = m_pTextures[i];
253+
m_aRects[i].pMaterial = m_pMaterial;
254+
}
255+
m_aRects[0].m_iPosX = 0.0f;
256+
m_aRects[0].m_iPosY = 0.0f;
257+
m_aRects[0].m_iWidth = 256.0f;
258+
m_aRects[0].m_iHeight = 256.0f;
259+
m_aRects[0].m_vPos.Set(0.0f, 0.0f);
260+
m_aRects[0].m_vUV.Set(1.0f, 1.0f);
261+
262+
m_aRects[1].m_iPosX = 256.0f;
263+
m_aRects[1].m_iPosY = 0.0f;
264+
m_aRects[1].m_iWidth = 512.0f;
265+
m_aRects[1].m_iHeight = 256.0f;
266+
m_aRects[1].m_vPos.Set(0.0f, 0.0f);
267+
m_aRects[1].m_vUV.Set(1.0f, 1.0f);
268+
269+
m_aRects[2].m_iPosX = 512.0f;
270+
m_aRects[2].m_iPosY = 0.0f;
271+
m_aRects[2].m_iWidth = 640.0f;
272+
m_aRects[2].m_iHeight = 256.0f;
273+
m_aRects[2].m_vPos.Set(0.0f, 0.0f);
274+
m_aRects[2].m_vUV.Set(0.5f, 1.0f);
275+
276+
m_aRects[3].m_iPosX = 0.0f;
277+
m_aRects[3].m_iPosY = 256.0f;
278+
m_aRects[3].m_iWidth = 256.0f;
279+
m_aRects[3].m_iHeight = 448.0f;
280+
m_aRects[3].m_vPos.Set(0.0f, 0.0f);
281+
m_aRects[3].m_vUV.Set(1.0f, 0.75f);
282+
283+
m_aRects[4].m_iPosX = 256.0f;
284+
m_aRects[4].m_iPosY = 256.0f;
285+
m_aRects[4].m_iWidth = 512.0f;
286+
m_aRects[4].m_iHeight = 448.0f;
287+
m_aRects[4].m_vPos.Set(0.0f, 0.0f);
288+
m_aRects[4].m_vUV.Set(1.0f, 0.75f);
289+
290+
m_aRects[5].m_iPosX = 512.0f;
291+
m_aRects[5].m_iPosY = 256.0f;
292+
m_aRects[5].m_iWidth = 640.0f;
293+
m_aRects[5].m_iHeight = 448.0f;
294+
m_aRects[5].m_vPos.Set(0.0f, 0.0f);
295+
m_aRects[5].m_vUV.Set(0.5f, 0.75f);
238296

239297
return TTRUE;
240298
}
@@ -302,5 +360,51 @@ void ABINKMoviePlayer::BinkSleep(TINT a_iMicroseconds)
302360
// $JPOG: FUNCTION 006d5f20
303361
TBOOL ABINKMoviePlayer::RenderToTiles()
304362
{
305-
return TBOOL();
363+
if (m_hBink == TNULL || m_bHasMovieStopped || !m_bDrawingFrame) {
364+
return TFALSE;
365+
}
366+
367+
auto pRootTask = g_oTheApp.GetRootTask();
368+
auto pRenderInterface = pRootTask->GetRenderInterface();
369+
370+
m_iFrameCount++;
371+
372+
pRenderInterface->Supports32BitTextures();
373+
374+
BinkDoFrame(m_hBink);
375+
376+
if (!m_bUnk && m_iFrameCount == m_hBink->Frames) {
377+
StopMovie();
378+
m_bHasMovieStopped = TTRUE;
379+
return TFALSE;
380+
}
381+
382+
SetFrameReady(TTRUE);
383+
m_bFrameReady = TTRUE;
384+
385+
// Render to each tile
386+
for (int i = 0; i < MAX_TILES; i++)
387+
{
388+
TTextureResourceHAL *pTexture = static_cast<TTextureResourceHAL *>(m_aRects[i].pTexture);
389+
IDirect3DTexture8 *d3dtexture = pTexture->GetD3DTexture();
390+
391+
D3DLOCKED_RECT lockedRect;
392+
d3dtexture->LockRect(0, &lockedRect, NULL, 0);
393+
394+
BinkCopyToBuffer(
395+
m_hBink,
396+
lockedRect.pBits,
397+
lockedRect.Pitch,
398+
0x100,
399+
static_cast<int>(m_aRects[i].m_iWidth - m_aRects[i].m_iPosX),
400+
static_cast<int>(m_aRects[i].m_iHeight - m_aRects[i].m_iPosY),
401+
BINKSURFACE8P);
402+
403+
d3dtexture->UnlockRect(0);
404+
}
405+
406+
m_bFrameReady = TTRUE;
407+
BinkNextFrame(m_hBink);
408+
409+
return TTRUE;
306410
}

OpenJPOG/Source/Movie/ABINKMoviePlayer.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,30 @@
77
#include <windows.h>
88
#include "TKernel/TMemory.h"
99
#include "TRender/TTextureFactory.h"
10+
#include "TSpriteShader/Include/TSpriteShader.h"
11+
12+
#define MAX_TILES 6
1013

1114
TOSHI_NAMESPACE_BEGIN
1215

1316
class ABINKMoviePlayer : public AMoviePlayer
1417
{
18+
struct Rect
19+
{
20+
TTextureResource *pTexture = TNULL; // 0x280
21+
TSpriteMaterial *pMaterial = TNULL; // 0x284
22+
TFLOAT m_iPosX; // 0x288
23+
TFLOAT m_iPosY; // 0x28C
24+
TFLOAT m_iWidth; // 0x290
25+
TFLOAT m_iHeight; // 0x294
26+
Toshi::TVector2 m_vPos;
27+
Toshi::TVector2 m_vUV;
28+
29+
//~Rect();
30+
31+
//TBOOL Create(int a_iPosX, int a_iPosY, int a_iWidth, int a_iHeight, TFLOAT a_iRenderPos1X, TFLOAT a_iRenderPos1Y, TFLOAT a_iRenderWidth, TFLOAT a_iRenderHeight, Toshi::TTEXTURERESOURCEFORMAT a_eFormat);
32+
};
33+
1534
public:
1635
ABINKMoviePlayer();
1736

@@ -34,6 +53,12 @@ class ABINKMoviePlayer : public AMoviePlayer
3453

3554
virtual TBOOL FreeVideoResource();
3655

56+
// $JPOG: FUNCTION 006d6610
57+
virtual TBOOL IsMoviePlaying()
58+
{
59+
return !m_bHasMovieStopped;
60+
}
61+
3762
// $JPOG: FUNCTION 006d6640
3863
virtual TBOOL FreeAudioResource()
3964
{
@@ -76,6 +101,7 @@ class ABINKMoviePlayer : public AMoviePlayer
76101
TBOOL m_bIsBINKInitialized; // 0x211
77102
TBOOL m_bDrawingFrame; // 0x213
78103
TBOOL m_bRenderingTiles; // 0x214
104+
TBOOL m_bFrameReady; // 0x212
79105
HBINK m_hBink; // 0x218
80106
TINT m_iFrameCount; // 0x220
81107
TINT m_iFrameBufferWidth; // 0x224
@@ -84,8 +110,10 @@ class ABINKMoviePlayer : public AMoviePlayer
84110
TINT m_iHeight; // 0x230
85111
Toshi::TTextureResource *m_pTextures[8]; // 0x240
86112
TPBYTE m_pFrameBufferBits; // 0x234
113+
Toshi::TSpriteMaterial *m_pMaterial; // 0x260
87114
LPDIRECTSOUND m_pDirectSound; // 0x278
88115
TINT m_iCurrentTextureIndex; // 0x27C
116+
Rect m_aRects[6]; // 0x280
89117
};
90118

91119
TOSHI_NAMESPACE_END

OpenJPOG/Source/Movie/AMoviePlayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class AMoviePlayer
176176
// 0x0 vftable
177177
TBOOL m_bIsStopped; // 0x4
178178
TBOOL m_bIsInitialized; // 0x5
179+
TBOOL m_bUnk; // 0x6
179180
TBOOL m_bIsFrameReady; // 0x7
180181
TBOOL m_bIsFullscreen; // 0x8
181182
TBOOL m_bDoAudio; // 0x9

0 commit comments

Comments
 (0)