gsdx-ogl-wnd:

* clean texture management & use different texture unit for various texture operation
* separate sampler and texture setup
* Always disable GL_SCISSOR_TEST before any cleaning to be sure the all pixels are reset
* properly set upscale_multiplier in the linux gui (was mixed with msaa). Unfortunately it is still broken...
* Fix EGL with GSopen1
* Use stdcall for function definition in the replay (avoid segmentation fault)
* Directly use gl_Position in shader instead of an extra user defined variable


git-svn-id: http://pcsx2.googlecode.com/svn/branches/gsdx-ogl-wnd@5648 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2013-06-01 09:29:57 +00:00
parent acaf1ac8d5
commit efcb015361
9 changed files with 131 additions and 196 deletions

View File

@ -228,31 +228,21 @@ namespace GLLoader {
string ext((const char*)gl_GetStringi(GL_EXTENSIONS, i)); string ext((const char*)gl_GetStringi(GL_EXTENSIONS, i));
if (ext.compare("GL_ARB_separate_shader_objects") == 0) { if (ext.compare("GL_ARB_separate_shader_objects") == 0) {
if (!fglrx_buggy_driver) found_GL_ARB_separate_shader_objects = true; if (!fglrx_buggy_driver) found_GL_ARB_separate_shader_objects = true;
else fprintf(stderr, "Buggy driver detected, GL_ARB_separate_shader_objects will be disabled\n");
} }
if (ext.compare("GL_ARB_shading_language_420pack") == 0) { if (ext.compare("GL_ARB_shading_language_420pack") == 0) found_GL_ARB_shading_language_420pack = true;
found_GL_ARB_shading_language_420pack = true; if (ext.compare("GL_ARB_texture_storage") == 0) found_GL_ARB_texture_storage = true;
} if (ext.compare("GL_NV_copy_image") == 0) found_GL_NV_copy_image = true;
if (ext.compare("GL_ARB_texture_storage") == 0) {
found_GL_ARB_texture_storage = true;
}
if (ext.compare("GL_NV_copy_image") == 0) {
found_GL_NV_copy_image = true;
}
// Replace previous extensions (when driver will be updated) // Replace previous extensions (when driver will be updated)
if (ext.compare("GL_ARB_copy_image") == 0) { if (ext.compare("GL_ARB_copy_image") == 0) found_GL_ARB_copy_image = true;
found_GL_ARB_copy_image = true;
}
fprintf(stderr, "EXT: %s\n", ext.c_str());
} }
} }
if (!found_GL_ARB_separate_shader_objects) { if (!found_GL_ARB_separate_shader_objects) {
fprintf(stderr, "GL_ARB_separate_shader_objects is not supported\n"); fprintf(stderr, "GL_ARB_separate_shader_objects is not supported\n");
//return false;
} }
if (!found_GL_ARB_shading_language_420pack) { if (!found_GL_ARB_shading_language_420pack) {
fprintf(stderr, "GL_ARB_shading_language_420pack is not supported\n"); fprintf(stderr, "GL_ARB_shading_language_420pack is not supported\n");
//return false;
} }
if (!found_GL_ARB_texture_storage) { if (!found_GL_ARB_texture_storage) {
fprintf(stderr, "GL_ARB_texture_storage is not supported\n"); fprintf(stderr, "GL_ARB_texture_storage is not supported\n");

View File

@ -50,8 +50,6 @@ GSDeviceOGL::GSDeviceOGL()
, m_fbo(0) , m_fbo(0)
, m_fbo_read(0) , m_fbo_read(0)
, m_vb_sr(NULL) , m_vb_sr(NULL)
, m_srv_changed(false)
, m_ss_changed(false)
{ {
m_msaa = !!theApp.GetConfig("UserHacks", 0) ? theApp.GetConfig("UserHacks_MSAA", 0) : 0; m_msaa = !!theApp.GetConfig("UserHacks", 0) ? theApp.GetConfig("UserHacks_MSAA", 0) : 0;
@ -719,23 +717,20 @@ void GSDeviceOGL::DrawIndexedPrimitive(int offset, int count)
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c) void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c)
{ {
GLuint fbo_old = m_state.fbo; glDisable(GL_SCISSOR_TEST);
if (static_cast<GSTextureOGL*>(t)->IsBackbuffer()) { if (static_cast<GSTextureOGL*>(t)->IsBackbuffer()) {
// FIXME I really not sure
OMSetFBO(0); OMSetFBO(0);
//gl_ClearBufferfv(GL_COLOR, GL_LEFT, c.v);
// glDrawBuffer(GL_BACK); // this is the default when there is no FB
// 0 will select the first drawbuffer ie GL_BACK
gl_ClearBufferfv(GL_COLOR, 0, c.v); gl_ClearBufferfv(GL_COLOR, 0, c.v);
// code for the old interface
// glClearColor(c.x, c.y, c.z, c.w);
// glClear(GL_COLOR_BUFFER_BIT);
} else { } else {
// FIXME1 I need to clarify this FBO attachment stuff
// I would like to avoid FBO for a basic clean operation
OMSetFBO(m_fbo); OMSetFBO(m_fbo);
static_cast<GSTextureOGL*>(t)->Attach(GL_COLOR_ATTACHMENT0); static_cast<GSTextureOGL*>(t)->Attach(GL_COLOR_ATTACHMENT0);
gl_ClearBufferfv(GL_COLOR, 0, c.v); gl_ClearBufferfv(GL_COLOR, 0, c.v);
} }
OMSetFBO(fbo_old); glEnable(GL_SCISSOR_TEST);
} }
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, uint32 c) void GSDeviceOGL::ClearRenderTarget(GSTexture* t, uint32 c)
@ -746,14 +741,9 @@ void GSDeviceOGL::ClearRenderTarget(GSTexture* t, uint32 c)
void GSDeviceOGL::ClearDepth(GSTexture* t, float c) void GSDeviceOGL::ClearDepth(GSTexture* t, float c)
{ {
GLuint fbo_old = m_state.fbo;
// FIXME I need to clarify this FBO attachment stuff
// I would like to avoid FBO for a basic clean operation
OMSetFBO(m_fbo); OMSetFBO(m_fbo);
static_cast<GSTextureOGL*>(t)->Attach(GL_DEPTH_STENCIL_ATTACHMENT); static_cast<GSTextureOGL*>(t)->Attach(GL_DEPTH_STENCIL_ATTACHMENT);
// FIXME can you clean depth and stencil separately
// XXX: glClear* depends on the scissor test!!! Disable it because the viewport
// could be smaller than the texture and we really want to clean all pixels.
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
if (m_state.dss != NULL && m_state.dss->IsMaskEnable()) { if (m_state.dss != NULL && m_state.dss->IsMaskEnable()) {
gl_ClearBufferfv(GL_DEPTH, 0, &c); gl_ClearBufferfv(GL_DEPTH, 0, &c);
@ -763,20 +753,17 @@ void GSDeviceOGL::ClearDepth(GSTexture* t, float c)
glDepthMask(false); glDepthMask(false);
} }
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
OMSetFBO(fbo_old);
} }
void GSDeviceOGL::ClearStencil(GSTexture* t, uint8 c) void GSDeviceOGL::ClearStencil(GSTexture* t, uint8 c)
{ {
GLuint fbo_old = m_state.fbo;
// FIXME I need to clarify this FBO attachment stuff
// I would like to avoid FBO for a basic clean operation
OMSetFBO(m_fbo); OMSetFBO(m_fbo);
static_cast<GSTextureOGL*>(t)->Attach(GL_DEPTH_STENCIL_ATTACHMENT); static_cast<GSTextureOGL*>(t)->Attach(GL_DEPTH_STENCIL_ATTACHMENT);
GLint color = c; GLint color = c;
// FIXME can you clean depth and stencil separately
glDisable(GL_SCISSOR_TEST);
gl_ClearBufferiv(GL_STENCIL, 0, &color); gl_ClearBufferiv(GL_STENCIL, 0, &color);
OMSetFBO(fbo_old); glEnable(GL_SCISSOR_TEST);
} }
GSTexture* GSDeviceOGL::CreateRenderTarget(int w, int h, bool msaa, int format) GSTexture* GSDeviceOGL::CreateRenderTarget(int w, int h, bool msaa, int format)
@ -887,7 +874,7 @@ void GSDeviceOGL::CopyRect(GSTexture* st, GSTexture* dt, const GSVector4i& r)
gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read); gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read);
st_ogl->AttachRead(GL_COLOR_ATTACHMENT0); st_ogl->AttachRead(GL_COLOR_ATTACHMENT0);
dt_ogl->EnableUnit(0); dt_ogl->EnableUnit(6);
glCopyTexSubImage2D(dt_ogl->GetTarget(), 0, r.x, r.y, r.x, r.y, r.width(), r.height()); glCopyTexSubImage2D(dt_ogl->GetTarget(), 0, r.x, r.y, r.x, r.y, r.width(), r.height());
gl_BindFramebuffer(GL_READ_FRAMEBUFFER, 0); gl_BindFramebuffer(GL_READ_FRAMEBUFFER, 0);
@ -1214,21 +1201,20 @@ void GSDeviceOGL::PSSetShaderResource(int i, GSTexture* sr)
if (m_state.ps_srv[i] != srv) if (m_state.ps_srv[i] != srv)
{ {
m_state.ps_srv[i] = srv; m_state.ps_srv[i] = srv;
if (srv != NULL)
m_srv_changed = true; m_state.ps_srv[i]->EnableUnit(i);
} }
} }
void GSDeviceOGL::PSSetSamplerState(GLuint ss0, GLuint ss1, GLuint ss2) void GSDeviceOGL::PSSetSamplerState(GLuint ss0, GLuint ss1, GLuint ss2)
{ {
if(m_state.ps_ss[0] != ss0 || m_state.ps_ss[1] != ss1) if (m_state.ps_ss[0] != ss0) {
//if(m_state.ps_ss[0] != ss0 || m_state.ps_ss[1] != ss1 || m_state.ps_ss[2] != ss2)
{
m_state.ps_ss[0] = ss0; m_state.ps_ss[0] = ss0;
gl_BindSampler(0, ss0);
}
if (m_state.ps_ss[1] != ss1) {
m_state.ps_ss[1] = ss1; m_state.ps_ss[1] = ss1;
//m_state.ps_ss[2] = ss2; gl_BindSampler(1, ss1);
m_ss_changed = true;
} }
} }
@ -1240,24 +1226,6 @@ void GSDeviceOGL::PSSetShader(GLuint ps)
if (GLLoader::found_GL_ARB_separate_shader_objects) if (GLLoader::found_GL_ARB_separate_shader_objects)
gl_UseProgramStages(m_pipeline, GL_FRAGMENT_SHADER_BIT, ps); gl_UseProgramStages(m_pipeline, GL_FRAGMENT_SHADER_BIT, ps);
} }
// Sampler and texture must be set at the same time
// 1/ select the texture unit
// gl_ActiveTexture(GL_TEXTURE0 + 1);
// 2/ bind the texture
// glBindTexture(GL_TEXTURE_2D , brickTexture);
// 3/ sets the texture sampler in GLSL (could be useless with layout stuff)
// gl_Uniform1i(brickSamplerId , 1);
// 4/ set the sampler state
// gl_BindSampler(1 , sampler);
if (m_srv_changed || m_ss_changed) {
for (uint32 i=0 ; i < 1; i++) {
if (m_state.ps_srv[i] != NULL) {
m_state.ps_srv[i]->EnableUnit(i);
gl_BindSampler(i, m_state.ps_ss[i]);
}
}
}
} }
void GSDeviceOGL::OMSetFBO(GLuint fbo, GLenum buffer) void GSDeviceOGL::OMSetFBO(GLuint fbo, GLenum buffer)

View File

@ -551,9 +551,6 @@ class GSDeviceOGL : public GSDevice
GLenum draw; GLenum draw;
} m_state; } m_state;
bool m_srv_changed;
bool m_ss_changed;
hash_map<uint32, GLuint > m_vs; hash_map<uint32, GLuint > m_vs;
hash_map<uint32, GLuint > m_gs; hash_map<uint32, GLuint > m_gs;
hash_map<uint32, GLuint > m_ps; hash_map<uint32, GLuint > m_ps;

View File

@ -24,7 +24,7 @@
#include "GSdx.h" #include "GSdx.h"
#include "GSLinuxLogo.h" #include "GSLinuxLogo.h"
GtkWidget *msaa_combo_box, *render_combo_box, *filter_combo_box; GtkWidget *fsaa_combo_box, *render_combo_box, *filter_combo_box;
GtkWidget *shadeboost_check, *paltex_check, *fba_check, *aa_check, *native_res_check; GtkWidget *shadeboost_check, *paltex_check, *fba_check, *aa_check, *native_res_check;
GtkWidget *sb_contrast, *sb_brightness, *sb_saturation; GtkWidget *sb_contrast, *sb_brightness, *sb_saturation;
GtkWidget *resx_spin, *resy_spin; GtkWidget *resx_spin, *resy_spin;
@ -133,7 +133,7 @@ GtkWidget* CreateMsaaComboBox()
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "5x"); gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "5x");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "6x"); gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "6x");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), theApp.GetConfig("msaa", 0)); gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), theApp.GetConfig("upscale_multiplier", 2)-1);
return combo_box; return combo_box;
} }
@ -152,11 +152,8 @@ GtkWidget* CreateFilterComboBox()
void toggle_widget_states( GtkWidget *widget, gpointer callback_data ) void toggle_widget_states( GtkWidget *widget, gpointer callback_data )
{ {
int render_type; int render_type = gtk_combo_box_get_active(GTK_COMBO_BOX(render_combo_box));
bool hardware_render = false, software_render = false, null_render = false; bool hardware_render = ((render_type % 3) == 1);
render_type = gtk_combo_box_get_active(GTK_COMBO_BOX(render_combo_box));
hardware_render = ((render_type % 3) == 1);
if (hardware_render) if (hardware_render)
{ {
@ -168,15 +165,15 @@ void toggle_widget_states( GtkWidget *widget, gpointer callback_data )
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(native_res_check))) if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(native_res_check)))
{ {
gtk_widget_set_sensitive(msaa_combo_box, false); gtk_widget_set_sensitive(fsaa_combo_box, false);
gtk_widget_set_sensitive(resx_spin, false); gtk_widget_set_sensitive(resx_spin, false);
gtk_widget_set_sensitive(resy_spin, false); gtk_widget_set_sensitive(resy_spin, false);
} }
else else
{ {
gtk_widget_set_sensitive(msaa_combo_box, true); gtk_widget_set_sensitive(fsaa_combo_box, true);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(msaa_combo_box)) == 0) if (gtk_combo_box_get_active(GTK_COMBO_BOX(fsaa_combo_box)) == 0)
{ {
gtk_widget_set_sensitive(resx_spin, true); gtk_widget_set_sensitive(resx_spin, true);
gtk_widget_set_sensitive(resy_spin, true); gtk_widget_set_sensitive(resy_spin, true);
@ -200,7 +197,7 @@ void toggle_widget_states( GtkWidget *widget, gpointer callback_data )
gtk_widget_set_sensitive(fba_check, false); gtk_widget_set_sensitive(fba_check, false);
gtk_widget_set_sensitive(native_res_check, false); gtk_widget_set_sensitive(native_res_check, false);
gtk_widget_set_sensitive(msaa_combo_box, false); gtk_widget_set_sensitive(fsaa_combo_box, false);
gtk_widget_set_sensitive(resx_spin, false); gtk_widget_set_sensitive(resx_spin, false);
gtk_widget_set_sensitive(resy_spin, false); gtk_widget_set_sensitive(resy_spin, false);
@ -229,10 +226,10 @@ bool RunLinuxDialog()
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *main_box, *res_box, *hw_box, *sw_box; GtkWidget *main_box, *res_box, *hw_box, *sw_box;
GtkWidget *native_box, *msaa_box, *resxy_box, *renderer_box, *interlace_box, *threads_box, *filter_box; GtkWidget *native_box, *fsaa_box, *resxy_box, *renderer_box, *interlace_box, *threads_box, *filter_box;
GtkWidget *hw_table, *res_frame, *hw_frame, *sw_frame; GtkWidget *hw_table, *res_frame, *hw_frame, *sw_frame;
GtkWidget *interlace_combo_box, *threads_spin; GtkWidget *interlace_combo_box, *threads_spin;
GtkWidget *interlace_label, *threads_label, *native_label, *msaa_label, *rexy_label, *render_label, *filter_label; GtkWidget *interlace_label, *threads_label, *native_label, *fsaa_label, *rexy_label, *render_label, *filter_label;
GtkWidget *hack_table, *hack_skipdraw_label, *hack_box, *hack_frame; GtkWidget *hack_table, *hack_skipdraw_label, *hack_box, *hack_frame;
GtkWidget *hack_alpha_check, *hack_offset_check, *hack_skipdraw_spin, *hack_msaa_check, *hack_sprite_check, * hack_wild_check, *hack_enble_check; GtkWidget *hack_alpha_check, *hack_offset_check, *hack_skipdraw_spin, *hack_msaa_check, *hack_sprite_check, * hack_wild_check, *hack_enble_check;
@ -323,11 +320,11 @@ bool RunLinuxDialog()
gtk_box_pack_start(GTK_BOX(native_box), native_label, false, false, 5); gtk_box_pack_start(GTK_BOX(native_box), native_label, false, false, 5);
gtk_box_pack_start(GTK_BOX(native_box), native_res_check, false, false, 5); gtk_box_pack_start(GTK_BOX(native_box), native_res_check, false, false, 5);
msaa_label = gtk_label_new("Or Use Scaling (broken):"); fsaa_label = gtk_label_new("Or Use Scaling (broken):");
msaa_combo_box = CreateMsaaComboBox(); fsaa_combo_box = CreateMsaaComboBox();
msaa_box = gtk_hbox_new(false, 5); fsaa_box = gtk_hbox_new(false, 5);
gtk_box_pack_start(GTK_BOX(msaa_box), msaa_label, false, false, 5); gtk_box_pack_start(GTK_BOX(fsaa_box), fsaa_label, false, false, 5);
gtk_box_pack_start(GTK_BOX(msaa_box), msaa_combo_box, false, false, 5); gtk_box_pack_start(GTK_BOX(fsaa_box), fsaa_combo_box, false, false, 5);
rexy_label = gtk_label_new("Custom Resolution:"); rexy_label = gtk_label_new("Custom Resolution:");
resx_spin = gtk_spin_button_new_with_range(256,8192,1); resx_spin = gtk_spin_button_new_with_range(256,8192,1);
@ -405,7 +402,7 @@ bool RunLinuxDialog()
// Populate all those boxes we created earlier with widgets. // Populate all those boxes we created earlier with widgets.
gtk_container_add(GTK_CONTAINER(res_box), native_box); gtk_container_add(GTK_CONTAINER(res_box), native_box);
gtk_container_add(GTK_CONTAINER(res_box), msaa_box); gtk_container_add(GTK_CONTAINER(res_box), fsaa_box);
gtk_container_add(GTK_CONTAINER(res_box), resxy_box); gtk_container_add(GTK_CONTAINER(res_box), resxy_box);
gtk_container_add(GTK_CONTAINER(sw_box), threads_box); gtk_container_add(GTK_CONTAINER(sw_box), threads_box);
@ -437,7 +434,7 @@ bool RunLinuxDialog()
} }
g_signal_connect(render_combo_box, "changed", G_CALLBACK(toggle_widget_states), NULL); g_signal_connect(render_combo_box, "changed", G_CALLBACK(toggle_widget_states), NULL);
g_signal_connect(msaa_combo_box, "changed", G_CALLBACK(toggle_widget_states), NULL); g_signal_connect(fsaa_combo_box, "changed", G_CALLBACK(toggle_widget_states), NULL);
g_signal_connect(native_res_check, "toggled", G_CALLBACK(toggle_widget_states), NULL); g_signal_connect(native_res_check, "toggled", G_CALLBACK(toggle_widget_states), NULL);
// Put the box in the dialog and show it to the world. // Put the box in the dialog and show it to the world.
gtk_container_add (GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_box); gtk_container_add (GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_box);
@ -484,7 +481,7 @@ bool RunLinuxDialog()
theApp.SetConfig("ShadeBoost_Brightness", (int)gtk_range_get_value(GTK_RANGE(sb_brightness))); theApp.SetConfig("ShadeBoost_Brightness", (int)gtk_range_get_value(GTK_RANGE(sb_brightness)));
theApp.SetConfig("ShadeBoost_Contrast", (int)gtk_range_get_value(GTK_RANGE(sb_contrast))); theApp.SetConfig("ShadeBoost_Contrast", (int)gtk_range_get_value(GTK_RANGE(sb_contrast)));
theApp.SetConfig("msaa", (int)gtk_combo_box_get_active(GTK_COMBO_BOX(msaa_combo_box))); theApp.SetConfig("upscale_multiplier", (int)gtk_combo_box_get_active(GTK_COMBO_BOX(fsaa_combo_box))+1);
theApp.SetConfig("resx", (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(resx_spin))); theApp.SetConfig("resx", (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(resx_spin)));
theApp.SetConfig("resy", (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(resy_spin))); theApp.SetConfig("resy", (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(resy_spin)));
@ -498,6 +495,9 @@ bool RunLinuxDialog()
theApp.SetConfig("UserHacks", (int)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hack_enble_check))); theApp.SetConfig("UserHacks", (int)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hack_enble_check)));
theApp.SetConfig("UserHacks_TCOffset", get_hex_entry(hack_tco_entry)); theApp.SetConfig("UserHacks_TCOffset", get_hex_entry(hack_tco_entry));
// NOT supported yet
theApp.SetConfig("msaa", 0);
// Let's just be windowed for the moment. // Let's just be windowed for the moment.
theApp.SetConfig("windowed", 1); theApp.SetConfig("windowed", 1);

View File

@ -23,7 +23,7 @@
#include <limits.h> #include <limits.h>
#include "GSTextureOGL.h" #include "GSTextureOGL.h"
static int g_state_texture_unit = -1; static int g_state_texture_unit = -1;
static int g_state_texture_id = -1; static int g_state_texture_id[7] = {0, 0, 0, 0, 0, 0, 0};
// FIXME: check if it possible to always use those setup by default // FIXME: check if it possible to always use those setup by default
// glPixelStorei(GL_PACK_ALIGNMENT, 1); // glPixelStorei(GL_PACK_ALIGNMENT, 1);
@ -121,7 +121,7 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format, GLuint
// Howto allocate the texture unit !!! // Howto allocate the texture unit !!!
// In worst case the HW renderer seems to use 3 texture unit // In worst case the HW renderer seems to use 3 texture unit
// 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(3);
if (m_msaa) { if (m_msaa) {
ASSERT(m_texture_target == GL_TEXTURE_2D_MULTISAMPLE); ASSERT(m_texture_target == GL_TEXTURE_2D_MULTISAMPLE);
// Require a recent GLEW and GL4.3 // Require a recent GLEW and GL4.3
@ -137,13 +137,17 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, bool msaa, int format, GLuint
GSTextureOGL::~GSTextureOGL() GSTextureOGL::~GSTextureOGL()
{ {
/* Unbind the texture from our local state */
for (uint i = 0; i < 7; i++)
if (g_state_texture_id[i] == m_texture_id)
g_state_texture_id[i] = 0;
gl_DeleteBuffers(1, &m_pbo_id); gl_DeleteBuffers(1, &m_pbo_id);
glDeleteTextures(1, &m_texture_id); glDeleteTextures(1, &m_texture_id);
} }
void GSTextureOGL::Attach(GLenum attachment) void GSTextureOGL::Attach(GLenum attachment)
{ {
//fprintf(stderr, "format %d,%x\n", m_type, m_format);
gl_FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, m_texture_target, m_texture_id, 0); gl_FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, m_texture_target, m_texture_id, 0);
// FIXME DEBUG // FIXME DEBUG
//fprintf(stderr, "FB status %x\n", gl_CheckFramebufferStatus(GL_FRAMEBUFFER)); //fprintf(stderr, "FB status %x\n", gl_CheckFramebufferStatus(GL_FRAMEBUFFER));
@ -162,7 +166,7 @@ bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch)
// 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
EnableUnit(0); EnableUnit(4);
// pitch is in byte wherease GL_UNPACK_ROW_LENGTH is in pixel // pitch is in byte wherease GL_UNPACK_ROW_LENGTH is in pixel
GLenum format; GLenum format;
@ -233,21 +237,18 @@ bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch)
void GSTextureOGL::EnableUnit(uint32 unit) void GSTextureOGL::EnableUnit(uint32 unit)
{ {
if (!IsBackbuffer()) { /* Not a real texture */
// FIXME if (IsBackbuffer()) {
// Howto allocate the texture unit !!! return;
// In worst case the HW renderer seems to use 3 texture unit
// For the moment SW renderer only use 1 so don't bother
if (g_state_texture_unit != unit) {
g_state_texture_unit = unit;
gl_ActiveTexture(GL_TEXTURE0 + unit);
// When you change the texture unit, texture must be rebinded
g_state_texture_id = m_texture_id;
glBindTexture(m_texture_target, m_texture_id);
} else if (g_state_texture_id != m_texture_id) {
g_state_texture_id = m_texture_id;
glBindTexture(m_texture_target, m_texture_id);
} }
if (g_state_texture_unit != unit) {
gl_ActiveTexture(GL_TEXTURE0 + unit);
g_state_texture_unit = unit;
}
if (g_state_texture_id[unit] != m_texture_id) {
g_state_texture_id[unit] = m_texture_id;
glBindTexture(m_texture_target, m_texture_id);
} }
} }
@ -262,7 +263,7 @@ bool GSTextureOGL::Map(GSMap& m, const GSVector4i* r)
// Can be used on GL_PIXEL_UNPACK_BUFFER or GL_TEXTURE_BUFFER // Can be used on GL_PIXEL_UNPACK_BUFFER or GL_TEXTURE_BUFFER
if (m_type == GSTexture::Offscreen) { if (m_type == GSTexture::Offscreen) {
// Bind the texture to the read framebuffer to avoid any disturbance // Bind the texture to the read framebuffer to avoid any disturbance
EnableUnit(0); EnableUnit(5);
gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read); gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read);
gl_FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture_target, m_texture_id, 0); gl_FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture_target, m_texture_id, 0);
glReadBuffer(GL_COLOR_ATTACHMENT0); glReadBuffer(GL_COLOR_ATTACHMENT0);
@ -444,8 +445,6 @@ bool GSTextureOGL::Save(const string& fn, bool dds)
} else if(IsDss()) { } else if(IsDss()) {
gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read); gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read);
//EnableUnit(0);
gl_FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_texture_target, m_texture_id, 0); gl_FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_texture_target, m_texture_id, 0);
glReadPixels(0, 0, m_size.x, m_size.y, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, image); glReadPixels(0, 0, m_size.x, m_size.y, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, image);
@ -453,7 +452,7 @@ bool GSTextureOGL::Save(const string& fn, bool dds)
} else { } else {
gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read); gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read);
EnableUnit(0); EnableUnit(6);
gl_FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture_target, m_texture_id, 0); gl_FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture_target, m_texture_id, 0);
glReadBuffer(GL_COLOR_ATTACHMENT0); glReadBuffer(GL_COLOR_ATTACHMENT0);

View File

@ -168,35 +168,9 @@ bool GSWndEGL::Create(const string& title, int w, int h)
// note this part must be only executed when replaying .gs debug file // note this part must be only executed when replaying .gs debug file
m_NativeDisplay = XOpenDisplay(NULL); m_NativeDisplay = XOpenDisplay(NULL);
if (!OpenEGLDisplay()) return false;
#if 0
int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_DEPTH_SIZE, 24,
None
};
XVisualInfo* vi = glXChooseVisual(m_NativeDisplay, DefaultScreen(m_NativeDisplay), attrListDbl);
/* create a color map */
XSetWindowAttributes attr;
attr.colormap = XCreateColormap(m_NativeDisplay, RootWindow(m_NativeDisplay, vi->screen),
vi->visual, AllocNone);
attr.border_pixel = 0;
attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
StructureNotifyMask | SubstructureRedirectMask | SubstructureNotifyMask |
EnterWindowMask | LeaveWindowMask | FocusChangeMask ;
// Create a window at the last position/size
m_NativeWindow = XCreateWindow(m_NativeDisplay, RootWindow(m_NativeDisplay, vi->screen),
0 , 0 , w, h, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &attr);
XFree(vi);
#else
m_NativeWindow = XCreateSimpleWindow(m_NativeDisplay, DefaultRootWindow(m_NativeDisplay), 0, 0, w, h, 0, 0, 0); m_NativeWindow = XCreateSimpleWindow(m_NativeDisplay, DefaultRootWindow(m_NativeDisplay), 0, 0, w, h, 0, 0, 0);
#endif
XMapWindow (m_NativeDisplay, m_NativeWindow); XMapWindow (m_NativeDisplay, m_NativeWindow);

View File

@ -34,14 +34,14 @@ int main ( int argc, char *argv[] )
{ {
if (argc < 3) help(); if (argc < 3) help();
void *handle = dlopen(argv[1], RTLD_LAZY|RTLD_DEEPBIND); void *handle = dlopen(argv[1], RTLD_LAZY|RTLD_GLOBAL);
if (handle == NULL) { if (handle == NULL) {
fprintf(stderr, "Failed to open plugin %s\n", argv[1]); fprintf(stderr, "Failed to open plugin %s\n", argv[1]);
help(); help();
} }
void (*GSsetSettingsDir_ptr)(const char*); __attribute__((stdcall)) void (*GSsetSettingsDir_ptr)(const char*);
void (*GSReplay_ptr)(char*, int); __attribute__((stdcall)) void (*GSReplay_ptr)(char*, int);
*(void**)(&GSsetSettingsDir_ptr) = dlsym(handle, "GSsetSettingsDir"); *(void**)(&GSsetSettingsDir_ptr) = dlsym(handle, "GSsetSettingsDir");
*(void**)(&GSReplay_ptr) = dlsym(handle, "GSReplay"); *(void**)(&GSReplay_ptr) = dlsym(handle, "GSReplay");
@ -50,8 +50,7 @@ int main ( int argc, char *argv[] )
(void)GSsetSettingsDir_ptr(argv[3]); (void)GSsetSettingsDir_ptr(argv[3]);
} else if ( argc == 3) { } else if ( argc == 3) {
#ifdef XDG_STD #ifdef XDG_STD
std::string home("HOME"); char *val = getenv("HOME");
char * val = getenv( home.c_str() );
if (val == NULL) { if (val == NULL) {
dlclose(handle); dlclose(handle);
fprintf(stderr, "Failed to get the home dir\n"); fprintf(stderr, "Failed to get the home dir\n");

View File

@ -46,7 +46,7 @@
struct vertex struct vertex
{ {
vec4 p; //vec4 p;
vec4 t; vec4 t;
vec4 tp; vec4 tp;
vec4 c; vec4 c;
@ -69,17 +69,17 @@ layout(location = 0) out vertex VSout;
#define VSout_c (VSout.c) #define VSout_c (VSout.c)
#else #else
#ifdef DISABLE_SSO #ifdef DISABLE_SSO
out vec4 SHADERp; //out vec4 SHADERp;
out vec4 SHADERt; out vec4 SHADERt;
out vec4 SHADERtp; out vec4 SHADERtp;
out vec4 SHADERc; out vec4 SHADERc;
#else #else
layout(location = 0) out vec4 SHADERp; //layout(location = 0) out vec4 SHADERp;
layout(location = 1) out vec4 SHADERt; layout(location = 0) out vec4 SHADERt;
layout(location = 2) out vec4 SHADERtp; layout(location = 1) out vec4 SHADERtp;
layout(location = 3) out vec4 SHADERc; layout(location = 2) out vec4 SHADERc;
#endif #endif
#define VSout_p SHADERp //#define VSout_p SHADERp
#define VSout_t SHADERt #define VSout_t SHADERt
#define VSout_tp SHADERtp #define VSout_tp SHADERtp
#define VSout_c SHADERc #define VSout_c SHADERc
@ -130,7 +130,7 @@ void vs_main()
final_p.z = log2(1.0f + float(z)) / 32.0f; final_p.z = log2(1.0f + float(z)) / 32.0f;
} }
VSout_p = final_p; //VSout_p = final_p;
gl_Position = final_p; // NOTE I don't know if it is possible to merge POSITION_OUT and gl_Position gl_Position = final_p; // NOTE I don't know if it is possible to merge POSITION_OUT and gl_Position
#if VS_RTCOPY #if VS_RTCOPY
VSout_tp = final_p * vec4(0.5, -0.5, 0, 0) + 0.5; VSout_tp = final_p * vec4(0.5, -0.5, 0, 0) + 0.5;
@ -241,46 +241,50 @@ void gs_main()
// right bottom => GSin[1]; // right bottom => GSin[1];
vertex rb = GSin[1]; vertex rb = GSin[1];
vertex lt = GSin[0]; vertex lt = GSin[0];
vec4 rb_p = gl_in[1].gl_Position;
vec4 lb_p = gl_in[1].gl_Position;
vec4 rt_p = gl_in[1].gl_Position;
vec4 lt_p = gl_in[0].gl_Position;
lt.p.z = rb.p.z; lt_p.z = rb_p.z;
lt.t.zw = rb.t.zw; lt.t.zw = rb.t.zw;
#if GS_IIP == 0 #if GS_IIP == 0
lt.c = rb.c; lt.c = rb.c;
#endif #endif
vertex lb = rb; vertex lb = rb;
lb.p.x = lt.p.x; lb_p.x = lt_p.x;
lb.t.x = lt.t.x; lb.t.x = lt.t.x;
vertex rt = rb; vertex rt = rb;
rt.p.y = lt.p.y; rt_p.y = lt_p.y;
rt.t.y = lt.t.y; rt.t.y = lt.t.y;
// Triangle 1 // Triangle 1
gl_Position = lt.p; gl_Position = lt_p;
GSout = lt; GSout = lt;
EmitVertex(); EmitVertex();
gl_Position = lb.p; gl_Position = lb_p;
GSout = lb; GSout = lb;
EmitVertex(); EmitVertex();
gl_Position = rt.p; gl_Position = rt_p;
GSout = rt; GSout = rt;
EmitVertex(); EmitVertex();
EndPrimitive(); EndPrimitive();
// Triangle 2 // Triangle 2
gl_Position = lb.p; gl_Position = lb_p;
GSout = lb; GSout = lb;
EmitVertex(); EmitVertex();
gl_Position = rt.p; gl_Position = rt_p;
GSout = rt; GSout = rt;
EmitVertex(); EmitVertex();
gl_Position = rb.p; gl_Position = rb_p;
GSout = rb; GSout = rb;
EmitVertex(); EmitVertex();
@ -295,7 +299,7 @@ void gs_main()
#ifdef FRAGMENT_SHADER #ifdef FRAGMENT_SHADER
#if __VERSION__ > 140 && !(defined(NO_STRUCT)) #if __VERSION__ > 140 && !(defined(NO_STRUCT))
layout(location = 0) in vertex PSin; layout(location = 0) in vertex PSin;
#define PSin_p (PSin.p) //#define PSin_p (PSin.p)
#define PSin_t (PSin.t) #define PSin_t (PSin.t)
#define PSin_tp (PSin.tp) #define PSin_tp (PSin.tp)
#define PSin_c (PSin.c) #define PSin_c (PSin.c)
@ -306,12 +310,12 @@ in vec4 SHADERt;
in vec4 SHADERtp; in vec4 SHADERtp;
in vec4 SHADERc; in vec4 SHADERc;
#else #else
layout(location = 0) in vec4 SHADERp; //layout(location = 0) in vec4 SHADERp;
layout(location = 1) in vec4 SHADERt; layout(location = 0) in vec4 SHADERt;
layout(location = 2) in vec4 SHADERtp; layout(location = 1) in vec4 SHADERtp;
layout(location = 3) in vec4 SHADERc; layout(location = 2) in vec4 SHADERc;
#endif #endif
#define PSin_p SHADERp //#define PSin_p SHADERp
#define PSin_t SHADERt #define PSin_t SHADERt
#define PSin_tp SHADERtp #define PSin_tp SHADERtp
#define PSin_c SHADERc #define PSin_c SHADERc

View File

@ -74,7 +74,7 @@ static const char* tfx_glsl =
"\n" "\n"
"struct vertex\n" "struct vertex\n"
"{\n" "{\n"
" vec4 p;\n" " //vec4 p;\n"
" vec4 t;\n" " vec4 t;\n"
" vec4 tp;\n" " vec4 tp;\n"
" vec4 c;\n" " vec4 c;\n"
@ -97,17 +97,17 @@ static const char* tfx_glsl =
"#define VSout_c (VSout.c)\n" "#define VSout_c (VSout.c)\n"
"#else\n" "#else\n"
"#ifdef DISABLE_SSO\n" "#ifdef DISABLE_SSO\n"
"out vec4 SHADERp;\n" "//out vec4 SHADERp;\n"
"out vec4 SHADERt;\n" "out vec4 SHADERt;\n"
"out vec4 SHADERtp;\n" "out vec4 SHADERtp;\n"
"out vec4 SHADERc;\n" "out vec4 SHADERc;\n"
"#else\n" "#else\n"
"layout(location = 0) out vec4 SHADERp;\n" "//layout(location = 0) out vec4 SHADERp;\n"
"layout(location = 1) out vec4 SHADERt;\n" "layout(location = 0) out vec4 SHADERt;\n"
"layout(location = 2) out vec4 SHADERtp;\n" "layout(location = 1) out vec4 SHADERtp;\n"
"layout(location = 3) out vec4 SHADERc;\n" "layout(location = 2) out vec4 SHADERc;\n"
"#endif\n" "#endif\n"
"#define VSout_p SHADERp\n" "//#define VSout_p SHADERp\n"
"#define VSout_t SHADERt\n" "#define VSout_t SHADERt\n"
"#define VSout_tp SHADERtp\n" "#define VSout_tp SHADERtp\n"
"#define VSout_c SHADERc\n" "#define VSout_c SHADERc\n"
@ -158,7 +158,7 @@ static const char* tfx_glsl =
" final_p.z = log2(1.0f + float(z)) / 32.0f;\n" " final_p.z = log2(1.0f + float(z)) / 32.0f;\n"
" }\n" " }\n"
"\n" "\n"
" VSout_p = final_p;\n" " //VSout_p = final_p;\n"
" gl_Position = final_p; // NOTE I don't know if it is possible to merge POSITION_OUT and gl_Position\n" " gl_Position = final_p; // NOTE I don't know if it is possible to merge POSITION_OUT and gl_Position\n"
"#if VS_RTCOPY\n" "#if VS_RTCOPY\n"
" VSout_tp = final_p * vec4(0.5, -0.5, 0, 0) + 0.5;\n" " VSout_tp = final_p * vec4(0.5, -0.5, 0, 0) + 0.5;\n"
@ -269,46 +269,50 @@ static const char* tfx_glsl =
" // right bottom => GSin[1];\n" " // right bottom => GSin[1];\n"
" vertex rb = GSin[1];\n" " vertex rb = GSin[1];\n"
" vertex lt = GSin[0];\n" " vertex lt = GSin[0];\n"
" vec4 rb_p = gl_in[1].gl_Position;\n"
" vec4 lb_p = gl_in[1].gl_Position;\n"
" vec4 rt_p = gl_in[1].gl_Position;\n"
" vec4 lt_p = gl_in[0].gl_Position;\n"
"\n" "\n"
" lt.p.z = rb.p.z;\n" " lt_p.z = rb_p.z;\n"
" lt.t.zw = rb.t.zw;\n" " lt.t.zw = rb.t.zw;\n"
"#if GS_IIP == 0\n" "#if GS_IIP == 0\n"
" lt.c = rb.c;\n" " lt.c = rb.c;\n"
"#endif\n" "#endif\n"
"\n" "\n"
" vertex lb = rb;\n" " vertex lb = rb;\n"
" lb.p.x = lt.p.x;\n" " lb_p.x = lt_p.x;\n"
" lb.t.x = lt.t.x;\n" " lb.t.x = lt.t.x;\n"
"\n" "\n"
" vertex rt = rb;\n" " vertex rt = rb;\n"
" rt.p.y = lt.p.y;\n" " rt_p.y = lt_p.y;\n"
" rt.t.y = lt.t.y;\n" " rt.t.y = lt.t.y;\n"
"\n" "\n"
" // Triangle 1\n" " // Triangle 1\n"
" gl_Position = lt.p;\n" " gl_Position = lt_p;\n"
" GSout = lt;\n" " GSout = lt;\n"
" EmitVertex();\n" " EmitVertex();\n"
"\n" "\n"
" gl_Position = lb.p;\n" " gl_Position = lb_p;\n"
" GSout = lb;\n" " GSout = lb;\n"
" EmitVertex();\n" " EmitVertex();\n"
"\n" "\n"
" gl_Position = rt.p;\n" " gl_Position = rt_p;\n"
" GSout = rt;\n" " GSout = rt;\n"
" EmitVertex();\n" " EmitVertex();\n"
"\n" "\n"
" EndPrimitive();\n" " EndPrimitive();\n"
"\n" "\n"
" // Triangle 2\n" " // Triangle 2\n"
" gl_Position = lb.p;\n" " gl_Position = lb_p;\n"
" GSout = lb;\n" " GSout = lb;\n"
" EmitVertex();\n" " EmitVertex();\n"
"\n" "\n"
" gl_Position = rt.p;\n" " gl_Position = rt_p;\n"
" GSout = rt;\n" " GSout = rt;\n"
" EmitVertex();\n" " EmitVertex();\n"
"\n" "\n"
" gl_Position = rb.p;\n" " gl_Position = rb_p;\n"
" GSout = rb;\n" " GSout = rb;\n"
" EmitVertex();\n" " EmitVertex();\n"
"\n" "\n"
@ -323,7 +327,7 @@ static const char* tfx_glsl =
"#ifdef FRAGMENT_SHADER\n" "#ifdef FRAGMENT_SHADER\n"
"#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n" "#if __VERSION__ > 140 && !(defined(NO_STRUCT))\n"
"layout(location = 0) in vertex PSin;\n" "layout(location = 0) in vertex PSin;\n"
"#define PSin_p (PSin.p)\n" "//#define PSin_p (PSin.p)\n"
"#define PSin_t (PSin.t)\n" "#define PSin_t (PSin.t)\n"
"#define PSin_tp (PSin.tp)\n" "#define PSin_tp (PSin.tp)\n"
"#define PSin_c (PSin.c)\n" "#define PSin_c (PSin.c)\n"
@ -334,12 +338,12 @@ static const char* tfx_glsl =
"in vec4 SHADERtp;\n" "in vec4 SHADERtp;\n"
"in vec4 SHADERc;\n" "in vec4 SHADERc;\n"
"#else\n" "#else\n"
"layout(location = 0) in vec4 SHADERp;\n" "//layout(location = 0) in vec4 SHADERp;\n"
"layout(location = 1) in vec4 SHADERt;\n" "layout(location = 0) in vec4 SHADERt;\n"
"layout(location = 2) in vec4 SHADERtp;\n" "layout(location = 1) in vec4 SHADERtp;\n"
"layout(location = 3) in vec4 SHADERc;\n" "layout(location = 2) in vec4 SHADERc;\n"
"#endif\n" "#endif\n"
"#define PSin_p SHADERp\n" "//#define PSin_p SHADERp\n"
"#define PSin_t SHADERt\n" "#define PSin_t SHADERt\n"
"#define PSin_tp SHADERtp\n" "#define PSin_tp SHADERtp\n"
"#define PSin_c SHADERc\n" "#define PSin_c SHADERc\n"