-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #5
- Loading branch information
Showing
3 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,83 @@ | ||
#pragma once | ||
#include <cIGZUnknown.h> | ||
#include <cRZRect.h> | ||
|
||
static const uint32_t GZIID_cIGZBuffer = 0x20732180; | ||
|
||
class cIGZBufferHardwareCache; | ||
|
||
class cGZBufferColorType | ||
{ | ||
public: | ||
enum eColorType | ||
{ | ||
Null, | ||
AutoFromScreenFormat, | ||
Unknown_RGB8, | ||
AutoFromScreenFormat16, | ||
R5G5B5 = 4, | ||
R5G6B5 = 5, | ||
A1R5G5B5 = 6, | ||
A4R4G4B4 = 7, | ||
R8G8B8 = 8, | ||
A8R8G8B8 = 9, | ||
}; | ||
}; | ||
|
||
class cIGZBuffer : public cIGZUnknown | ||
{ | ||
// TODO | ||
public: | ||
enum eLockFlags { | ||
IsDirtyUpdate = 0x8000, | ||
}; | ||
|
||
public: | ||
virtual bool Init(uint32_t width, uint32_t height, cGZBufferColorType::eColorType bufferColorType, uint32_t colorDepthInBits) = 0; | ||
virtual bool Shutdown(void) = 0; | ||
virtual bool Uninitialize(void) = 0; | ||
|
||
virtual bool Lock(uint32_t lockFlags) = 0; | ||
virtual bool Unlock(uint32_t lockFlags) = 0; | ||
virtual bool IsLocked() const = 0; | ||
|
||
virtual uint32_t Width() const = 0; | ||
virtual uint32_t Height() const = 0; | ||
|
||
virtual uint32_t GetBufferArea() const = 0; | ||
virtual uint32_t GetBufferArea(cRZRect& rect) const = 0; | ||
virtual uint32_t GetMemoryUsage() const = 0; | ||
virtual cGZBufferColorType::eColorType GetColorType() const = 0; | ||
virtual uint8_t GetColorType(cGZBufferColorType::eColorType& bufferColorType) const = 0; | ||
virtual uint32_t GetBitsPerPixel() const = 0; | ||
virtual uint32_t GetBytesPerPixel() const = 0; | ||
|
||
virtual bool Fill(uint32_t color, cRZRect const& targetArea, cRZRect*) = 0; | ||
virtual bool Fill(uint32_t color, int32_t x, int32_t y, int32_t width, int32_t height, cRZRect*) = 0; | ||
virtual bool Fill(uint32_t color, cRZRect*) = 0; | ||
|
||
virtual uint32_t GetPixel(uint32_t x, uint32_t y) const = 0; | ||
virtual void SetPixel(uint32_t x, uint32_t y, uint32_t color) = 0; | ||
|
||
virtual void SetTransparency(uint32_t color) = 0; | ||
virtual uint32_t GetTransparency() const = 0; | ||
virtual bool IsPixelTransparent(uint32_t x, uint32_t y) = 0; | ||
virtual bool GetTransparentColor(uint32_t& color) const = 0; | ||
virtual void RemoveTransparency() = 0; | ||
|
||
virtual bool DrawLine(int32_t, int32_t, int32_t, int32_t, int32_t, uint32_t) = 0; | ||
virtual bool Blt(cIGZBuffer* srcBuffer, cRZRect const& srcRect, cRZRect const& targetRect, cRZRect const*) = 0; | ||
|
||
virtual uint32_t ConvertRGBValueToNative(uint8_t red, uint8_t green, uint8_t blue) = 0; | ||
virtual bool ConvertNativeValueToRGB(uint32_t color, uint8_t& red, uint8_t& green, uint8_t& blue) = 0; | ||
virtual uint32_t ConvertRGBAValueToNative(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) = 0; | ||
virtual bool ConvertNativeValueToRGBA(uint32_t color, uint8_t& red, uint8_t& green, uint8_t& blue, uint8_t& alpha) = 0; | ||
|
||
virtual uint32_t GetColorSurfaceBits() = 0; | ||
virtual uint32_t GetColorSurfaceStride() = 0; | ||
virtual uint32_t GetChangeCounter() = 0; | ||
|
||
virtual cIGZBufferHardwareCache* GetHardwareCache() = 0; | ||
virtual bool SetHardwareCache(cIGZBufferHardwareCache* cache) = 0; | ||
|
||
virtual bool IsReady() = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,89 @@ | ||
#include <cIGZCOM.h> | ||
#include <cRZCOMDllDirector.h> | ||
#include <cRZSysServPtr.h> | ||
#include "../cGDriver.h" | ||
|
||
extern cRZCOMSlimDllDirector* RZGetCOMDllDirector(); | ||
|
||
static const uint32_t GZCLSID_cGZBuffer = 0xC470D325; | ||
static const uint32_t GZIID_cIGZGraphicSystem = 0x73283c; | ||
static const uint32_t RZSRVID_GraphicSystem = 0xc416025c; | ||
|
||
class cIGZGraphicSystem : public cIGZUnknown | ||
{ | ||
public: | ||
virtual bool CreateBuffer(cIGZBuffer** ppvObj) = 0; | ||
// Don't need to declare the rest of the interface right now | ||
}; | ||
|
||
namespace nSCGL | ||
{ | ||
cIGZBuffer* cGDriver::CopyColorBuffer(int32_t, int32_t, int32_t, int32_t, cIGZBuffer*) { | ||
NOTIMPL(); | ||
return nullptr; | ||
static inline cIGZBuffer* CreateBufferFromGraphicsSystem() | ||
{ | ||
cRZSysServPtr<cIGZGraphicSystem, GZIID_cIGZGraphicSystem, RZSRVID_GraphicSystem> pGraphicsSystem; | ||
if ((cIGZGraphicSystem*)pGraphicsSystem == nullptr) { | ||
return nullptr; | ||
} | ||
|
||
cIGZBuffer* newBuffer = nullptr; | ||
if (!pGraphicsSystem->CreateBuffer(&newBuffer)) { | ||
return nullptr; | ||
} | ||
|
||
return newBuffer; | ||
} | ||
|
||
cIGZBuffer* cGDriver::CopyColorBuffer(int32_t x, int32_t y, int32_t width, int32_t height, cIGZBuffer* buffer) { | ||
int32_t startX = x; | ||
int32_t startY = y; | ||
int32_t endX = x + width; | ||
int32_t endY = y + height; | ||
|
||
if (startX < 0) { x = 0; } | ||
if (startY < 0) { y = 0; } | ||
if (endX > viewportWidth) { endX = viewportWidth; } | ||
if (endY > viewportHeight) { endY = viewportHeight; } | ||
|
||
uint8_t* colorBytes = nullptr; | ||
x = startX; | ||
y = startY; | ||
width = endX - startX; | ||
height = endY - startY; | ||
|
||
if (buffer == nullptr || !buffer->IsReady()) { | ||
buffer = CreateBufferFromGraphicsSystem(); | ||
if (buffer == nullptr) { | ||
return nullptr; | ||
} | ||
} | ||
else if (buffer->GetColorType() != cGZBufferColorType::A8R8G8B8) { | ||
return nullptr; | ||
} | ||
|
||
colorBytes = new uint8_t[3 * width * height]; | ||
if (colorBytes == nullptr) { | ||
return buffer; | ||
} | ||
|
||
glReadBuffer(GL_BACK); | ||
glPixelStorei(GL_PACK_ALIGNMENT, 1); | ||
glReadPixels(x, viewportHeight - startY - height, width, height, GL_RGB, GL_UNSIGNED_BYTE, colorBytes); | ||
|
||
uint8_t const* colorBytesCursor = colorBytes; | ||
if ((buffer->IsReady() || buffer->Init(width, height, cGZBufferColorType::A8R8G8B8, 32)) && buffer->Lock(cIGZBuffer::eLockFlags::IsDirtyUpdate)) { | ||
while (--height >= 0) { | ||
for (int i = 0; i < width; i++) { | ||
uint32_t color = 0xFF000000 | (colorBytesCursor[0] << 16) | (colorBytesCursor[1] << 8) | colorBytesCursor[2]; | ||
buffer->SetPixel(i, height, color); | ||
|
||
colorBytesCursor += 3; | ||
} | ||
} | ||
|
||
buffer->Unlock(cIGZBuffer::eLockFlags::IsDirtyUpdate); | ||
} | ||
|
||
delete[] colorBytes; | ||
return buffer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
class cRZRect | ||
{ | ||
public: | ||
union | ||
{ | ||
int32_t nX; | ||
float fX; | ||
}; | ||
|
||
union | ||
{ | ||
int32_t nY; | ||
float fY; | ||
}; | ||
|
||
union | ||
{ | ||
int32_t nWidth; | ||
float fWidth; | ||
}; | ||
|
||
union | ||
{ | ||
int32_t nHeight; | ||
float fHeight; | ||
}; | ||
}; |