mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-24 16:49:50 +00:00
Add support for 24/8 textures in the GE debugger.
This commit is contained in:
parent
bccb8dfb1e
commit
fee1ab98ba
@ -55,6 +55,8 @@ enum GPUDebugBufferFormat {
|
||||
GPU_DBG_FORMAT_FLOAT = 0x10,
|
||||
GPU_DBG_FORMAT_16BIT = 0x11,
|
||||
GPU_DBG_FORMAT_8BIT = 0x12,
|
||||
GPU_DBG_FORMAT_24BIT_8X = 0x13,
|
||||
GPU_DBG_FORMAT_24X_8BIT = 0x14,
|
||||
};
|
||||
|
||||
inline GPUDebugBufferFormat &operator |=(GPUDebugBufferFormat &lhs, const GPUDebugBufferFormat &rhs) {
|
||||
@ -137,11 +139,23 @@ struct GPUDebugBuffer {
|
||||
fmt_ = fmt;
|
||||
flipped_ = flipped;
|
||||
|
||||
u32 pixelSize = 2;
|
||||
if (fmt == GPU_DBG_FORMAT_8888 || fmt == GPU_DBG_FORMAT_8888_BGRA || fmt == GPU_DBG_FORMAT_FLOAT) {
|
||||
u32 pixelSize;
|
||||
switch (fmt) {
|
||||
case GPU_DBG_FORMAT_8888:
|
||||
case GPU_DBG_FORMAT_8888_BGRA:
|
||||
case GPU_DBG_FORMAT_FLOAT:
|
||||
case GPU_DBG_FORMAT_24BIT_8X:
|
||||
case GPU_DBG_FORMAT_24X_8BIT:
|
||||
pixelSize = 4;
|
||||
} else if (fmt == GPU_DBG_FORMAT_8BIT) {
|
||||
break;
|
||||
|
||||
case GPU_DBG_FORMAT_8BIT:
|
||||
pixelSize = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
pixelSize = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
data_ = new u8[pixelSize * stride * height];
|
||||
@ -154,7 +168,11 @@ struct GPUDebugBuffer {
|
||||
data_ = NULL;
|
||||
}
|
||||
|
||||
u8 *GetData() const {
|
||||
u8 *GetData() {
|
||||
return data_;
|
||||
}
|
||||
|
||||
const u8 *GetData() const {
|
||||
return data_;
|
||||
}
|
||||
|
||||
|
@ -67,19 +67,20 @@ static const char basic_vs[] =
|
||||
"}\n";
|
||||
|
||||
SimpleGLWindow::SimpleGLWindow(HWND wnd)
|
||||
: hWnd_(wnd), valid_(false), drawProgram_(NULL), tex_(0), flags_(0), zoom_(false),
|
||||
dragging_(false), offsetX_(0), offsetY_(0) {
|
||||
: hWnd_(wnd), valid_(false), drawProgram_(nullptr), tex_(0), flags_(0), zoom_(false),
|
||||
dragging_(false), offsetX_(0), offsetY_(0), reformatBuf_(nullptr) {
|
||||
SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG) this);
|
||||
}
|
||||
|
||||
SimpleGLWindow::~SimpleGLWindow() {
|
||||
if (drawProgram_ != NULL) {
|
||||
if (drawProgram_ != nullptr) {
|
||||
glsl_destroy(drawProgram_);
|
||||
}
|
||||
if (tex_) {
|
||||
glDeleteTextures(1, &tex_);
|
||||
glDeleteTextures(1, &checker_);
|
||||
}
|
||||
delete [] reformatBuf_;
|
||||
};
|
||||
|
||||
void SimpleGLWindow::Initialize(u32 flags) {
|
||||
@ -204,12 +205,13 @@ void SimpleGLWindow::DrawChecker() {
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||
}
|
||||
|
||||
void SimpleGLWindow::Draw(u8 *data, int w, int h, bool flipped, Format fmt) {
|
||||
void SimpleGLWindow::Draw(const u8 *data, int w, int h, bool flipped, Format fmt) {
|
||||
wglMakeCurrent(hDC_, hGLRC_);
|
||||
|
||||
GLint components = GL_RGBA;
|
||||
GLint memComponents = 0;
|
||||
GLenum glfmt;
|
||||
const u8 *finalData = data;
|
||||
if (fmt == FORMAT_8888) {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
glfmt = GL_UNSIGNED_BYTE;
|
||||
@ -220,6 +222,15 @@ void SimpleGLWindow::Draw(u8 *data, int w, int h, bool flipped, Format fmt) {
|
||||
} else if (fmt == FORMAT_FLOAT) {
|
||||
glfmt = GL_FLOAT;
|
||||
components = GL_RED;
|
||||
} else if (fmt == FORMAT_24BIT_8X) {
|
||||
glfmt = GL_UNSIGNED_INT;
|
||||
components = GL_RED;
|
||||
finalData = Reformat(data, fmt, w * h);
|
||||
} else if (fmt == FORMAT_24X_8BIT) {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glfmt = GL_UNSIGNED_BYTE;
|
||||
components = GL_RED;
|
||||
finalData = Reformat(data, fmt, w * h);
|
||||
} else {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
|
||||
if (fmt == FORMAT_4444) {
|
||||
@ -259,7 +270,7 @@ void SimpleGLWindow::Draw(u8 *data, int w, int h, bool flipped, Format fmt) {
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, tex_);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, components, w, h, 0, memComponents, glfmt, data);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, components, w, h, 0, memComponents, glfmt, finalData);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
@ -423,6 +434,28 @@ bool SimpleGLWindow::ToggleZoom() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const u8 *SimpleGLWindow::Reformat(const u8 *data, Format fmt, u32 numPixels) {
|
||||
if (!reformatBuf_ || reformatBufSize_ < numPixels) {
|
||||
delete [] reformatBuf_;
|
||||
reformatBuf_ = new u32[numPixels];
|
||||
reformatBufSize_ = numPixels;
|
||||
}
|
||||
|
||||
const u32 *data32 = (const u32 *)data;
|
||||
if (fmt == FORMAT_24BIT_8X) {
|
||||
for (u32 i = 0; i < numPixels; ++i) {
|
||||
reformatBuf_[i] = (data32[i] << 8) | ((data32[i] >> 16) & 0xFF);
|
||||
}
|
||||
} else if (fmt == FORMAT_24X_8BIT) {
|
||||
u8 *buf8 = (u8 *)reformatBuf_;
|
||||
for (u32 i = 0; i < numPixels; ++i) {
|
||||
u32 v = (data32[i] >> 24) & 0xFF;
|
||||
buf8[i] = v;
|
||||
}
|
||||
}
|
||||
return (const u8 *)reformatBuf_;
|
||||
}
|
||||
|
||||
SimpleGLWindow *SimpleGLWindow::GetFrom(HWND hwnd) {
|
||||
return (SimpleGLWindow*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ struct SimpleGLWindow {
|
||||
FORMAT_FLOAT = 0x10,
|
||||
FORMAT_16BIT = 0x11,
|
||||
FORMAT_8BIT = 0x12,
|
||||
FORMAT_24BIT_8X = 0x13,
|
||||
FORMAT_24X_8BIT = 0x14,
|
||||
};
|
||||
|
||||
enum Flags {
|
||||
@ -54,7 +56,7 @@ struct SimpleGLWindow {
|
||||
~SimpleGLWindow();
|
||||
|
||||
void Clear();
|
||||
void Draw(u8 *data, int w, int h, bool flipped = false, Format = FORMAT_8888);
|
||||
void Draw(const u8 *data, int w, int h, bool flipped = false, Format = FORMAT_8888);
|
||||
void Redraw(bool andSwap = true);
|
||||
void Initialize(u32 flags);
|
||||
static SimpleGLWindow *GetFrom(HWND hwnd);
|
||||
@ -101,6 +103,7 @@ protected:
|
||||
bool DragContinue(int mouseX, int mouseY);
|
||||
bool DragEnd(int mouseX, int mouseY);
|
||||
bool ToggleZoom();
|
||||
const u8 *Reformat(const u8 *data, Format fmt, u32 numPixels);
|
||||
|
||||
HWND hWnd_;
|
||||
HDC hDC_;
|
||||
@ -127,4 +130,6 @@ protected:
|
||||
// Offset to position the texture is drawn at.
|
||||
int offsetX_;
|
||||
int offsetY_;
|
||||
u32 *reformatBuf_;
|
||||
u32 reformatBufSize_;
|
||||
};
|
Loading…
Reference in New Issue
Block a user