diff --git a/Core/GameEngine/Source/GameClient/MapUtil.cpp b/Core/GameEngine/Source/GameClient/MapUtil.cpp index 1aab4551571..1a12c47e344 100644 --- a/Core/GameEngine/Source/GameClient/MapUtil.cpp +++ b/Core/GameEngine/Source/GameClient/MapUtil.cpp @@ -1290,12 +1290,15 @@ Bool parseMapPreviewChunk(DataChunkInput &file, DataChunkInfo *info, void *userD //texture->Get_Surface_Level(); DEBUG_LOG(("BeginMapPreviewInfo")); + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); UnsignedInt *buffer = new UnsignedInt[size.x * size.y]; Int x,y; for (y=0; yDrawPixel( x, y, file.readInt() ); + surface->Draw_Pixel( x, y, file.readInt(), bytesPerPixel, pBits, pitch ); buffer[y + x] = file.readInt(); DEBUG_LOG(("x:%d, y:%d, %X", x, y, buffer[y + x])); } @@ -1303,6 +1306,7 @@ Bool parseMapPreviewChunk(DataChunkInput &file, DataChunkInfo *info, void *userD mapPreviewImage->setRawTextureData(buffer); DEBUG_ASSERTCRASH(file.atEndOfChunk(), ("Unexpected data left over.")); DEBUG_LOG(("EndMapPreviewInfo")); + surface->Unlock(); REF_PTR_RELEASE(surface); return true; */ diff --git a/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp index 4deeb1db6ca..f62d68654a3 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp @@ -168,8 +168,8 @@ void W3DRadar::deleteResources( void ) deleteInstance(m_shroudImage); m_shroudImage = nullptr; - DEBUG_ASSERTCRASH(m_shroudSurface == NULL, ("W3DRadar::deleteResources: m_shroudSurface is expected NULL")); - DEBUG_ASSERTCRASH(m_shroudSurfaceBits == NULL, ("W3DRadar::deleteResources: m_shroudSurfaceBits is expected NULL")); + DEBUG_ASSERTCRASH(m_shroudSurface == nullptr, ("W3DRadar::deleteResources: m_shroudSurface is expected null")); + DEBUG_ASSERTCRASH(m_shroudSurfaceBits == nullptr, ("W3DRadar::deleteResources: m_shroudSurfaceBits is expected null")); } @@ -697,6 +697,10 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text Player *player = rts::getObservedOrLocalPlayer(); + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); + for( const RadarObject *rObj = listHead; rObj; rObj = rObj->friend_getNext() ) { if (!canRenderObject(rObj, player)) @@ -736,21 +740,23 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text // draw the blip, but make sure the points are legal if( legalRadarPoint( radarPoint.x, radarPoint.y ) ) - surface->DrawPixel( radarPoint.x, radarPoint.y, c ); + surface->Draw_Pixel( radarPoint.x, radarPoint.y, c, bytesPerPixel, pBits, pitch ); radarPoint.y++; if( legalRadarPoint( radarPoint.x, radarPoint.y ) ) - surface->DrawPixel( radarPoint.x, radarPoint.y, c ); + surface->Draw_Pixel( radarPoint.x, radarPoint.y, c, bytesPerPixel, pBits, pitch ); radarPoint.x++; if( legalRadarPoint( radarPoint.x, radarPoint.y ) ) - surface->DrawPixel( radarPoint.x, radarPoint.y, c ); + surface->Draw_Pixel( radarPoint.x, radarPoint.y, c, bytesPerPixel, pBits, pitch ); radarPoint.y--; if( legalRadarPoint( radarPoint.x, radarPoint.y ) ) - surface->DrawPixel( radarPoint.x, radarPoint.y, c ); + surface->Draw_Pixel( radarPoint.x, radarPoint.y, c, bytesPerPixel, pBits, pitch ); } + + surface->Unlock(); REF_PTR_RELEASE(surface); } @@ -1068,6 +1074,11 @@ void W3DRadar::buildTerrainTexture( TerrainLogic *terrain ) ICoord2D radarPoint; Coord3D worldPoint; Bridge *bridge; + + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); + for( y = 0; y < m_textureHeight; y++ ) { @@ -1253,25 +1264,17 @@ void W3DRadar::buildTerrainTexture( TerrainLogic *terrain ) } - // // draw the pixel for the terrain at this point, note that because of the orientation // of our world we draw it with positive y in the "up" direction - // - // FYI: I tried making this faster by pulling out all the code inside DrawPixel - // and locking only once ... but it made absolutely *no* performance difference, - // the sampling and interpolation algorithm for generating pretty looking terrain - // and water for the radar is just, well, expensive. - // - surface->DrawPixel( x, y, GameMakeColor( color.red * 255, - color.green * 255, - color.blue * 255, - 255 ) ); + Color pixelColor = GameMakeColor( color.red * 255, color.green * 255, color.blue * 255, 255 ); + surface->Draw_Pixel( x, y, pixelColor, bytesPerPixel, pBits, pitch ); } } // all done with the surface + surface->Unlock(); REF_PTR_RELEASE(surface); } @@ -1288,11 +1291,18 @@ void W3DRadar::clearShroud() SurfaceClass *surface = m_shroudTexture->Get_Surface_Level(); // fill to clear, shroud will make black. Don't want to make something black that logic can't clear - unsigned int color = GameMakeColor( 0, 0, 0, 0 ); + + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); + const Color color = GameMakeColor( 0, 0, 0, 0 ); + for( Int y = 0; y < m_textureHeight; y++ ) { - surface->DrawHLine(y, 0, m_textureWidth-1, color); + surface->Draw_H_Line(y, 0, m_textureWidth-1, color, bytesPerPixel, pBits, pitch); } + + surface->Unlock(); REF_PTR_RELEASE(surface); } @@ -1346,41 +1356,39 @@ void W3DRadar::setShroudLevel(Int shroudX, Int shroudY, CellShroudStatus setting else alpha = 0; - if (m_shroudSurface == NULL) + if (m_shroudSurface == nullptr) { // This is expensive. SurfaceClass* surface = m_shroudTexture->Get_Surface_Level(); DEBUG_ASSERTCRASH( surface, ("W3DRadar: Can't get surface for Shroud texture") ); + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); + const Color color = GameMakeColor( 0, 0, 0, alpha ); - for( Int y = radarMinY; y <= radarMaxY; y++ ) + for( Int y = radarMinY; y <= radarMaxY; ++y ) { - for( Int x = radarMinX; x <= radarMaxX; x++ ) + for( Int x = radarMinX; x <= radarMaxX; ++x ) { - surface->DrawPixel( x, y, GameMakeColor( 0, 0, 0, alpha ) ); + surface->Draw_Pixel( x, y, color, bytesPerPixel, pBits, pitch ); } } + + surface->Unlock(); REF_PTR_RELEASE(surface); } else { // This is cheap. - DEBUG_ASSERTCRASH(m_shroudSurfaceBits != NULL, ("W3DRadar::setShroudLevel: m_shroudSurfaceBits is not expected NULL")); + DEBUG_ASSERTCRASH(m_shroudSurfaceBits != nullptr, ("W3DRadar::setShroudLevel: m_shroudSurfaceBits is not expected null")); DEBUG_ASSERTCRASH(m_shroudSurfacePixelSize != 0, ("W3DRadar::setShroudLevel: m_shroudSurfacePixelSize is not expected 0")); const Color color = GameMakeColor( 0, 0, 0, alpha ); for( Int y = radarMinY; y <= radarMaxY; ++y ) { - UnsignedByte* row = static_cast(m_shroudSurfaceBits) + y * m_shroudSurfacePitch; for( Int x = radarMinX; x <= radarMaxX; ++x ) { - UnsignedByte* column = row + x * m_shroudSurfacePixelSize; - - switch (m_shroudSurfacePixelSize) - { - case 1: *column = (UnsignedByte)(color & 0xFF); break; - case 2: *reinterpret_cast(column) = (UnsignedShort)(color & 0xFFFF); break; - case 4: *reinterpret_cast(column) = (UnsignedInt)color; break; - } + m_shroudSurface->Draw_Pixel( x, y, color, m_shroudSurfacePixelSize, m_shroudSurfaceBits, m_shroudSurfacePitch ); } } } @@ -1388,9 +1396,9 @@ void W3DRadar::setShroudLevel(Int shroudX, Int shroudY, CellShroudStatus setting void W3DRadar::beginSetShroudLevel() { - DEBUG_ASSERTCRASH( m_shroudSurface == NULL, ("W3DRadar::beginSetShroudLevel: m_shroudSurface is expected NULL") ); + DEBUG_ASSERTCRASH( m_shroudSurface == nullptr, ("W3DRadar::beginSetShroudLevel: m_shroudSurface is expected null") ); m_shroudSurface = m_shroudTexture->Get_Surface_Level(); - DEBUG_ASSERTCRASH( m_shroudSurface != NULL, ("W3DRadar::beginSetShroudLevel: Can't get surface for Shroud texture") ); + DEBUG_ASSERTCRASH( m_shroudSurface != nullptr, ("W3DRadar::beginSetShroudLevel: Can't get surface for Shroud texture") ); SurfaceClass::SurfaceDescription sd; m_shroudSurface->Get_Description(sd); @@ -1400,11 +1408,11 @@ void W3DRadar::beginSetShroudLevel() void W3DRadar::endSetShroudLevel() { - DEBUG_ASSERTCRASH( m_shroudSurface != NULL, ("W3DRadar::endSetShroudLevel: m_shroudSurface is not expected NULL") ); - if (m_shroudSurfaceBits != NULL) + DEBUG_ASSERTCRASH( m_shroudSurface != nullptr, ("W3DRadar::endSetShroudLevel: m_shroudSurface is not expected null") ); + if (m_shroudSurfaceBits != nullptr) { m_shroudSurface->Unlock(); - m_shroudSurfaceBits = NULL; + m_shroudSurfaceBits = nullptr; m_shroudSurfacePitch = 0; m_shroudSurfacePixelSize = 0; } @@ -1555,6 +1563,10 @@ void W3DRadar::refreshObjects() UnsignedByte minAlpha = 8; + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); + for( const RadarObject *rObj = listHead; rObj; rObj = rObj->friend_getNext() ) { UnsignedByte h = (UnsignedByte)(rObj->isTemporarilyHidden()); @@ -1639,24 +1651,26 @@ void W3DRadar::refreshObjects() // draw the blip, but make sure the points are legal if( legalRadarPoint( radarPoint.x, radarPoint.y ) ) - surface->DrawPixel( radarPoint.x, radarPoint.y, c ); + surface->Draw_Pixel( radarPoint.x, radarPoint.y, c, bytesPerPixel, pBits, pitch ); radarPoint.x++; if( legalRadarPoint( radarPoint.x, radarPoint.y ) ) - surface->DrawPixel( radarPoint.x, radarPoint.y, c ); + surface->Draw_Pixel( radarPoint.x, radarPoint.y, c, bytesPerPixel, pBits, pitch ); radarPoint.y++; if( legalRadarPoint( radarPoint.x, radarPoint.y ) ) - surface->DrawPixel( radarPoint.x, radarPoint.y, c ); + surface->Draw_Pixel( radarPoint.x, radarPoint.y, c, bytesPerPixel, pBits, pitch ); radarPoint.x--; if( legalRadarPoint( radarPoint.x, radarPoint.y ) ) - surface->DrawPixel( radarPoint.x, radarPoint.y, c ); + surface->Draw_Pixel( radarPoint.x, radarPoint.y, c, bytesPerPixel, pBits, pitch ); } + + surface->Unlock(); REF_PTR_RELEASE(surface); } diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp index 31a11d23f43..f28f8a9fb96 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp @@ -965,7 +965,11 @@ void WaterRenderObjClass::ReAcquireResources(void) if (m_whiteTexture && !m_whiteTexture->Is_Initialized()) { m_whiteTexture->Init(); SurfaceClass *surface=m_whiteTexture->Get_Surface_Level(); - surface->DrawPixel(0,0,0xffffffff); + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); + surface->Draw_Pixel(0, 0, 0xffffffff, bytesPerPixel, pBits, pitch); + surface->Unlock(); REF_PTR_RELEASE(surface); } } @@ -1111,7 +1115,11 @@ Int WaterRenderObjClass::init(Real waterLevel, Real dx, Real dy, SceneClass *par //For some reason setting a null texture does not result in 0xffffffff for pixel shaders so using explicit "white" texture. m_whiteTexture=MSGNEW("TextureClass") TextureClass(1,1,WW3D_FORMAT_A4R4G4B4,MIP_LEVELS_1); SurfaceClass *surface=m_whiteTexture->Get_Surface_Level(); - surface->DrawPixel(0,0,0xffffffff); + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); + surface->Draw_Pixel(0, 0, 0xffffffff, bytesPerPixel, pBits, pitch); + surface->Unlock(); REF_PTR_RELEASE(surface); m_waterNoiseTexture=WW3DAssetManager::Get_Instance()->Get_Texture("Noise0000.tga"); @@ -2961,7 +2969,11 @@ void WaterRenderObjClass::setupFlatWaterShader(void) if (!m_whiteTexture->Is_Initialized()) { m_whiteTexture->Init(); SurfaceClass *surface=m_whiteTexture->Get_Surface_Level(); - surface->DrawPixel(0,0,0xffffffff); + int pitch; + void *pBits = surface->Lock(&pitch); + const unsigned int bytesPerPixel = surface->Get_Bytes_Per_Pixel(); + surface->Draw_Pixel(0, 0, 0xffffffff, bytesPerPixel, pBits, pitch); + surface->Unlock(); REF_PTR_RELEASE(surface); } DX8Wrapper::_Get_D3D_Device8()->SetTexture(3,m_whiteTexture->Peek_D3D_Texture()); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp b/Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp index 1c768fec1b9..140c2cd0f65 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp @@ -205,16 +205,23 @@ void SurfaceClass::Get_Description(SurfaceDescription &surface_desc) surface_desc.Width = d3d_desc.Width; } -void *SurfaceClass::Lock(int *pitch) +unsigned int SurfaceClass::Get_Bytes_Per_Pixel() +{ + SurfaceDescription surfaceDesc; + Get_Description(surfaceDesc); + return ::Get_Bytes_Per_Pixel(surfaceDesc.Format); +} + +SurfaceClass::LockedSurfacePtr SurfaceClass::Lock(int *pitch) { D3DLOCKED_RECT lock_rect; ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); DX8_ErrorCode(D3DSurface->LockRect(&lock_rect, nullptr, 0)); *pitch = lock_rect.Pitch; - return (void *)lock_rect.pBits; + return static_cast(lock_rect.pBits); } -void *SurfaceClass::Lock(int *pitch, const Vector2i &min, const Vector2i &max) +SurfaceClass::LockedSurfacePtr SurfaceClass::Lock(int *pitch, const Vector2i &min, const Vector2i &max) { D3DLOCKED_RECT lock_rect; ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); @@ -227,7 +234,7 @@ void *SurfaceClass::Lock(int *pitch, const Vector2i &min, const Vector2i &max) DX8_ErrorCode(D3DSurface->LockRect(&lock_rect, &rect, 0)); *pitch = lock_rect.Pitch; - return (void *)lock_rect.pBits; + return static_cast(lock_rect.pBits); } void SurfaceClass::Unlock(void) @@ -256,7 +263,7 @@ void SurfaceClass::Clear() Get_Description(sd); // size of each pixel in bytes - unsigned int size=Get_Bytes_Per_Pixel(sd.Format); + unsigned int size=::Get_Bytes_Per_Pixel(sd.Format); D3DLOCKED_RECT lock_rect; ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); @@ -295,7 +302,7 @@ void SurfaceClass::Copy(const unsigned char *other) Get_Description(sd); // size of each pixel in bytes - unsigned int size=Get_Bytes_Per_Pixel(sd.Format); + unsigned int size=::Get_Bytes_Per_Pixel(sd.Format); D3DLOCKED_RECT lock_rect; ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); @@ -334,7 +341,7 @@ void SurfaceClass::Copy(const Vector2i &min, const Vector2i &max, const unsigned Get_Description(sd); // size of each pixel in bytes - unsigned int size=Get_Bytes_Per_Pixel(sd.Format); + unsigned int size=::Get_Bytes_Per_Pixel(sd.Format); D3DLOCKED_RECT lock_rect; ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); @@ -379,7 +386,7 @@ unsigned char *SurfaceClass::CreateCopy(int *width,int *height,int*size,bool fli Get_Description(sd); // size of each pixel in bytes - unsigned int mysize=Get_Bytes_Per_Pixel(sd.Format); + unsigned int mysize=::Get_Bytes_Per_Pixel(sd.Format); *width=sd.Width; *height=sd.Height; @@ -559,7 +566,7 @@ void SurfaceClass::FindBB(Vector2i *min,Vector2i*max) DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,&rect,D3DLOCK_READONLY)); int x,y; - unsigned int size=Get_Bytes_Per_Pixel(sd.Format); + unsigned int size=::Get_Bytes_Per_Pixel(sd.Format); Vector2i realmin=*max; Vector2i realmax=*min; @@ -622,7 +629,7 @@ bool SurfaceClass::Is_Transparent_Column(unsigned int column) break; } - unsigned int size=Get_Bytes_Per_Pixel(sd.Format); + unsigned int size=::Get_Bytes_Per_Pixel(sd.Format); D3DLOCKED_RECT lock_rect; ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); @@ -656,7 +663,7 @@ bool SurfaceClass::Is_Transparent_Column(unsigned int column) } /*********************************************************************************************** - * SurfaceClass::Get_Pixel -- Returns the pixel's RGB valus to the caller * + * SurfaceClass::Get_Pixel -- Returns the pixel's RGB valus to the caller * * * * * * * @@ -669,28 +676,16 @@ bool SurfaceClass::Is_Transparent_Column(unsigned int column) * * * HISTORY: * * 2/13/2001 hy : Created. * + * 1/10/2025 TheSuperHackers : Added bits and pitch to argument list for better performance * *=============================================================================================*/ -void SurfaceClass::Get_Pixel(Vector3 &rgb, int x,int y) +void SurfaceClass::Get_Pixel(Vector3 &rgb, int x, int y, LockedSurfacePtr pBits, int pitch) { SurfaceDescription sd; Get_Description(sd); - x = min(x,(int)sd.Width - 1); - y = min(y,(int)sd.Height - 1); - - D3DLOCKED_RECT lock_rect; - ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); - RECT rect; - ::ZeroMemory(&rect, sizeof(RECT)); - - rect.bottom=y+1; - rect.top=y; - rect.left=x; - rect.right=x+1; - - DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,&rect,D3DLOCK_READONLY)); - Convert_Pixel(rgb,sd,(unsigned char *) lock_rect.pBits); - DX8_ErrorCode(D3DSurface->UnlockRect()); + unsigned int bytesPerPixel = ::Get_Bytes_Per_Pixel(sd.Format); + unsigned char* dst = static_cast(pBits) + y * pitch + x * bytesPerPixel; + Convert_Pixel(rgb,sd,dst); } /*********************************************************************************************** @@ -766,44 +761,16 @@ void SurfaceClass::Detach (void) * WARNINGS: * * * * HISTORY: * + * 1/10/2025 TheSuperHackers : Added bits and pitch to argument list for better performance * *=============================================================================================*/ -void SurfaceClass::DrawPixel(const unsigned int x,const unsigned int y, unsigned int color) +void SurfaceClass::Draw_Pixel(const unsigned int x, const unsigned int y, unsigned int color, + unsigned int bytesPerPixel, LockedSurfacePtr pBits, int pitch) { - SurfaceDescription sd; - Get_Description(sd); - - unsigned int size=Get_Bytes_Per_Pixel(sd.Format); - - D3DLOCKED_RECT lock_rect; - ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); - RECT rect; - ::ZeroMemory(&rect, sizeof(RECT)); - - rect.bottom=y+1; - rect.top=y; - rect.left=x; - rect.right=x+1; - - DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,&rect,0)); - unsigned char *cptr=(unsigned char*)lock_rect.pBits; - unsigned short *sptr=(unsigned short*)lock_rect.pBits; - unsigned int *lptr=(unsigned int*)lock_rect.pBits; + unsigned char* dst = static_cast(pBits) + y * pitch + x * bytesPerPixel; + memcpy(dst, &color, bytesPerPixel); +} - switch (size) - { - case 1: - *cptr=(unsigned char) (color & 0xFF); - break; - case 2: - *sptr=(unsigned short) (color & 0xFFFF); - break; - case 4: - *lptr=color; - break; - } - DX8_ErrorCode(D3DSurface->UnlockRect()); -} /*********************************************************************************************** * SurfaceClass::DrawHLine -- draws a horizontal line * @@ -819,49 +786,18 @@ void SurfaceClass::DrawPixel(const unsigned int x,const unsigned int y, unsigned * * * HISTORY: * * 4/9/2001 hy : Created. * - * 4/9/2001 hy : Created. * + * 1/10/2025 TheSuperHackers : Added bits and pitch to argument list for better performance * *=============================================================================================*/ -void SurfaceClass::DrawHLine(const unsigned int y,const unsigned int x1, const unsigned int x2, unsigned int color) +void SurfaceClass::Draw_H_Line(const unsigned int y, const unsigned int x1, const unsigned int x2, + unsigned int color, unsigned int bytesPerPixel, LockedSurfacePtr pBits, int pitch) { - SurfaceDescription sd; - Get_Description(sd); - - unsigned int size=Get_Bytes_Per_Pixel(sd.Format); - - D3DLOCKED_RECT lock_rect; - ::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT)); - RECT rect; - ::ZeroMemory(&rect, sizeof(RECT)); - - rect.bottom=y+1; - rect.top=y; - rect.left=x1; - rect.right=x2+1; - - DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,&rect,0)); - unsigned char *cptr=(unsigned char*)lock_rect.pBits; - unsigned short *sptr=(unsigned short*)lock_rect.pBits; - unsigned int *lptr=(unsigned int*)lock_rect.pBits; + unsigned char* row = static_cast(pBits) + y * pitch; - unsigned int x; - // the assumption here is that whenever a pixel has alpha it's in the MSB - for (x=x1; x<=x2; x++) + for (unsigned int x = x1; x <= x2; ++x) { - switch (size) - { - case 1: - *cptr++=(unsigned char) (color & 0xFF); - break; - case 2: - *sptr++=(unsigned short) (color & 0xFFFF); - break; - case 4: - *lptr++=color; - break; - } + unsigned char* dst = row + x * bytesPerPixel; + memcpy(dst, &color, bytesPerPixel); } - - DX8_ErrorCode(D3DSurface->UnlockRect()); } @@ -927,7 +863,7 @@ bool SurfaceClass::Is_Monochrome(void) int pitch,size; - size=Get_Bytes_Per_Pixel(sd.Format); + size=::Get_Bytes_Per_Pixel(sd.Format); unsigned char *bits=(unsigned char*) Lock(&pitch); Vector3 rgb; @@ -977,7 +913,7 @@ void SurfaceClass::Hue_Shift(const Vector3 &hsv_shift) Get_Description(sd); int pitch,size; - size=Get_Bytes_Per_Pixel(sd.Format); + size=::Get_Bytes_Per_Pixel(sd.Format); unsigned char *bits=(unsigned char*) Lock(&pitch); Vector3 rgb; diff --git a/Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.h b/Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.h index 4d227fe4fcf..fb1f5a12af7 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.h +++ b/Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.h @@ -57,6 +57,7 @@ class SurfaceClass : public W3DMPO, public RefCountClass { W3DMPO_GLUE(SurfaceClass) public: + typedef void *LockedSurfacePtr; struct SurfaceDescription { WW3DFormat Format; // Surface format @@ -76,11 +77,14 @@ class SurfaceClass : public W3DMPO, public RefCountClass ~SurfaceClass(void); // Get surface description - void Get_Description(SurfaceDescription &surface_desc); + void Get_Description(SurfaceDescription &surface_desc); + + // Get the bytes per pixel count + unsigned int Get_Bytes_Per_Pixel(); // Lock / unlock the surface - void *Lock(int *pitch); - void *Lock(int *pitch, const Vector2i &min, const Vector2i &max); + LockedSurfacePtr Lock(int *pitch); + LockedSurfacePtr Lock(int *pitch, const Vector2i &min, const Vector2i &max); void Unlock(void); // HY -- The following functions are support functions for font3d @@ -102,7 +106,7 @@ class SurfaceClass : public W3DMPO, public RefCountClass // copies the contents of one surface to another, stretches void Stretch_Copy( - unsigned int dstx, unsigned int dsty,unsigned int dstwidth, unsigned int dstheight, + unsigned int dstx, unsigned int dsty, unsigned int dstwidth, unsigned int dstheight, unsigned int srcx, unsigned int srcy, unsigned int srcwidth, unsigned int srcheight, const SurfaceClass *source); @@ -123,12 +127,15 @@ class SurfaceClass : public W3DMPO, public RefCountClass void Detach (void); // draws a horizontal line - void DrawHLine(const unsigned int y,const unsigned int x1, const unsigned int x2, unsigned int color); + void Draw_H_Line(const unsigned int y, const unsigned int x1, const unsigned int x2, + unsigned int color, unsigned int bytesPerPixel, LockedSurfacePtr pBits, int pitch); - void DrawPixel(const unsigned int x,const unsigned int y, unsigned int color); + // draws a pixel + void Draw_Pixel(const unsigned int x, const unsigned int y, unsigned int color, + unsigned int bytesPerPixel, LockedSurfacePtr pBits, int pitch); - // get pixel function .. to be used infrequently - void Get_Pixel(Vector3 &rgb, int x,int y); + // get pixel function + void Get_Pixel(Vector3 &rgb, int x, int y, LockedSurfacePtr pBits, int pitch); void Hue_Shift(const Vector3 &hsv_shift);