From efcb015361e4d44980af7177047723f07a579b8c Mon Sep 17 00:00:00 2001 From: "gregory.hainaut" Date: Sat, 1 Jun 2013 09:29:57 +0000 Subject: [PATCH] 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 --- plugins/GSdx/GLLoader.cpp | 20 +++------ plugins/GSdx/GSDeviceOGL.cpp | 80 ++++++++++------------------------ plugins/GSdx/GSDeviceOGL.h | 3 -- plugins/GSdx/GSLinuxDialog.cpp | 42 +++++++++--------- plugins/GSdx/GSTextureOGL.cpp | 45 ++++++++++--------- plugins/GSdx/GSWndEGL.cpp | 28 +----------- plugins/GSdx/linux_replay.cpp | 9 ++-- plugins/GSdx/res/tfx.glsl | 50 +++++++++++---------- plugins/GSdx/res/tfx.h | 50 +++++++++++---------- 9 files changed, 131 insertions(+), 196 deletions(-) diff --git a/plugins/GSdx/GLLoader.cpp b/plugins/GSdx/GLLoader.cpp index 810507c8ab..c08d1c05d2 100644 --- a/plugins/GSdx/GLLoader.cpp +++ b/plugins/GSdx/GLLoader.cpp @@ -228,31 +228,21 @@ namespace GLLoader { string ext((const char*)gl_GetStringi(GL_EXTENSIONS, i)); if (ext.compare("GL_ARB_separate_shader_objects") == 0) { 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) { - 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_shading_language_420pack") == 0) 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; // Replace previous extensions (when driver will be updated) - if (ext.compare("GL_ARB_copy_image") == 0) { - found_GL_ARB_copy_image = true; - } - fprintf(stderr, "EXT: %s\n", ext.c_str()); + if (ext.compare("GL_ARB_copy_image") == 0) found_GL_ARB_copy_image = true; } } if (!found_GL_ARB_separate_shader_objects) { fprintf(stderr, "GL_ARB_separate_shader_objects is not supported\n"); - //return false; } if (!found_GL_ARB_shading_language_420pack) { fprintf(stderr, "GL_ARB_shading_language_420pack is not supported\n"); - //return false; } if (!found_GL_ARB_texture_storage) { fprintf(stderr, "GL_ARB_texture_storage is not supported\n"); diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 3c6cbbf1c7..84752404bb 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -50,8 +50,6 @@ GSDeviceOGL::GSDeviceOGL() , m_fbo(0) , m_fbo_read(0) , m_vb_sr(NULL) - , m_srv_changed(false) - , m_ss_changed(false) { 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) { - GLuint fbo_old = m_state.fbo; + glDisable(GL_SCISSOR_TEST); if (static_cast(t)->IsBackbuffer()) { - // FIXME I really not sure 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); - // code for the old interface - // glClearColor(c.x, c.y, c.z, c.w); - // glClear(GL_COLOR_BUFFER_BIT); } else { - // FIXME1 I need to clarify this FBO attachment stuff - // I would like to avoid FBO for a basic clean operation OMSetFBO(m_fbo); static_cast(t)->Attach(GL_COLOR_ATTACHMENT0); + gl_ClearBufferfv(GL_COLOR, 0, c.v); } - OMSetFBO(fbo_old); + glEnable(GL_SCISSOR_TEST); } 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) { - 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); static_cast(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); if (m_state.dss != NULL && m_state.dss->IsMaskEnable()) { gl_ClearBufferfv(GL_DEPTH, 0, &c); @@ -763,20 +753,17 @@ void GSDeviceOGL::ClearDepth(GSTexture* t, float c) glDepthMask(false); } glEnable(GL_SCISSOR_TEST); - OMSetFBO(fbo_old); } 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); static_cast(t)->Attach(GL_DEPTH_STENCIL_ATTACHMENT); GLint color = c; - // FIXME can you clean depth and stencil separately + + glDisable(GL_SCISSOR_TEST); gl_ClearBufferiv(GL_STENCIL, 0, &color); - OMSetFBO(fbo_old); + glEnable(GL_SCISSOR_TEST); } 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); 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()); gl_BindFramebuffer(GL_READ_FRAMEBUFFER, 0); @@ -1182,7 +1169,7 @@ void GSDeviceOGL::IASetPrimitiveTopology(GLenum topology) void GSDeviceOGL::VSSetShader(GLuint vs) { - if(m_state.vs != vs) + if (m_state.vs != vs) { m_state.vs = vs; if (GLLoader::found_GL_ARB_separate_shader_objects) @@ -1192,7 +1179,7 @@ void GSDeviceOGL::VSSetShader(GLuint vs) void GSDeviceOGL::GSSetShader(GLuint gs) { - if(m_state.gs != gs) + if (m_state.gs != gs) { m_state.gs = gs; if (GLLoader::found_GL_ARB_separate_shader_objects) @@ -1211,53 +1198,34 @@ void GSDeviceOGL::PSSetShaderResource(int i, GSTexture* sr) { GSTextureOGL* srv = static_cast(sr); - if(m_state.ps_srv[i] != srv) + if (m_state.ps_srv[i] != srv) { m_state.ps_srv[i] = srv; - - m_srv_changed = true; + if (srv != NULL) + m_state.ps_srv[i]->EnableUnit(i); } } 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 || m_state.ps_ss[1] != ss1 || m_state.ps_ss[2] != ss2) - { + if (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[2] = ss2; - - m_ss_changed = true; + gl_BindSampler(1, ss1); } } void GSDeviceOGL::PSSetShader(GLuint ps) { - if(m_state.ps != ps) + if (m_state.ps != ps) { m_state.ps = ps; if (GLLoader::found_GL_ARB_separate_shader_objects) 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) @@ -1278,7 +1246,7 @@ void GSDeviceOGL::OMSetFBO(GLuint fbo, GLenum buffer) void GSDeviceOGL::OMSetDepthStencilState(GSDepthStencilOGL* dss, uint8 sref) { - if(m_state.dss != dss) { + if (m_state.dss != dss) { m_state.dss = dss; m_state.sref = sref; @@ -1294,7 +1262,7 @@ void GSDeviceOGL::OMSetDepthStencilState(GSDepthStencilOGL* dss, uint8 sref) void GSDeviceOGL::OMSetBlendState(GSBlendStateOGL* bs, float bf) { - if( m_state.bs != bs || (m_state.bf != bf && bs->HasConstantFactor()) ) + if ( m_state.bs != bs || (m_state.bf != bf && bs->HasConstantFactor()) ) { m_state.bs = bs; m_state.bf = bf; diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 16b4f3eb3e..d671bf6556 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -551,9 +551,6 @@ class GSDeviceOGL : public GSDevice GLenum draw; } m_state; - bool m_srv_changed; - bool m_ss_changed; - hash_map m_vs; hash_map m_gs; hash_map m_ps; diff --git a/plugins/GSdx/GSLinuxDialog.cpp b/plugins/GSdx/GSLinuxDialog.cpp index c74b0cc823..b8d2af2005 100644 --- a/plugins/GSdx/GSLinuxDialog.cpp +++ b/plugins/GSdx/GSLinuxDialog.cpp @@ -24,7 +24,7 @@ #include "GSdx.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 *sb_contrast, *sb_brightness, *sb_saturation; 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), "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; } @@ -152,11 +152,8 @@ GtkWidget* CreateFilterComboBox() void toggle_widget_states( GtkWidget *widget, gpointer callback_data ) { - int render_type; - bool hardware_render = false, software_render = false, null_render = false; - - render_type = gtk_combo_box_get_active(GTK_COMBO_BOX(render_combo_box)); - hardware_render = ((render_type % 3) == 1); + int render_type = gtk_combo_box_get_active(GTK_COMBO_BOX(render_combo_box)); + bool hardware_render = ((render_type % 3) == 1); 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))) { - 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(resy_spin, false); } 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(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(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(resy_spin, false); @@ -229,10 +226,10 @@ bool RunLinuxDialog() { GtkWidget *dialog; 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 *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_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_res_check, false, false, 5); - msaa_label = gtk_label_new("Or Use Scaling (broken):"); - msaa_combo_box = CreateMsaaComboBox(); - msaa_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(msaa_box), msaa_combo_box, false, false, 5); + fsaa_label = gtk_label_new("Or Use Scaling (broken):"); + fsaa_combo_box = CreateMsaaComboBox(); + fsaa_box = gtk_hbox_new(false, 5); + gtk_box_pack_start(GTK_BOX(fsaa_box), fsaa_label, false, false, 5); + gtk_box_pack_start(GTK_BOX(fsaa_box), fsaa_combo_box, false, false, 5); rexy_label = gtk_label_new("Custom Resolution:"); 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. 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(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(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); // 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); @@ -484,7 +481,7 @@ bool RunLinuxDialog() 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("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("resy", (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(resy_spin))); @@ -497,6 +494,9 @@ bool RunLinuxDialog() theApp.SetConfig("UserHacks_SpriteHack", (int)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hack_sprite_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)); + + // NOT supported yet + theApp.SetConfig("msaa", 0); // Let's just be windowed for the moment. theApp.SetConfig("windowed", 1); diff --git a/plugins/GSdx/GSTextureOGL.cpp b/plugins/GSdx/GSTextureOGL.cpp index 918682a8a0..b33f10283e 100644 --- a/plugins/GSdx/GSTextureOGL.cpp +++ b/plugins/GSdx/GSTextureOGL.cpp @@ -23,7 +23,7 @@ #include #include "GSTextureOGL.h" 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 // 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 !!! // In worst case the HW renderer seems to use 3 texture unit // For the moment SW renderer only use 1 so don't bother - EnableUnit(0); + EnableUnit(3); if (m_msaa) { ASSERT(m_texture_target == GL_TEXTURE_2D_MULTISAMPLE); // 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() { + /* 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); glDeleteTextures(1, &m_texture_id); } 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); // FIXME DEBUG //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 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 GLenum format; @@ -233,21 +237,18 @@ bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch) void GSTextureOGL::EnableUnit(uint32 unit) { - if (!IsBackbuffer()) { - // FIXME - // Howto allocate the 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 - 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); - } + /* Not a real texture */ + if (IsBackbuffer()) { + return; + } + + 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 if (m_type == GSTexture::Offscreen) { // Bind the texture to the read framebuffer to avoid any disturbance - EnableUnit(0); + EnableUnit(5); gl_BindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read); gl_FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture_target, m_texture_id, 0); glReadBuffer(GL_COLOR_ATTACHMENT0); @@ -444,8 +445,6 @@ bool GSTextureOGL::Save(const string& fn, bool dds) } else if(IsDss()) { 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); 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 { 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); glReadBuffer(GL_COLOR_ATTACHMENT0); diff --git a/plugins/GSdx/GSWndEGL.cpp b/plugins/GSdx/GSWndEGL.cpp index cb9c09029b..6113dabf4b 100644 --- a/plugins/GSdx/GSWndEGL.cpp +++ b/plugins/GSdx/GSWndEGL.cpp @@ -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 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); -#endif XMapWindow (m_NativeDisplay, m_NativeWindow); diff --git a/plugins/GSdx/linux_replay.cpp b/plugins/GSdx/linux_replay.cpp index dea3eb91cd..d6de2f73ed 100644 --- a/plugins/GSdx/linux_replay.cpp +++ b/plugins/GSdx/linux_replay.cpp @@ -34,14 +34,14 @@ int main ( int argc, char *argv[] ) { 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) { fprintf(stderr, "Failed to open plugin %s\n", argv[1]); help(); } - void (*GSsetSettingsDir_ptr)(const char*); - void (*GSReplay_ptr)(char*, int); + __attribute__((stdcall)) void (*GSsetSettingsDir_ptr)(const char*); + __attribute__((stdcall)) void (*GSReplay_ptr)(char*, int); *(void**)(&GSsetSettingsDir_ptr) = dlsym(handle, "GSsetSettingsDir"); *(void**)(&GSReplay_ptr) = dlsym(handle, "GSReplay"); @@ -50,8 +50,7 @@ int main ( int argc, char *argv[] ) (void)GSsetSettingsDir_ptr(argv[3]); } else if ( argc == 3) { #ifdef XDG_STD - std::string home("HOME"); - char * val = getenv( home.c_str() ); + char *val = getenv("HOME"); if (val == NULL) { dlclose(handle); fprintf(stderr, "Failed to get the home dir\n"); diff --git a/plugins/GSdx/res/tfx.glsl b/plugins/GSdx/res/tfx.glsl index b67e18276f..36017dd420 100644 --- a/plugins/GSdx/res/tfx.glsl +++ b/plugins/GSdx/res/tfx.glsl @@ -46,7 +46,7 @@ struct vertex { - vec4 p; + //vec4 p; vec4 t; vec4 tp; vec4 c; @@ -69,17 +69,17 @@ layout(location = 0) out vertex VSout; #define VSout_c (VSout.c) #else #ifdef DISABLE_SSO -out vec4 SHADERp; +//out vec4 SHADERp; out vec4 SHADERt; out vec4 SHADERtp; out vec4 SHADERc; #else -layout(location = 0) out vec4 SHADERp; -layout(location = 1) out vec4 SHADERt; -layout(location = 2) out vec4 SHADERtp; -layout(location = 3) out vec4 SHADERc; +//layout(location = 0) out vec4 SHADERp; +layout(location = 0) out vec4 SHADERt; +layout(location = 1) out vec4 SHADERtp; +layout(location = 2) out vec4 SHADERc; #endif -#define VSout_p SHADERp +//#define VSout_p SHADERp #define VSout_t SHADERt #define VSout_tp SHADERtp #define VSout_c SHADERc @@ -130,7 +130,7 @@ void vs_main() 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 #if VS_RTCOPY VSout_tp = final_p * vec4(0.5, -0.5, 0, 0) + 0.5; @@ -241,46 +241,50 @@ void gs_main() // right bottom => GSin[1]; vertex rb = GSin[1]; 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; #if GS_IIP == 0 lt.c = rb.c; #endif vertex lb = rb; - lb.p.x = lt.p.x; + lb_p.x = lt_p.x; lb.t.x = lt.t.x; vertex rt = rb; - rt.p.y = lt.p.y; + rt_p.y = lt_p.y; rt.t.y = lt.t.y; // Triangle 1 - gl_Position = lt.p; + gl_Position = lt_p; GSout = lt; EmitVertex(); - gl_Position = lb.p; + gl_Position = lb_p; GSout = lb; EmitVertex(); - gl_Position = rt.p; + gl_Position = rt_p; GSout = rt; EmitVertex(); EndPrimitive(); // Triangle 2 - gl_Position = lb.p; + gl_Position = lb_p; GSout = lb; EmitVertex(); - gl_Position = rt.p; + gl_Position = rt_p; GSout = rt; EmitVertex(); - gl_Position = rb.p; + gl_Position = rb_p; GSout = rb; EmitVertex(); @@ -295,7 +299,7 @@ void gs_main() #ifdef FRAGMENT_SHADER #if __VERSION__ > 140 && !(defined(NO_STRUCT)) layout(location = 0) in vertex PSin; -#define PSin_p (PSin.p) +//#define PSin_p (PSin.p) #define PSin_t (PSin.t) #define PSin_tp (PSin.tp) #define PSin_c (PSin.c) @@ -306,12 +310,12 @@ in vec4 SHADERt; in vec4 SHADERtp; in vec4 SHADERc; #else -layout(location = 0) in vec4 SHADERp; -layout(location = 1) in vec4 SHADERt; -layout(location = 2) in vec4 SHADERtp; -layout(location = 3) in vec4 SHADERc; +//layout(location = 0) in vec4 SHADERp; +layout(location = 0) in vec4 SHADERt; +layout(location = 1) in vec4 SHADERtp; +layout(location = 2) in vec4 SHADERc; #endif -#define PSin_p SHADERp +//#define PSin_p SHADERp #define PSin_t SHADERt #define PSin_tp SHADERtp #define PSin_c SHADERc diff --git a/plugins/GSdx/res/tfx.h b/plugins/GSdx/res/tfx.h index abc03efbcb..c6f0216259 100644 --- a/plugins/GSdx/res/tfx.h +++ b/plugins/GSdx/res/tfx.h @@ -74,7 +74,7 @@ static const char* tfx_glsl = "\n" "struct vertex\n" "{\n" - " vec4 p;\n" + " //vec4 p;\n" " vec4 t;\n" " vec4 tp;\n" " vec4 c;\n" @@ -97,17 +97,17 @@ static const char* tfx_glsl = "#define VSout_c (VSout.c)\n" "#else\n" "#ifdef DISABLE_SSO\n" - "out vec4 SHADERp;\n" + "//out vec4 SHADERp;\n" "out vec4 SHADERt;\n" "out vec4 SHADERtp;\n" "out vec4 SHADERc;\n" "#else\n" - "layout(location = 0) out vec4 SHADERp;\n" - "layout(location = 1) out vec4 SHADERt;\n" - "layout(location = 2) out vec4 SHADERtp;\n" - "layout(location = 3) out vec4 SHADERc;\n" + "//layout(location = 0) out vec4 SHADERp;\n" + "layout(location = 0) out vec4 SHADERt;\n" + "layout(location = 1) out vec4 SHADERtp;\n" + "layout(location = 2) out vec4 SHADERc;\n" "#endif\n" - "#define VSout_p SHADERp\n" + "//#define VSout_p SHADERp\n" "#define VSout_t SHADERt\n" "#define VSout_tp SHADERtp\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" " }\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" "#if VS_RTCOPY\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" " vertex rb = GSin[1];\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" - " lt.p.z = rb.p.z;\n" + " lt_p.z = rb_p.z;\n" " lt.t.zw = rb.t.zw;\n" "#if GS_IIP == 0\n" " lt.c = rb.c;\n" "#endif\n" "\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" "\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" "\n" " // Triangle 1\n" - " gl_Position = lt.p;\n" + " gl_Position = lt_p;\n" " GSout = lt;\n" " EmitVertex();\n" "\n" - " gl_Position = lb.p;\n" + " gl_Position = lb_p;\n" " GSout = lb;\n" " EmitVertex();\n" "\n" - " gl_Position = rt.p;\n" + " gl_Position = rt_p;\n" " GSout = rt;\n" " EmitVertex();\n" "\n" " EndPrimitive();\n" "\n" " // Triangle 2\n" - " gl_Position = lb.p;\n" + " gl_Position = lb_p;\n" " GSout = lb;\n" " EmitVertex();\n" "\n" - " gl_Position = rt.p;\n" + " gl_Position = rt_p;\n" " GSout = rt;\n" " EmitVertex();\n" "\n" - " gl_Position = rb.p;\n" + " gl_Position = rb_p;\n" " GSout = rb;\n" " EmitVertex();\n" "\n" @@ -323,7 +327,7 @@ static const char* tfx_glsl = "#ifdef FRAGMENT_SHADER\n" "#if __VERSION__ > 140 && !(defined(NO_STRUCT))\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_tp (PSin.tp)\n" "#define PSin_c (PSin.c)\n" @@ -334,12 +338,12 @@ static const char* tfx_glsl = "in vec4 SHADERtp;\n" "in vec4 SHADERc;\n" "#else\n" - "layout(location = 0) in vec4 SHADERp;\n" - "layout(location = 1) in vec4 SHADERt;\n" - "layout(location = 2) in vec4 SHADERtp;\n" - "layout(location = 3) in vec4 SHADERc;\n" + "//layout(location = 0) in vec4 SHADERp;\n" + "layout(location = 0) in vec4 SHADERt;\n" + "layout(location = 1) in vec4 SHADERtp;\n" + "layout(location = 2) in vec4 SHADERc;\n" "#endif\n" - "#define PSin_p SHADERp\n" + "//#define PSin_p SHADERp\n" "#define PSin_t SHADERt\n" "#define PSin_tp SHADERtp\n" "#define PSin_c SHADERc\n"