gsdx-ogl: LINUX-ONLY

* invert the index of fragment output. Seem to work better on Nvidia (strangely no impact for AMD)
* opengl support pitch too, so remove useless copy to an fbo


git-svn-id: http://pcsx2.googlecode.com/svn/branches/gsdx-ogl@5034 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2011-12-30 22:25:17 +00:00
parent ea33beb360
commit 9ca65c9cc6
6 changed files with 33 additions and 54 deletions

View File

@ -18,6 +18,7 @@ set(CommonFlags
-Wunused-variable -Wunused-variable
-std=c++0x -std=c++0x
-fno-strict-aliasing -fno-strict-aliasing
-DOGL_DEBUG
) )
set(OptimizationFlags set(OptimizationFlags
@ -28,7 +29,7 @@ set(OptimizationFlags
# Debug - Build # Debug - Build
if(CMAKE_BUILD_TYPE STREQUAL Debug) if(CMAKE_BUILD_TYPE STREQUAL Debug)
# add defines # add defines
add_definitions(${CommonFlags} -g -Wall) add_definitions(${CommonFlags} -DOGL_DEBUG -g -Wall)
endif(CMAKE_BUILD_TYPE STREQUAL Debug) endif(CMAKE_BUILD_TYPE STREQUAL Debug)
# Devel - Build # Devel - Build

View File

@ -54,8 +54,8 @@
//#define LOUD_DEBUGGING //#define LOUD_DEBUGGING
#define SHADER_DEBUG #define SHADER_DEBUG
//#define DUMP_START (500) //#define DUMP_START (13000)
//#define DUMP_LENGTH (40) //#define DUMP_LENGTH (200)
//#define DUMP_ONLY_FRAME (112) //#define DUMP_ONLY_FRAME (112)
#ifdef DUMP_START #ifdef DUMP_START
@ -219,9 +219,9 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
glGenFramebuffers(1, &m_fbo); glGenFramebuffers(1, &m_fbo);
// Setup FBO fragment output // Setup FBO fragment output
OMSetFBO(m_fbo); // OMSetFBO(m_fbo);
glDrawBuffer(GL_COLOR_ATTACHMENT0); // glDrawBuffer(GL_COLOR_ATTACHMENT0);
OMSetFBO(0); // OMSetFBO(0);
// **************************************************************** // ****************************************************************
// Vertex buffer state // Vertex buffer state
@ -711,7 +711,6 @@ void GSDeviceOGL::CopyRect(GSTexture* st, GSTexture* dt, const GSVector4i& r)
GLuint fbo_old = m_state.fbo; GLuint fbo_old = m_state.fbo;
OMSetFBO(m_fbo); OMSetFBO(m_fbo);
// Set the input of glCopyTexSubImage2D // Set the input of glCopyTexSubImage2D
static_cast<GSTextureOGL*>(st)->Attach(GL_COLOR_ATTACHMENT1); static_cast<GSTextureOGL*>(st)->Attach(GL_COLOR_ATTACHMENT1);
glReadBuffer(GL_COLOR_ATTACHMENT1); glReadBuffer(GL_COLOR_ATTACHMENT1);
@ -1012,6 +1011,8 @@ void GSDeviceOGL::IASetVertexBuffer(const void* vertices, size_t count)
} }
vb->upload(vertices, map_flags); vb->upload(vertices, map_flags);
// FIXME: disable it when code is working
CheckDebugLog();
} }
void GSDeviceOGL::IASetPrimitiveTopology(GLenum topology) void GSDeviceOGL::IASetPrimitiveTopology(GLenum topology)

View File

@ -171,6 +171,12 @@ struct GSVertexBufferState {
void upload(const void* src, uint32 flags) void upload(const void* src, uint32 flags)
{ {
uint8* dst = (uint8*) glMapBufferRange(GL_ARRAY_BUFFER, stride*start, stride*count, flags); uint8* dst = (uint8*) glMapBufferRange(GL_ARRAY_BUFFER, stride*start, stride*count, flags);
#ifdef OGL_DEBUG
if (dst == NULL) {
fprintf(stderr, "CRITICAL ERROR map failed for vb !!!\n");
return;
}
#endif
memcpy(dst, src, stride*count); memcpy(dst, src, stride*count);
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
} }

View File

@ -26,8 +26,7 @@ static uint g_state_texture_unit = 0;
static uint g_state_texture_id = 0; static uint g_state_texture_id = 0;
GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format) GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format)
: m_texture_unit(0), : m_extra_buffer_id(0),
m_extra_buffer_id(0),
m_pbo_size(0) m_pbo_size(0)
{ {
// ************************************************************* // *************************************************************
@ -120,7 +119,7 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format)
switch (m_type) { switch (m_type) {
case GSTexture::DepthStencil: case GSTexture::DepthStencil:
EnableUnit(1); EnableUnit(1);
glTexImage2D(m_texture_target, 0, m_format, w, h, 0, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, NULL); glTexImage2D(m_texture_target, 0, m_format, m_size.x, m_size.y, 0, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, NULL);
break; break;
case GSTexture::RenderTarget: case GSTexture::RenderTarget:
case GSTexture::Texture: case GSTexture::Texture:
@ -130,7 +129,7 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format)
// For the moment SW renderer only use 1 so don't bother // For the moment SW renderer only use 1 so don't bother
EnableUnit(0); EnableUnit(0);
if (m_format == GL_RGBA8) { if (m_format == GL_RGBA8) {
glTexImage2D(m_texture_target, 0, m_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(m_texture_target, 0, m_format, m_size.x, m_size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
} }
else else
assert(0); // TODO Later assert(0); // TODO Later
@ -161,54 +160,27 @@ void GSTextureOGL::Attach(GLenum attachment)
bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch) bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch)
{ {
// static int update_count = 0;
// update_count++;
// To update only a part of the texture you can use:
// glTexSubImage2D — specify a two-dimensional texture subimage
if (m_type == GSTexture::DepthStencil || m_type == GSTexture::Offscreen) assert(0); if (m_type == GSTexture::DepthStencil || m_type == GSTexture::Offscreen) assert(0);
// glTexSubImage2D specifies a two-dimensional subtexture for the current texture unit, specified with glActiveTexture.
// If a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target
//(see glBindBuffer) while a texture image is
// specified, data is treated as a byte offset into the buffer object's data store
// FIXME warning order of the y axis // FIXME warning order of the y axis
// FIXME I'm not confident with GL_UNSIGNED_BYTE type // FIXME I'm not confident with GL_UNSIGNED_BYTE type
// FIXME add a state check
EnableUnit(0); EnableUnit(0);
if (m_format != GL_RGBA8) assert(0); if (m_format != GL_RGBA8) {
fprintf(stderr, "wrong pixel format\n");
// FIXME. That suck but I don't know how to do better for now. I think we need to create a texture buffer and directly upload the copy assert(0);
// The case appears on SW mode. Src pitch is 2x dst pitch.
int rowbytes = r.width() << 2;
if (pitch != rowbytes) {
uint32 map_flags = GL_MAP_WRITE_BIT;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_extra_buffer_id);
if (!m_pbo_size) {
m_pbo_size = m_size.x * m_size.y * 4;
glBufferData(GL_PIXEL_UNPACK_BUFFER, m_pbo_size, NULL, GL_STREAM_DRAW);
} else {
GL_MAP_INVALIDATE_BUFFER_BIT;
} }
uint8* src = (uint8*) data; // pitch could be different of width*element_size
uint8* dst = (uint8*) glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, m_pbo_size, map_flags); glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch>>2);
for(int h = r.height(); h > 0; h--, src += pitch, dst += rowbytes) // FIXME : it crash on colin mcrae rally 3 (others game too) when the size is 16
{ //if (m_size.x != 16)
memcpy(dst, src, rowbytes);
}
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
glTexSubImage2D(m_texture_target, 0, r.x, r.y, r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE, 0 /* offset in UNPACK BUFFER */);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
} else {
glTexSubImage2D(m_texture_target, 0, r.x, r.y, r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE, data); glTexSubImage2D(m_texture_target, 0, r.x, r.y, r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE, data);
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); // Restore default behavior
return true;
#if 0 #if 0
if(m_dev && m_texture) if(m_dev && m_texture)
{ {

View File

@ -28,7 +28,6 @@ class GSTextureOGL : public GSTexture
private: private:
GLenum m_texture_target; // texture target: 2D, rectangle etc... GLenum m_texture_target; // texture target: 2D, rectangle etc...
GLuint m_texture_id; // the texture id GLuint m_texture_id; // the texture id
uint m_texture_unit; // the texture unit offset
uint m_extra_buffer_id; uint m_extra_buffer_id;
int m_pbo_size; int m_pbo_size;

View File

@ -257,8 +257,8 @@ void gs_main()
layout(location = 0) in vertex PSin; layout(location = 0) in vertex PSin;
// Same buffer but 2 colors for dual source blending // Same buffer but 2 colors for dual source blending
layout(location = 0, index = 0) out vec4 SV_Target0; layout(location = 0, index = 1) out vec4 SV_Target0;
layout(location = 0, index = 1) out vec4 SV_Target1; layout(location = 0, index = 0) out vec4 SV_Target1;
layout(binding = 0) uniform sampler2D TextureSampler; layout(binding = 0) uniform sampler2D TextureSampler;
layout(binding = 1) uniform sampler2D PaletteSampler; layout(binding = 1) uniform sampler2D PaletteSampler;