1 #include "FirstUiBuilder.h"
2 #include "UIDirect3DTextureCanvas.h"
4 #include "UIDirect3DPrimaryCanvas.h"
8 UIDirect3DTextureCanvas::UIDirect3DTextureCanvas( const UISize
&Size
, const bool InSystemMemory
) :
9 UIDirectDrawCanvas( Size
),
13 mInSystemMemory
= InSystemMemory
;
16 //----------------------------------------------------------------------
18 UIDirect3DTextureCanvas::~UIDirect3DTextureCanvas()
23 //----------------------------------------------------------------------
25 bool UIDirect3DTextureCanvas::IsA( const UITypeID Type
) const
27 return (Type
== TUIDirect3DTextureCanvas
) || UIDirectDrawCanvas::IsA( Type
);
30 //----------------------------------------------------------------------
32 UIBaseObject
*UIDirect3DTextureCanvas::Clone( void ) const
37 //----------------------------------------------------------------------
39 void UIDirect3DTextureCanvas::SetRenderCanvas( UIDirect3DPrimaryCanvas
*NewRenderCanvas
)
42 NewRenderCanvas
->Attach( this );
45 mRenderCanvas
->Detach( this );
47 mRenderCanvas
= NewRenderCanvas
;
50 //----------------------------------------------------------------------
52 UIDirect3DPrimaryCanvas
*UIDirect3DTextureCanvas::GetRenderCanvas( void ) const
57 //----------------------------------------------------------------------
59 void UIDirect3DTextureCanvas::NotifyRenderCanvasChanged( void )
64 //----------------------------------------------------------------------
66 bool UIDirect3DTextureCanvas::Generate( void ) const
68 assert( mRenderCanvas
);
72 LPDIRECTDRAWSURFACE7 CreatedSurface
;
73 DDSURFACEDESC2 ddsd
= { sizeof( ddsd
) };
76 // Round texture size up to a power of two
77 const_cast<UIDirect3DTextureCanvas
*>( this )->mSize
.x
= (long)(pow( 2.0, ceil( log( (double) mSize
.x
) / log( 2.0 ) ) ));
78 const_cast<UIDirect3DTextureCanvas
*>( this )->mSize
.y
= (long)(pow( 2.0, ceil( log( (double) mSize
.y
) / log( 2.0 ) ) ));
80 // Make texture a square
81 if( mSize
.x
< mSize
.y
)
82 const_cast<UIDirect3DTextureCanvas
*>( this )->mSize
.x
= mSize
.y
;
84 const_cast<UIDirect3DTextureCanvas
*>( this )->mSize
.y
= mSize
.x
;
86 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
87 ddsd
.dwWidth
= GetWidth();
88 ddsd
.dwHeight
= GetHeight();
90 mRenderCanvas
->GetPreferedPixelFormat( &ddsd
.ddpfPixelFormat
);
93 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
95 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
97 ddsd
.ddsCaps
.dwCaps2
= 0;
99 hr
= gDirectDraw
->CreateSurface( &ddsd
, &CreatedSurface
, 0 );
104 const_cast<UIDirect3DTextureCanvas
*>( this )->SetSurface( CreatedSurface
);
106 else if( mSurface
->IsLost() )
108 if( FAILED( mSurface
->Restore() ) )
112 if( !UICanvas::Generate() )
117 const_cast<UIDirect3DTextureCanvas
*>( this )->mSurface
= 0;
124 //----------------------------------------------------------------------
126 bool UIDirect3DTextureCanvas::CreateFromSurfaceDescription( LPDDSURFACEDESC2 pddsd
)
130 LPDIRECTDRAWSURFACE7 CreatedSurface
;
133 hr
= gDirectDraw
->CreateSurface( pddsd
, &CreatedSurface
, 0 );
138 SetSurface( CreatedSurface
);
142 //----------------------------------------------------------------------
144 void UIDirect3DTextureCanvas::SetHasShader (bool b
)
149 //----------------------------------------------------------------------