Support flipped and not flipped buffers.

This commit is contained in:
Unknown W. Brackets committed 2013-09-22 22:37:37 -07:00
1 parent 47b43e997f
commit 6a313ac204
5 files changed
+20 -9

No files matched your search

+12 -2
View File
@@ -35,7 +35,7 @@ struct GPUDebugBuffer {
}
GPUDebugBuffer(void *data, u32 stride, u32 height, GEBufferFormat fmt)
: alloc_(false), data_((u8 *)data), stride_(stride), height_(height), fmt_(fmt) {
: alloc_(false), data_((u8 *)data), stride_(stride), height_(height), fmt_(fmt), flipped_(false) {
}
GPUDebugBuffer(GPUDebugBuffer &&other) {
@@ -43,6 +43,7 @@ struct GPUDebugBuffer {
data_ = other.data_;
height_ = other.height_;
stride_ = other.stride_;
flipped_ = other.flipped_;
fmt_ = other.fmt_;
other.alloc_ = false;
other.data_ = NULL;
@@ -59,6 +60,7 @@ struct GPUDebugBuffer {
data_ = other.data_;
height_ = other.height_;
stride_ = other.stride_;
flipped_ = other.flipped_;
fmt_ = other.fmt_;
other.alloc_ = false;
other.data_ = NULL;
@@ -67,9 +69,10 @@ struct GPUDebugBuffer {
return *this;
}
void Allocate(u32 stride, u32 height, GEBufferFormat fmt) {
void Allocate(u32 stride, u32 height, GEBufferFormat fmt, bool flipped = false) {
if (alloc_ && stride_ == stride && height_ == height && fmt_ == fmt) {
// Already allocated the right size.
flipped_ = flipped;
return;
}
@@ -78,6 +81,7 @@ struct GPUDebugBuffer {
height_ = height;
stride_ = stride;
fmt_ = fmt;
flipped_ = flipped;
u32 pixelSize = 2;
if (fmt == GE_FORMAT_8888) {
@@ -106,14 +110,20 @@ struct GPUDebugBuffer {
return stride_;
}
bool GetFlipped() const {
return flipped_;
}
GEBufferFormat GetFormat() const {
return fmt_;
}
private:
bool alloc_;
u8 *data_;
u32 height_;
u32 stride_;
bool flipped_;
GEBufferFormat fmt_;
};
+1 -1
View File
@@ -1340,7 +1340,7 @@ bool FramebufferManager::GetCurrentFramebuffer(GPUDebugBuffer &buffer)
return true;
}
buffer.Allocate(vfb->renderWidth, vfb->renderHeight, GE_FORMAT_8888);
buffer.Allocate(vfb->renderWidth, vfb->renderHeight, GE_FORMAT_8888, true);
fbo_bind_for_read(vfb->fbo);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
+1 -1
View File
@@ -147,7 +147,7 @@ BOOL CGEDebugger::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
if (bufferResult) {
auto fmt = SimpleGLWindow::Format(buffer.GetFormat());
frameWindow->Draw(buffer.GetData(), buffer.GetStride(), buffer.GetHeight(), fmt, SimpleGLWindow::RESIZE_SHRINK_CENTER);
frameWindow->Draw(buffer.GetData(), buffer.GetStride(), buffer.GetHeight(), buffer.GetFlipped(), fmt, SimpleGLWindow::RESIZE_SHRINK_CENTER);
} else {
ERROR_LOG(COMMON, "Unable to get buffer.");
}
+5 -4
View File
@@ -205,7 +205,7 @@ void SimpleGLWindow::DrawChecker() {
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
}
void SimpleGLWindow::Draw(u8 *data, int w, int h, Format fmt, ResizeType resize) {
void SimpleGLWindow::Draw(u8 *data, int w, int h, bool flipped, Format fmt, ResizeType resize) {
DrawChecker();
glDisable(GL_BLEND);
@@ -258,14 +258,15 @@ void SimpleGLWindow::Draw(u8 *data, int w, int h, Format fmt, ResizeType resize)
}
}
const float pos[12] = {x,y,0, x+fw,y,0, x+fw,y+fh,0, x,y+fh,0};
const float texCoords[8] = {0,1, 1,1, 1,0, 0,0};
const GLubyte indices[4] = {0,1,3,2};
static const float texCoords[8] = {0,0, 1,0, 1,1, 0,1};
static const float texCoordsFlipped[8] = {0,1, 1,1, 1,0, 0,0};
static const GLubyte indices[4] = {0,1,3,2};
Matrix4x4 ortho;
ortho.setOrtho(0, (float)w_, (float)h_, 0, -1, 1);
glUniformMatrix4fv(drawProgram_->u_viewproj, 1, GL_FALSE, ortho.getReadPtr());
glVertexAttribPointer(drawProgram_->a_position, 3, GL_FLOAT, GL_FALSE, 12, pos);
glVertexAttribPointer(drawProgram_->a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, texCoords);
glVertexAttribPointer(drawProgram_->a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, flipped ? texCoordsFlipped : texCoords);
glActiveTexture(GL_TEXTURE0);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
+1 -1
View File
@@ -41,7 +41,7 @@ struct SimpleGLWindow {
~SimpleGLWindow();
void Clear();
void Draw(u8 *data, int w, int h, Format = FORMAT_8888, ResizeType resize = RESIZE_NONE);
void Draw(u8 *data, int w, int h, bool flipped = false, Format = FORMAT_8888, ResizeType resize = RESIZE_NONE);
void Swap() {
SwapBuffers(hDC_);