mirror of
https://github.com/jmarshall23/CnC_Remastered_Collection.git
synced 2026-08-19 17:44:13 +02:00
Complete removal of directdraw and replaced with OpenGL. Has some bugs, movies disabled.
This commit is contained in:
+22
-134
@@ -237,39 +237,7 @@ BOOL GraphicViewPortClass::Change(int x, int y, int w, int h)
|
||||
*=========================================================================*/
|
||||
void GraphicBufferClass::DD_Init(GBC_Enum flags)
|
||||
{
|
||||
//
|
||||
// Create the direct draw surface description
|
||||
//
|
||||
memset (&VideoSurfaceDescription , 0 , sizeof ( VideoSurfaceDescription ));
|
||||
|
||||
VideoSurfaceDescription.dwSize = sizeof( VideoSurfaceDescription );
|
||||
VideoSurfaceDescription.dwFlags = DDSD_CAPS;
|
||||
VideoSurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
||||
|
||||
|
||||
if (!(flags & GBC_VISIBLE)) {
|
||||
VideoSurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
|
||||
VideoSurfaceDescription.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
|
||||
VideoSurfaceDescription.dwHeight = Height;
|
||||
VideoSurfaceDescription.dwWidth = Width;
|
||||
}
|
||||
|
||||
//
|
||||
// Need to set the DDSCAPS_MODEX flag if we want a 320 wide mode
|
||||
//
|
||||
if ( Width == 320 ) {
|
||||
VideoSurfaceDescription.ddsCaps.dwCaps |= DDSCAPS_MODEX;
|
||||
}
|
||||
|
||||
//
|
||||
// Call CreateSurface
|
||||
//
|
||||
DirectDrawObject->CreateSurface( &VideoSurfaceDescription , &VideoSurfacePtr , NULL);
|
||||
AllSurfaces.Add_DD_Surface (VideoSurfacePtr);
|
||||
|
||||
if ( GBC_VISIBLE & flags ){
|
||||
PaletteSurface=VideoSurfacePtr;
|
||||
}
|
||||
rawCpuBuffer = new unsigned char[Width * Height];
|
||||
|
||||
Allocated = FALSE; // even if system alloced, dont flag it cuz
|
||||
// we dont want it freed.
|
||||
@@ -278,13 +246,6 @@ void GraphicBufferClass::DD_Init(GBC_Enum flags)
|
||||
LockCount = 0; // surface is not locked
|
||||
}
|
||||
|
||||
|
||||
void GraphicBufferClass::Attach_DD_Surface (GraphicBufferClass * attach_buffer)
|
||||
{
|
||||
VideoSurfacePtr->AddAttachedSurface (attach_buffer->Get_DD_Surface());
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* GBC::INIT -- Core function responsible for initing a GBC *
|
||||
* *
|
||||
@@ -306,7 +267,7 @@ void GraphicBufferClass::Init(int w, int h, void *buffer, long size, GBC_Enum fl
|
||||
Size = size; // find size of physical buffer
|
||||
Width = w; // Record width of Buffer
|
||||
Height = h; // Record height of Buffer
|
||||
|
||||
rawCpuBuffer = nullptr;
|
||||
//
|
||||
// If the surface we are creating is a direct draw object then
|
||||
// we need to do a direct draw init. Otherwise we will do
|
||||
@@ -316,7 +277,7 @@ void GraphicBufferClass::Init(int w, int h, void *buffer, long size, GBC_Enum fl
|
||||
DD_Init(flags);
|
||||
} else {
|
||||
if (buffer) { // if buffer is specified
|
||||
Buffer = (BYTE *)buffer; // point to it and mark
|
||||
Buffer= (BYTE *)buffer; // point to it and mark
|
||||
Allocated = FALSE; // it as user allocated
|
||||
} else {
|
||||
if (!Size) Size = w*h;
|
||||
@@ -353,23 +314,8 @@ void GraphicBufferClass::Init(int w, int h, void *buffer, long size, GBC_Enum fl
|
||||
void GraphicBufferClass::Un_Init (void)
|
||||
{
|
||||
if ( IsDirectDraw ){
|
||||
|
||||
if ( VideoSurfacePtr ){
|
||||
|
||||
while ( LockCount ){
|
||||
|
||||
if (VideoSurfacePtr->Unlock ( NULL ) == DDERR_SURFACELOST){
|
||||
if (Gbuffer_Focus_Loss_Function){
|
||||
Gbuffer_Focus_Loss_Function();
|
||||
}
|
||||
AllSurfaces.Restore_Surfaces();
|
||||
}
|
||||
}
|
||||
|
||||
AllSurfaces.Remove_DD_Surface (VideoSurfacePtr);
|
||||
VideoSurfacePtr->Release();
|
||||
VideoSurfacePtr = NULL;
|
||||
}
|
||||
delete rawCpuBuffer;
|
||||
rawCpuBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,8 +333,7 @@ void GraphicBufferClass::Un_Init (void)
|
||||
GraphicBufferClass::GraphicBufferClass(void)
|
||||
{
|
||||
GraphicBuff = this; // Get a pointer to our self
|
||||
VideoSurfacePtr = NULL;
|
||||
memset(&VideoSurfaceDescription, 0, sizeof(DDSURFACEDESC));
|
||||
rawCpuBuffer = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -538,7 +483,7 @@ BOOL GraphicBufferClass::Lock(void)
|
||||
/*
|
||||
** If the video surface pointer is null then return
|
||||
*/
|
||||
if (!VideoSurfacePtr) return (FALSE);
|
||||
if (!rawCpuBuffer) return (FALSE);
|
||||
|
||||
/*
|
||||
** If we dont have focus then return failure
|
||||
@@ -548,7 +493,6 @@ BOOL GraphicBufferClass::Lock(void)
|
||||
|
||||
Block_Mouse(this);
|
||||
|
||||
|
||||
//
|
||||
// If surface is already locked then inc the lock count and return true
|
||||
//
|
||||
@@ -558,46 +502,15 @@ BOOL GraphicBufferClass::Lock(void)
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
//
|
||||
// If it isn't locked at all then we will have to request that Direct
|
||||
// Draw actually lock the surface.
|
||||
//
|
||||
Offset = (unsigned long)rawCpuBuffer; // 32bit to 64bit issue here.
|
||||
//Pitch = Width;
|
||||
|
||||
if (VideoSurfacePtr){
|
||||
while (!LockCount && restore_attempts<2) {
|
||||
result = VideoSurfacePtr->Lock ( NULL
|
||||
, &(VideoSurfaceDescription)
|
||||
, DDLOCK_WAIT
|
||||
, NULL);
|
||||
|
||||
switch (result){
|
||||
case DD_OK :
|
||||
Offset = (unsigned long)VideoSurfaceDescription.lpSurface;
|
||||
Pitch = VideoSurfaceDescription.lPitch;
|
||||
Pitch -= Width;
|
||||
LockCount++; // increment count so we can track if
|
||||
TotalLocks++; // Total number of times we have locked (for debugging)
|
||||
//Colour_Debug (1);
|
||||
Unblock_Mouse(this);
|
||||
return (TRUE); // we locked it multiple times.
|
||||
|
||||
case DDERR_SURFACELOST :
|
||||
if (Gbuffer_Focus_Loss_Function){
|
||||
Gbuffer_Focus_Loss_Function();
|
||||
}
|
||||
AllSurfaces.Restore_Surfaces();
|
||||
restore_attempts++;
|
||||
break;
|
||||
|
||||
default :
|
||||
Unblock_Mouse(this);
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
LockCount++; // increment count so we can track if
|
||||
TotalLocks++; // Total number of times we have locked (for debugging)
|
||||
|
||||
//Colour_Debug(1);
|
||||
Unblock_Mouse(this);
|
||||
return (FALSE); //Return false because we couldnt lock or restore the surface
|
||||
return (TRUE); //Return false because we couldnt lock or restore the surface
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
@@ -615,6 +528,8 @@ BOOL GraphicBufferClass::Lock(void)
|
||||
|
||||
BOOL GraphicBufferClass::Unlock(void)
|
||||
{
|
||||
Video_Set_Data((unsigned char *)Get_Graphic_Buffer()->GetMemoryBuffer(), Width, Height);
|
||||
|
||||
//
|
||||
// If there is no lock count or this is not a direct draw surface
|
||||
// then just return true as there is no harm done.
|
||||
@@ -627,17 +542,12 @@ BOOL GraphicBufferClass::Unlock(void)
|
||||
// If lock count is directly equal to one then we actually need to
|
||||
// unlock so just give it a shot.
|
||||
//
|
||||
if (LockCount == 1 && VideoSurfacePtr) {
|
||||
if (LockCount == 1) {
|
||||
Block_Mouse(this);
|
||||
if ( VideoSurfacePtr->Unlock ( NULL ) != DD_OK ){
|
||||
Unblock_Mouse(this);
|
||||
return(FALSE);
|
||||
} else {
|
||||
Offset=NOT_LOCKED;
|
||||
LockCount--;
|
||||
Unblock_Mouse(this);
|
||||
return(TRUE);
|
||||
}
|
||||
Offset = NOT_LOCKED;
|
||||
LockCount--;
|
||||
Unblock_Mouse(this);
|
||||
return(TRUE);
|
||||
}
|
||||
//Colour_Debug (0);
|
||||
LockCount--;
|
||||
@@ -677,30 +587,8 @@ HRESULT GraphicViewPortClass::DD_Linear_Blit_To_Linear (
|
||||
, BOOL mask )
|
||||
|
||||
{
|
||||
RECT source_rectangle;
|
||||
RECT dest_rectangle;
|
||||
int key_source=0;
|
||||
|
||||
if ( mask ){
|
||||
key_source=DDBLT_KEYSRC;
|
||||
}
|
||||
|
||||
|
||||
source_rectangle.left = source_x;
|
||||
source_rectangle.top = source_y;
|
||||
source_rectangle.right = source_x+width;
|
||||
source_rectangle.bottom = source_y+height;
|
||||
|
||||
dest_rectangle.left = dest_x;
|
||||
dest_rectangle.top = dest_y;
|
||||
dest_rectangle.right = dest_x+width;
|
||||
dest_rectangle.bottom = dest_y+height;
|
||||
|
||||
return ( dest.GraphicBuff->Get_DD_Surface()->Blt ( &dest_rectangle,
|
||||
GraphicBuff->Get_DD_Surface(),
|
||||
&source_rectangle,
|
||||
key_source | DDBLT_WAIT | DDBLT_ASYNC,
|
||||
NULL ) );
|
||||
Nearest_CopyImage((unsigned char*)GraphicBuff->GetMemoryBuffer(), source_x, source_y, GraphicBuff->Get_Width(), GraphicBuff->Get_Height(), (unsigned char *)dest.Get_Graphic_Buffer()->GetMemoryBuffer(), dest_x, dest_y, dest.Get_Graphic_Buffer()->Get_Width(), GraphicBuff->Get_Width(), GraphicBuff->Get_Height(), true);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user