From ad870c37f4c615931b5c21887afe01e59d4f6422 Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 22 Aug 2014 19:46:03 +0200 Subject: [PATCH 1/5] Back to previous resolution when escape was pressed in confirm resolution dialog --- src/states_screens/dialogs/confirm_resolution_dialog.cpp | 9 +++++++++ src/states_screens/dialogs/confirm_resolution_dialog.hpp | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/states_screens/dialogs/confirm_resolution_dialog.cpp b/src/states_screens/dialogs/confirm_resolution_dialog.cpp index 36f00240f..c4c1896ab 100644 --- a/src/states_screens/dialogs/confirm_resolution_dialog.cpp +++ b/src/states_screens/dialogs/confirm_resolution_dialog.cpp @@ -64,6 +64,15 @@ void ConfirmResolutionDialog::onUpdate(float dt) } +// ---------------------------------------------------------------------------- + +bool ConfirmResolutionDialog::onEscapePressed() +{ + ModalDialog::dismiss(); + irr_driver->cancelResChange(); + return true; +} // escapePressed + // ------------------------------------------------------------------------------------------------------ void ConfirmResolutionDialog::updateMessage() diff --git a/src/states_screens/dialogs/confirm_resolution_dialog.hpp b/src/states_screens/dialogs/confirm_resolution_dialog.hpp index 5a03bfc72..dc3ad1605 100644 --- a/src/states_screens/dialogs/confirm_resolution_dialog.hpp +++ b/src/states_screens/dialogs/confirm_resolution_dialog.hpp @@ -20,6 +20,7 @@ #define HEADER_CONFIRM_RES_DIALOG_HPP #include "guiengine/modaldialog.hpp" +#include "utils/cpp2011.hpp" /** * \brief Dialog shown after a resolution switch sot he user may confirm if @@ -28,6 +29,7 @@ */ class ConfirmResolutionDialog : public GUIEngine::ModalDialog { +private: /** number of seconds left before resolution is considered unplayable */ float m_remaining_time; @@ -40,6 +42,7 @@ public: GUIEngine::EventPropagation processEvent(const std::string& eventSource); virtual void onUpdate(float dt); + virtual bool onEscapePressed() OVERRIDE; }; From 8711955bdc9297b677759d2b137763b512216820 Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 22 Aug 2014 19:59:30 +0200 Subject: [PATCH 2/5] Fixed onEscapePressed event in addons loading screen. It actually was unused previously. I'm also not sure why there was assert(false) ? --- src/states_screens/dialogs/addons_loading.cpp | 6 +++--- src/states_screens/dialogs/addons_loading.hpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/states_screens/dialogs/addons_loading.cpp b/src/states_screens/dialogs/addons_loading.cpp index 1ebf2f3ad..a4959aafe 100644 --- a/src/states_screens/dialogs/addons_loading.cpp +++ b/src/states_screens/dialogs/addons_loading.cpp @@ -190,11 +190,12 @@ void AddonsLoading::init() } // init // ---------------------------------------------------------------------------- -void AddonsLoading::escapePressed() +bool AddonsLoading::onEscapePressed() { stopDownload(); ModalDialog::dismiss(); -} // escapePressed + return true; +} // onEscapePressed // ---------------------------------------------------------------------------- @@ -335,7 +336,6 @@ void AddonsLoading::stopDownload() // order to avoid a memory leak, we let network_http free // the request. //m_download_request->setManageMemory(true); - assert(false); m_download_request->cancel(); }; } // startDownload diff --git a/src/states_screens/dialogs/addons_loading.hpp b/src/states_screens/dialogs/addons_loading.hpp index fdb7fd5e3..27f52a431 100644 --- a/src/states_screens/dialogs/addons_loading.hpp +++ b/src/states_screens/dialogs/addons_loading.hpp @@ -23,6 +23,7 @@ #include "addons/addons_manager.hpp" #include "guiengine/widgets.hpp" #include "guiengine/modaldialog.hpp" +#include "utils/cpp2011.hpp" #include "utils/synchronised.hpp" namespace Online { class HTTPRequest; } @@ -32,7 +33,6 @@ namespace Online { class HTTPRequest; } */ class AddonsLoading : public GUIEngine::ModalDialog { - virtual void escapePressed(); private: GUIEngine::LabelWidget *m_state; GUIEngine::ProgressBarWidget *m_progress; @@ -70,6 +70,7 @@ public: * */ void onUpdate(float delta); void voteClicked(); + virtual bool onEscapePressed() OVERRIDE; }; // AddonsLoading From 90ecf50414db72ae052ff6db62ec2dc08f3b06dd Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 22 Aug 2014 20:40:22 +0200 Subject: [PATCH 3/5] Show console on windows only in debug mode --- src/main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5f883661e..924590261 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1155,8 +1155,12 @@ void askForInternetPermission() //============================================================================= -#if defined(DEBUG) && defined(WIN32) && !defined(__CYGWIN__) -#pragma comment(linker, "/SUBSYSTEM:console") +#if defined(WIN32) && defined(_MSC_VER) + #ifdef DEBUG + #pragma comment(linker, "/SUBSYSTEM:console") + #else + #pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") + #endif #endif // ---------------------------------------------------------------------------- From bc24c4558feaacae076e179760c397bce2aea418 Mon Sep 17 00:00:00 2001 From: vlj Date: Mon, 18 Aug 2014 10:00:04 +0200 Subject: [PATCH 4/5] Register some api functions --- src/graphics/gl_headers.hpp | 11 +++++++++++ src/graphics/glwrap.cpp | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/graphics/gl_headers.hpp b/src/graphics/gl_headers.hpp index 8d53259c5..a7737c2c0 100644 --- a/src/graphics/gl_headers.hpp +++ b/src/graphics/gl_headers.hpp @@ -72,6 +72,8 @@ extern PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced; extern PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex; extern PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced; extern PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex; +extern PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC glDrawElementsInstancedBaseVertexBaseInstance; +extern PFNGLMULTIDRAWELEMENTSINDIRECTPROC glMultiDrawElementsIndirect; extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; @@ -80,6 +82,9 @@ extern PFNGLTEXBUFFERPROC glTexBuffer; extern PFNGLBUFFERSUBDATAPROC glBufferSubData; extern PFNGLMAPBUFFERPROC glMapBuffer; extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; +extern PFNGLFLUSHMAPPEDBUFFERRANGEPROC glFlushMappedBufferRange; +extern PFNGLMEMORYBARRIERPROC glMemoryBarrier; +extern PFNGLBUFFERSTORAGEPROC glBufferStorage; extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; extern PFNGLFENCESYNCPROC glFenceSync; extern PFNGLCLIENTWAITSYNCPROC glClientWaitSync; @@ -109,6 +114,12 @@ extern PFNGLDELETESAMPLERSPROC glDeleteSamplers; extern PFNGLBINDSAMPLERPROC glBindSampler; extern PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf; extern PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri; +extern PFNGLGETTEXTURESAMPLERHANDLEARBPROC glGetTextureSamplerHandleARB; +extern PFNGLMAKETEXTUREHANDLERESIDENTARBPROC glMakeTextureHandleResidentARB; +extern PFNGLMAKETEXTUREHANDLENONRESIDENTARBPROC glMakeTextureHandleNonResidentARB; +extern PFNGLUNIFORMHANDLEUI64ARBPROC glUniformHandleui64ARB; +extern PFNGLISTEXTUREHANDLERESIDENTARBPROC glIsTextureHandleResidentARB; +extern PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer; #ifdef DEBUG extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; #endif diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 02db147a2..1cc4aa2a3 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -52,6 +52,8 @@ PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced; PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex; PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced; PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex; +PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC glDrawElementsInstancedBaseVertexBaseInstance; +PFNGLMULTIDRAWELEMENTSINDIRECTPROC glMultiDrawElementsIndirect; PFNGLDELETEBUFFERSPROC glDeleteBuffers; PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; PFNGLBINDVERTEXARRAYPROC glBindVertexArray; @@ -60,6 +62,9 @@ PFNGLTEXBUFFERPROC glTexBuffer; PFNGLBUFFERSUBDATAPROC glBufferSubData; PFNGLMAPBUFFERPROC glMapBuffer; PFNGLMAPBUFFERRANGEPROC glMapBufferRange; +PFNGLFLUSHMAPPEDBUFFERRANGEPROC glFlushMappedBufferRange; +PFNGLMEMORYBARRIERPROC glMemoryBarrier; +PFNGLBUFFERSTORAGEPROC glBufferStorage; PFNGLUNMAPBUFFERPROC glUnmapBuffer; PFNGLFENCESYNCPROC glFenceSync; PFNGLCLIENTWAITSYNCPROC glClientWaitSync; @@ -91,6 +96,12 @@ PFNGLBINDSAMPLERPROC glBindSampler; PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf; PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri; PFNGLGETSTRINGIPROC glGetStringi; +PFNGLGETTEXTURESAMPLERHANDLEARBPROC glGetTextureSamplerHandleARB; +PFNGLMAKETEXTUREHANDLERESIDENTARBPROC glMakeTextureHandleResidentARB; +PFNGLMAKETEXTUREHANDLENONRESIDENTARBPROC glMakeTextureHandleNonResidentARB; +PFNGLUNIFORMHANDLEUI64ARBPROC glUniformHandleui64ARB; +PFNGLISTEXTUREHANDLERESIDENTARBPROC glIsTextureHandleResidentARB; +PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer; #endif static bool is_gl_init = false; @@ -192,6 +203,9 @@ void initGL() glBufferData = (PFNGLBUFFERDATAPROC)IRR_OGL_LOAD_EXTENSION("glBufferData"); glMapBuffer = (PFNGLMAPBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glMapBuffer"); glMapBufferRange = (PFNGLMAPBUFFERRANGEPROC)IRR_OGL_LOAD_EXTENSION("glMapBufferRange"); + glFlushMappedBufferRange = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC)IRR_OGL_LOAD_EXTENSION("glFlushMappedBufferRange"); + glMemoryBarrier = (PFNGLMEMORYBARRIERPROC)IRR_OGL_LOAD_EXTENSION("glMemoryBarrier"); + glBufferStorage = (PFNGLBUFFERSTORAGEPROC)IRR_OGL_LOAD_EXTENSION("glBufferStorage"); glUnmapBuffer = (PFNGLUNMAPBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glUnmapBuffer"); glFenceSync = (PFNGLFENCESYNCPROC)IRR_OGL_LOAD_EXTENSION("glFenceSync"); glClientWaitSync = (PFNGLCLIENTWAITSYNCPROC)IRR_OGL_LOAD_EXTENSION("glClientWaitSync"); @@ -229,6 +243,8 @@ void initGL() glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC)IRR_OGL_LOAD_EXTENSION("glDrawElementsBaseVertex"); glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC)IRR_OGL_LOAD_EXTENSION("glDrawElementsInstanced"); glDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC)IRR_OGL_LOAD_EXTENSION("glDrawElementsInstancedBaseVertex"); + glDrawElementsInstancedBaseVertexBaseInstance = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC)IRR_OGL_LOAD_EXTENSION("glDrawElementsInstancedBaseVertexBaseInstance"); + glMultiDrawElementsIndirect = (PFNGLMULTIDRAWELEMENTSINDIRECTPROC)IRR_OGL_LOAD_EXTENSION("glMultiDrawElementsIndirect"); glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glDeleteBuffers"); glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)IRR_OGL_LOAD_EXTENSION("glGenVertexArrays"); glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)IRR_OGL_LOAD_EXTENSION("glBindVertexArray"); @@ -264,6 +280,12 @@ void initGL() glSamplerParameterf = (PFNGLSAMPLERPARAMETERFPROC)IRR_OGL_LOAD_EXTENSION("glSamplerParameterf"); glSamplerParameteri = (PFNGLSAMPLERPARAMETERIPROC)IRR_OGL_LOAD_EXTENSION("glSamplerParameteri"); glGetStringi = (PFNGLGETSTRINGIPROC)IRR_OGL_LOAD_EXTENSION("glGetstringi"); + glGetTextureSamplerHandleARB = (PFNGLGETTEXTURESAMPLERHANDLEARBPROC)IRR_OGL_LOAD_EXTENSION("glGetTextureSamplerHandleARB"); + glMakeTextureHandleResidentARB = (PFNGLMAKETEXTUREHANDLERESIDENTARBPROC)IRR_OGL_LOAD_EXTENSION("glMakeTextureHandleResidentARB"); + glMakeTextureHandleNonResidentARB = (PFNGLMAKETEXTUREHANDLENONRESIDENTARBPROC)IRR_OGL_LOAD_EXTENSION("glMakeTextureHandleNonResidentARB"); + glUniformHandleui64ARB = (PFNGLUNIFORMHANDLEUI64ARBPROC)IRR_OGL_LOAD_EXTENSION("glUniformHandleui64ARB"); + glIsTextureHandleResidentARB = (PFNGLISTEXTUREHANDLERESIDENTARBPROC)IRR_OGL_LOAD_EXTENSION("glIsTextureHandleResidentARB"); + glVertexAttribLPointer = (PFNGLVERTEXATTRIBLPOINTERPROC)IRR_OGL_LOAD_EXTENSION("glVertexAttribLPointer"); #ifdef DEBUG glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC)IRR_OGL_LOAD_EXTENSION("glDebugMessageCallbackARB"); #endif From 6ac3d6947123f408b5ca1ad10fa274b822c39280 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 18 Aug 2014 17:49:44 +0200 Subject: [PATCH 5/5] Play with bindless textures --- data/shaders/detailledobject_pass2.frag | 8 + data/shaders/grass_pass2.frag | 11 +- data/shaders/header.txt | 2 +- data/shaders/normalmap.frag | 5 + data/shaders/object_pass1.frag | 4 + data/shaders/object_pass2.frag | 8 + data/shaders/object_unlit.frag | 7 + data/shaders/objectpass_spheremap.frag | 7 + data/shaders/objectref_pass1.frag | 4 + data/shaders/objectref_pass2.frag | 7 + data/shaders/splatting.frag | 14 ++ data/shaders/transparent.frag | 7 + data/shaders/transparentfog.frag | 8 + data/shaders/utils/getLightFactor.frag | 6 + src/config/user_config.hpp | 3 + src/graphics/gl_headers.hpp | 5 + src/graphics/glwrap.cpp | 7 + src/graphics/render_geometry.cpp | 229 +++++++++++++++++------- src/graphics/shaders.cpp | 63 ++----- src/graphics/shaders.hpp | 34 ++-- src/graphics/stkmesh.hpp | 1 + src/graphics/stkmeshscenenode.cpp | 26 ++- 22 files changed, 337 insertions(+), 129 deletions(-) diff --git a/data/shaders/detailledobject_pass2.frag b/data/shaders/detailledobject_pass2.frag index 6d9a94c04..18372dfab 100644 --- a/data/shaders/detailledobject_pass2.frag +++ b/data/shaders/detailledobject_pass2.frag @@ -1,5 +1,10 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D Albedo; +layout(bindless_sampler) uniform sampler2D Detail; +#else uniform sampler2D Albedo; uniform sampler2D Detail; +#endif #if __VERSION__ >= 130 in vec2 uv; @@ -16,6 +21,9 @@ vec3 getLightFactor(float specMapValue); void main(void) { vec4 color = texture(Albedo, uv); +#ifdef GL_ARB_bindless_texture + color.xyz = pow(color.xyz, vec3(2.2)); +#endif vec4 detail = texture(Detail, uv_bis); color *= detail; vec3 LightFactor = getLightFactor(1. - color.a); diff --git a/data/shaders/grass_pass2.frag b/data/shaders/grass_pass2.frag index 663232a72..b8e5e256c 100644 --- a/data/shaders/grass_pass2.frag +++ b/data/shaders/grass_pass2.frag @@ -1,6 +1,12 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D Albedo; +layout(bindless_sampler) uniform sampler2D dtex; +#else uniform sampler2D Albedo; -uniform vec3 SunDir; uniform sampler2D dtex; +#endif + +uniform vec3 SunDir; in vec3 nor; in vec2 uv; @@ -26,6 +32,9 @@ void main(void) float scattering = mix(fPowEdotL, fLdotNBack, .5); vec4 color = texture(Albedo, uv); +#ifdef GL_ARB_bindless_texture + color.xyz = pow(color.xyz, vec3(2.2)); +#endif if (color.a < 0.5) discard; vec3 LightFactor = (scattering * 0.3) + getLightFactor(1.); FragColor = vec4(color.xyz * LightFactor, 1.); diff --git a/data/shaders/header.txt b/data/shaders/header.txt index 74a2cb81b..ec5c45115 100644 --- a/data/shaders/header.txt +++ b/data/shaders/header.txt @@ -14,4 +14,4 @@ layout (std140) uniform MatrixesData mat4 ShadowViewProjMatrixes[4]; vec2 screen; }; -#endif +#endif \ No newline at end of file diff --git a/data/shaders/normalmap.frag b/data/shaders/normalmap.frag index 255942efd..e7ba8efe4 100644 --- a/data/shaders/normalmap.frag +++ b/data/shaders/normalmap.frag @@ -1,5 +1,10 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D normalMap; +layout(bindless_sampler) uniform sampler2D DiffuseForAlpha; +#else uniform sampler2D normalMap; uniform sampler2D DiffuseForAlpha; +#endif in vec3 tangent; in vec3 bitangent; diff --git a/data/shaders/object_pass1.frag b/data/shaders/object_pass1.frag index e8e0df6ba..cd193b5ec 100644 --- a/data/shaders/object_pass1.frag +++ b/data/shaders/object_pass1.frag @@ -1,4 +1,8 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D tex; +#else uniform sampler2D tex; +#endif #if __VERSION__ >= 130 in vec3 nor; diff --git a/data/shaders/object_pass2.frag b/data/shaders/object_pass2.frag index d45ca01fb..f1b2200ad 100644 --- a/data/shaders/object_pass2.frag +++ b/data/shaders/object_pass2.frag @@ -1,4 +1,8 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D Albedo; +#else uniform sampler2D Albedo; +#endif in vec2 uv; in vec4 color; @@ -8,7 +12,11 @@ vec3 getLightFactor(float specMapValue); void main(void) { +#ifdef GL_ARB_bindless_texture + vec4 col = pow(texture(Albedo, uv), vec4(2.2)); +#else vec4 col = texture(Albedo, uv); +#endif col.xyz *= pow(color.xyz, vec3(2.2)); vec3 LightFactor = getLightFactor(1.); FragColor = vec4(col.xyz * LightFactor, 1.); diff --git a/data/shaders/object_unlit.frag b/data/shaders/object_unlit.frag index bf5c5f3c9..f13fc0812 100644 --- a/data/shaders/object_unlit.frag +++ b/data/shaders/object_unlit.frag @@ -1,4 +1,8 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D tex; +#else uniform sampler2D tex; +#endif in vec2 uv; in vec4 color; @@ -7,6 +11,9 @@ out vec4 FragColor; void main(void) { vec4 col = texture(tex, uv); +#ifdef GL_ARB_bindless_texture + col.xyz = pow(col.xyz, vec3(2.2)); +#endif col.xyz *= pow(color.xyz, vec3(2.2)); if (col.a < 0.5) discard; FragColor = vec4(col.xyz, 1.); diff --git a/data/shaders/objectpass_spheremap.frag b/data/shaders/objectpass_spheremap.frag index 138936d23..025151184 100644 --- a/data/shaders/objectpass_spheremap.frag +++ b/data/shaders/objectpass_spheremap.frag @@ -1,6 +1,10 @@ // See http://www.ozone3d.net/tutorials/glsl_texturing_p04.php for ref +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D tex; +#else uniform sampler2D tex; +#endif #if __VERSION__ >= 130 in vec3 nor; @@ -21,6 +25,9 @@ void main() { float m = 2.0 * sqrt(r.x * r.x + r.y * r.y + (r.z + 1.0) * (r.z + 1.0)); r.y = - r.y; vec4 detail0 = texture(tex, r.xy / m + .5); +#ifdef GL_ARB_bindless_texture + detail0.xyz = pow(detail0.xyz, vec3(2.2)); +#endif vec3 LightFactor = getLightFactor(1.); FragColor = vec4(detail0.xyz * LightFactor, 1.); diff --git a/data/shaders/objectref_pass1.frag b/data/shaders/objectref_pass1.frag index f4cf55e29..7738e82b8 100644 --- a/data/shaders/objectref_pass1.frag +++ b/data/shaders/objectref_pass1.frag @@ -1,4 +1,8 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D tex; +#else uniform sampler2D tex; +#endif #if __VERSION__ >= 130 in vec3 nor; diff --git a/data/shaders/objectref_pass2.frag b/data/shaders/objectref_pass2.frag index c20b7e82e..7ee2d3de0 100644 --- a/data/shaders/objectref_pass2.frag +++ b/data/shaders/objectref_pass2.frag @@ -1,4 +1,8 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D Albedo; +#else uniform sampler2D Albedo; +#endif in vec2 uv; in vec4 color; @@ -9,6 +13,9 @@ vec3 getLightFactor(float specMapValue); void main(void) { vec4 col = texture(Albedo, uv); +#ifdef GL_ARB_bindless_texture + col.xyz = pow(col.xyz, vec3(2.2)); +#endif col.xyz *= pow(color.xyz, vec3(2.2)); if (col.a * color.a < 0.5) discard; vec3 LightFactor = getLightFactor(1.); diff --git a/data/shaders/splatting.frag b/data/shaders/splatting.frag index d8bdc0555..ccb957cd7 100644 --- a/data/shaders/splatting.frag +++ b/data/shaders/splatting.frag @@ -1,8 +1,16 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D tex_layout; +layout(bindless_sampler) uniform sampler2D tex_detail0; +layout(bindless_sampler) uniform sampler2D tex_detail1; +layout(bindless_sampler) uniform sampler2D tex_detail2; +layout(bindless_sampler) uniform sampler2D tex_detail3; +#else uniform sampler2D tex_layout; uniform sampler2D tex_detail0; uniform sampler2D tex_detail1; uniform sampler2D tex_detail2; uniform sampler2D tex_detail3; +#endif #if __VERSION__ >= 130 in vec2 uv; @@ -24,6 +32,12 @@ void main() { vec4 detail2 = texture(tex_detail2, uv); vec4 detail3 = texture(tex_detail3, uv); vec4 detail4 = vec4(0.0); +#ifdef GL_ARB_bindless_texture + detail0.xyz = pow(detail0.xyz, vec3(2.2)); + detail1.xyz = pow(detail1.xyz, vec3(2.2)); + detail2.xyz = pow(detail2.xyz, vec3(2.2)); + detail3.xyz = pow(detail3.xyz, vec3(2.2)); +#endif vec4 splatted = splatting.r * detail0 + splatting.g * detail1 + diff --git a/data/shaders/transparent.frag b/data/shaders/transparent.frag index aaeba0601..5c84fee03 100644 --- a/data/shaders/transparent.frag +++ b/data/shaders/transparent.frag @@ -1,4 +1,8 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D tex; +#else uniform sampler2D tex; +#endif in vec2 uv; in vec4 color; @@ -8,6 +12,9 @@ out vec4 FragColor; void main() { vec4 Color = texture(tex, uv); +#ifdef GL_ARB_bindless_texture + Color.xyz = pow(Color.xyz, vec3(2.2)); +#endif Color.xyz *= pow(color.xyz, vec3(2.2)); Color.a *= color.a; // Premultiply alpha diff --git a/data/shaders/transparentfog.frag b/data/shaders/transparentfog.frag index d6f0f3344..b73a06fdf 100644 --- a/data/shaders/transparentfog.frag +++ b/data/shaders/transparentfog.frag @@ -1,4 +1,9 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D tex; +#else uniform sampler2D tex; +#endif + uniform float fogmax; uniform float startH; @@ -15,6 +20,9 @@ out vec4 FragColor; void main() { vec4 diffusecolor = texture(tex, uv); +#ifdef GL_ARB_bindless_texture + diffusecolor.xyz = pow(diffusecolor.xyz, vec3(2.2)); +#endif diffusecolor.xyz *= pow(color.xyz, vec3(2.2)); diffusecolor.a *= color.a; vec3 tmp = vec3(gl_FragCoord.xy / screen, gl_FragCoord.z); diff --git a/data/shaders/utils/getLightFactor.frag b/data/shaders/utils/getLightFactor.frag index ec7fa5725..9bf4cdf58 100644 --- a/data/shaders/utils/getLightFactor.frag +++ b/data/shaders/utils/getLightFactor.frag @@ -1,6 +1,12 @@ +#ifdef GL_ARB_bindless_texture +layout(bindless_sampler) uniform sampler2D DiffuseMap; +layout(bindless_sampler) uniform sampler2D SpecularMap; +layout(bindless_sampler) uniform sampler2D SSAO; +#else uniform sampler2D DiffuseMap; uniform sampler2D SpecularMap; uniform sampler2D SSAO; +#endif vec3 getLightFactor(float specMapValue) { diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index ae91e0b4d..88647b820 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -464,6 +464,9 @@ namespace UserConfigParams PARAM_PREFIX BoolUserConfigParam m_gi PARAM_DEFAULT(BoolUserConfigParam(false, "enable_gi", &m_video_group, "Enable Global Illumination")); + PARAM_PREFIX BoolUserConfigParam m_bindless_textures + PARAM_DEFAULT(BoolUserConfigParam(false, "enable_bindless_textures", + &m_video_group, "Enable Bindless Texture (Experimental !)")); // ---- Debug - not saved to config file /** If gamepad debugging is enabled. */ diff --git a/src/graphics/gl_headers.hpp b/src/graphics/gl_headers.hpp index a7737c2c0..81789ddf2 100644 --- a/src/graphics/gl_headers.hpp +++ b/src/graphics/gl_headers.hpp @@ -125,4 +125,9 @@ extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; #endif #endif + +#ifdef WIN32 +#define Bindless_Texture_Support +#endif + #endif \ No newline at end of file diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 1cc4aa2a3..c8b44bd5c 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -319,6 +319,13 @@ GLuint LoadShader(const char * file, unsigned type) char versionString[20]; sprintf(versionString, "#version %d\n", irr_driver->getGLSLVersion()); std::string Code = versionString; + if (UserConfigParams::m_bindless_textures) + Code += "#extension GL_ARB_bindless_texture : enable\n"; + else + { + Code += "#extension GL_ARB_bindless_texture : disable\n"; + Code += "#undef GL_ARB_bindless_texture\n"; + } std::ifstream Stream(file, std::ios::in); Code += "//" + std::string(file) + "\n"; if (irr_driver->needUBOWorkaround()) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 381338745..ae9d00c1d 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -123,13 +123,25 @@ void renderMeshes1stPass(const std::vector &TexUnits, std::vectorsize(); i++) { std::vector Textures; + std::vector Handles; GLMesh &mesh = *(STK::tuple_get<0>(meshes->at(i))); for (unsigned j = 0; j < TexUnits.size(); j++) { - if (!mesh.textures[j]) + if (!mesh.textures[TexUnits[j].m_id]) mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255)); - compressTexture(mesh.textures[j], TexUnits[j].m_premul_alpha); - Textures.push_back(getTextureGLuint(mesh.textures[TexUnits[j].m_id])); + compressTexture(mesh.textures[TexUnits[j].m_id], TexUnits[j].m_premul_alpha); + if (UserConfigParams::m_bindless_textures) + { +#ifdef Bindless_Texture_Support + if (!mesh.TextureHandles[TexUnits[j].m_id]) + mesh.TextureHandles[TexUnits[j].m_id] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[TexUnits[j].m_id]), Shader::getInstance()->SamplersId[j]); + if (!glIsTextureHandleResidentARB(mesh.TextureHandles[TexUnits[j].m_id])) + glMakeTextureHandleResidentARB(mesh.TextureHandles[TexUnits[j].m_id]); +#endif + Handles.push_back(mesh.TextureHandles[TexUnits[j].m_id]); + } + else + Textures.push_back(getTextureGLuint(mesh.textures[TexUnits[j].m_id])); } if (mesh.VAOType != VertexType) { @@ -138,7 +150,11 @@ void renderMeshes1stPass(const std::vector &TexUnits, std::vectorSetTextureUnits(Textures); + + if (UserConfigParams::m_bindless_textures) + Shader::getInstance()->SetTextureHandles(Handles); + else + Shader::getInstance()->SetTextureUnits(Textures); custom_unroll_args::template exec(Shader::getInstance(), meshes->at(i)); } } @@ -180,6 +196,7 @@ void renderInstancedMeshes1stPass(const std::vector &TexUnits, std::vec glUseProgram(Shader::getInstance()->Program); for (unsigned i = 0; i < meshes->size(); i++) { + std::vector Handles; std::vector Textures; GLMesh &mesh = *(STK::tuple_get<0>(meshes->at(i))); #ifdef DEBUG @@ -192,9 +209,23 @@ void renderInstancedMeshes1stPass(const std::vector &TexUnits, std::vec if (!mesh.textures[TexUnits[j].m_id]) mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255)); compressTexture(mesh.textures[TexUnits[j].m_id], TexUnits[j].m_premul_alpha); - Textures.push_back(getTextureGLuint(mesh.textures[TexUnits[j].m_id])); + if (UserConfigParams::m_bindless_textures) + { +#ifdef Bindless_Texture_Support + if (!mesh.TextureHandles[TexUnits[j].m_id]) + mesh.TextureHandles[TexUnits[j].m_id] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[TexUnits[j].m_id]), Shader::getInstance()->SamplersId[j]); + if (!glIsTextureHandleResidentARB(mesh.TextureHandles[TexUnits[j].m_id])) + glMakeTextureHandleResidentARB(mesh.TextureHandles[TexUnits[j].m_id]); +#endif + Handles.push_back(mesh.TextureHandles[TexUnits[j].m_id]); + } + else + Textures.push_back(getTextureGLuint(mesh.textures[TexUnits[j].m_id])); } - Shader::getInstance()->SetTextureUnits(Textures); + if (UserConfigParams::m_bindless_textures) + Shader::getInstance()->SetTextureHandles(Handles); + else + Shader::getInstance()->SetTextureUnits(Textures); instanced_custom_unroll_args::template exec(Shader::getInstance(), meshes->at(i)); } } @@ -291,21 +322,34 @@ void IrrDriver::renderSolidFirstPass() } template -void renderMeshes2ndPass(const std::vector &TexUnits, std::vector > *meshes) +void renderMeshes2ndPass(const std::vector &TexUnits, std::vector > *meshes, const std::vector &Prefilled_Handle, + const std::vector &Prefilled_Tex) { glUseProgram(Shader::getInstance()->Program); glBindVertexArray(VAOManager::getInstance()->getVAO(VertexType)); for (unsigned i = 0; i < meshes->size(); i++) { - std::vector Textures; + std::vector Handles(Prefilled_Handle); + std::vector Textures(Prefilled_Tex); GLMesh &mesh = *(STK::tuple_get<0>(meshes->at(i))); for (unsigned j = 0; j < TexUnits.size(); j++) { if (!mesh.textures[TexUnits[j].m_id]) mesh.textures[TexUnits[j].m_id] = getUnicolorTexture(video::SColor(255, 255, 255, 255)); compressTexture(mesh.textures[TexUnits[j].m_id], TexUnits[j].m_premul_alpha); - Textures.push_back(getTextureGLuint(mesh.textures[TexUnits[j].m_id])); - if (irr_driver->getLightViz()) + if (UserConfigParams::m_bindless_textures) + { +#ifdef Bindless_Texture_Support + if (!mesh.TextureHandles[TexUnits[j].m_id]) + mesh.TextureHandles[TexUnits[j].m_id] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[TexUnits[j].m_id]), Shader::getInstance()->SamplersId[Handles.size()]); + if (!glIsTextureHandleResidentARB(mesh.TextureHandles[TexUnits[j].m_id])) + glMakeTextureHandleResidentARB(mesh.TextureHandles[TexUnits[j].m_id]); + Handles.push_back(mesh.TextureHandles[TexUnits[j].m_id]); +#endif + } + else + Textures.push_back(getTextureGLuint(mesh.textures[TexUnits[j].m_id])); +/* if (irr_driver->getLightViz()) { GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); @@ -314,7 +358,7 @@ void renderMeshes2ndPass(const std::vector &TexUnits, std::vector &TexUnits, std::vectorSetTextureUnits(Textures); + + if (UserConfigParams::m_bindless_textures) + Shader::getInstance()->SetTextureHandles(Handles); + else + Shader::getInstance()->SetTextureUnits(Textures); custom_unroll_args::template exec(Shader::getInstance(), meshes->at(i)); } } template -void renderInstancedMeshes2ndPass(const std::vector &TexUnits, std::vector > *meshes) +void renderInstancedMeshes2ndPass(const std::vector &TexUnits, std::vector > *meshes, const std::vector &Prefilled_Handles, + const std::vector &Prefilled_tex) { glUseProgram(Shader::getInstance()->Program); for (unsigned i = 0; i < meshes->size(); i++) { GLMesh &mesh = *(STK::tuple_get<0>(meshes->at(i))); glBindVertexArray(mesh.vao); - std::vector Textures; + + std::vector Textures(Prefilled_tex); + std::vector Handles(Prefilled_Handles); + for (unsigned j = 0; j < TexUnits.size(); j++) { if (!mesh.textures[TexUnits[j].m_id]) mesh.textures[TexUnits[j].m_id] = getUnicolorTexture(video::SColor(255, 255, 255, 255)); compressTexture(mesh.textures[TexUnits[j].m_id], TexUnits[j].m_premul_alpha); - Textures.push_back(getTextureGLuint(mesh.textures[TexUnits[j].m_id])); - if (irr_driver->getLightViz()) +#ifdef Bindless_Texture_Support + if (!mesh.TextureHandles[TexUnits[j].m_id]) + mesh.TextureHandles[TexUnits[j].m_id] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[TexUnits[j].m_id]), Shader::getInstance()->SamplersId[Handles.size()]); + if (!glIsTextureHandleResidentARB(mesh.TextureHandles[TexUnits[j].m_id])) + glMakeTextureHandleResidentARB(mesh.TextureHandles[TexUnits[j].m_id]); +#endif + if (UserConfigParams::m_bindless_textures) + Handles.push_back(mesh.TextureHandles[TexUnits[j].m_id]); + else + Textures.push_back(getTextureGLuint(mesh.textures[TexUnits[j].m_id])); +/* if (irr_driver->getLightViz()) { GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); @@ -353,9 +414,14 @@ void renderInstancedMeshes2ndPass(const std::vector &TexUnits, std::vec { GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - } + }*/ } - Shader::getInstance()->SetTextureUnits(Textures); + + if (UserConfigParams::m_bindless_textures) + Shader::getInstance()->SetTextureHandles(Handles); + else + Shader::getInstance()->SetTextureUnits(Textures); + instanced_custom_unroll_args::template exec(Shader::getInstance(), meshes->at(i)); } } @@ -382,64 +448,74 @@ void IrrDriver::renderSolidSecondPass() glEnable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); -#ifdef GL_VERSION_3_3 - if (irr_driver->getGLSLVersion() >= 330) - glBindSampler(0, 0); + + uint64_t DiffuseHandle = 0, SpecularHandle = 0, SSAOHandle = 0, DepthHandle = 0; + + if (UserConfigParams::m_bindless_textures) + { +#ifdef Bindless_Texture_Support + DiffuseHandle = glGetTextureSamplerHandleARB(m_rtts->getRenderTarget(RTT_DIFFUSE), MeshShader::ObjectPass2Shader::getInstance()->SamplersId[0]); + if (!glIsTextureHandleResidentARB(DiffuseHandle)) + glMakeTextureHandleResidentARB(DiffuseHandle); + + SpecularHandle = glGetTextureSamplerHandleARB(m_rtts->getRenderTarget(RTT_SPECULAR), MeshShader::ObjectPass2Shader::getInstance()->SamplersId[1]); + if (!glIsTextureHandleResidentARB(SpecularHandle)) + glMakeTextureHandleResidentARB(SpecularHandle); + + SSAOHandle = glGetTextureSamplerHandleARB(m_rtts->getRenderTarget(RTT_HALF1_R), MeshShader::ObjectPass2Shader::getInstance()->SamplersId[2]); + if (!glIsTextureHandleResidentARB(SSAOHandle)) + glMakeTextureHandleResidentARB(SSAOHandle); + + DepthHandle = glGetTextureSamplerHandleARB(getDepthStencilTexture(), MeshShader::ObjectPass2Shader::getInstance()->SamplersId[3]); + if (!glIsTextureHandleResidentARB(DepthHandle)) + glMakeTextureHandleResidentARB(DepthHandle); #endif - setTexture(0, m_rtts->getRenderTarget(RTT_DIFFUSE), GL_NEAREST, GL_NEAREST); -#ifdef GL_VERSION_3_3 - if (irr_driver->getGLSLVersion() >= 330) - glBindSampler(1, 0); -#endif - setTexture(1, m_rtts->getRenderTarget(RTT_SPECULAR), GL_NEAREST, GL_NEAREST); -#ifdef GL_VERSION_3_3 - if (irr_driver->getGLSLVersion() >= 330) - glBindSampler(2, 0); -#endif - setTexture(2, m_rtts->getRenderTarget(RTT_HALF1_R), GL_LINEAR, GL_LINEAR); + } { ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS2)); m_scene_manager->drawAll(scene::ESNRP_SOLID); + std::vector DiffSpecSSAOTex = createVector(m_rtts->getRenderTarget(RTT_DIFFUSE), m_rtts->getRenderTarget(RTT_SPECULAR), m_rtts->getRenderTarget(RTT_HALF1_R)); + renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListMatDefault::getInstance()); + ), ListMatDefault::getInstance(), + createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), AnimatedListMatDefault::getInstance()); + ), AnimatedListMatDefault::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListMatAlphaRef::getInstance()); + ), ListMatAlphaRef::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), AnimatedListMatAlphaRef::getInstance()); + ), AnimatedListMatAlphaRef::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListMatSphereMap::getInstance()); + ), ListMatSphereMap::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true), TexUnit(1, true) - ), ListMatDetails::getInstance()); + ), ListMatDetails::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true), TexUnit(1, true) - ), AnimatedListMatDetails::getInstance()); - + ), AnimatedListMatDetails::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListMatGrass::getInstance()); + ), ListMatGrass::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListMatUnlit::getInstance()); + ), ListMatUnlit::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), AnimatedListMatUnlit::getInstance()); + ), AnimatedListMatUnlit::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(1, false), @@ -447,26 +523,25 @@ void IrrDriver::renderSolidSecondPass() TexUnit(3, true), TexUnit(4, true), TexUnit(5, true) - ), ListMatSplatting::getInstance()); + ), ListMatSplatting::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListMatNormalMap::getInstance()); - + ), ListMatNormalMap::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderInstancedMeshes2ndPass( TexUnits(TexUnit(0, true)), - ListInstancedMatDefault::getInstance()); + ListInstancedMatDefault::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderInstancedMeshes2ndPass( TexUnits(TexUnit(0, true)), - ListInstancedMatNormalMap::getInstance()); + ListInstancedMatNormalMap::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); renderInstancedMeshes2ndPass( TexUnits(TexUnit(0, true)), - ListInstancedMatAlphaRef::getInstance()); - setTexture(4, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST); + ListInstancedMatAlphaRef::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + DiffSpecSSAOTex.push_back(irr_driver->getDepthStencilTexture()); renderInstancedMeshes2ndPass( TexUnits(TexUnit(0, true)), - ListInstancedMatGrass::getInstance()); + ListInstancedMatGrass::getInstance(), createVector(DiffuseHandle, SpecularHandle, SSAOHandle, DepthHandle), DiffSpecSSAOTex); } m_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } @@ -504,8 +579,6 @@ void IrrDriver::renderNormalsVisualisation() } - - static video::ITexture *displaceTex = 0; void IrrDriver::renderTransparent() @@ -531,22 +604,22 @@ void IrrDriver::renderTransparent() glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListBlendTransparentFog::getInstance()); + ), ListBlendTransparentFog::getInstance(), createVector(), createVector()); glBlendFunc(GL_ONE, GL_ONE); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListAdditiveTransparentFog::getInstance()); + ), ListAdditiveTransparentFog::getInstance(), createVector(), createVector()); } else { glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListBlendTransparent::getInstance()); + ), ListBlendTransparent::getInstance(), createVector(), createVector()); glBlendFunc(GL_ONE, GL_ONE); renderMeshes2ndPass(TexUnits( TexUnit(0, true) - ), ListAdditiveTransparent::getInstance()); + ), ListAdditiveTransparent::getInstance(), createVector(), createVector()); } if (!UserConfigParams::m_dynamic_lights) @@ -671,14 +744,29 @@ void renderShadow(const std::vector TextureUnits, const std::vectorgetVAO(VertexType)); for (unsigned i = 0; i < t->size(); i++) { + std::vector Handles; std::vector Textures; - const GLMesh *mesh = STK::tuple_get<0>(t->at(i)); + GLMesh *mesh = STK::tuple_get<0>(t->at(i)); for (unsigned j = 0; j < TextureUnits.size(); j++) { compressTexture(mesh->textures[TextureUnits[j]], true); - Textures.push_back(getTextureGLuint(mesh->textures[TextureUnits[j]])); + if (UserConfigParams::m_bindless_textures) + { +#ifdef Bindless_Texture_Support + if (!mesh->TextureHandles[TextureUnits[j]]) + mesh->TextureHandles[TextureUnits[j]] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh->textures[TextureUnits[j]]), T::getInstance()->SamplersId[j]); + if (!glIsTextureHandleResidentARB(mesh->TextureHandles[TextureUnits[j]])) + glMakeTextureHandleResidentARB(mesh->TextureHandles[TextureUnits[j]]); +#endif + Handles.push_back(mesh->TextureHandles[TextureUnits[j]]); + } + else + Textures.push_back(getTextureGLuint(mesh->textures[TextureUnits[j]])); } - T::getInstance()->SetTextureUnits(Textures); + if (UserConfigParams::m_bindless_textures) + T::getInstance()->SetTextureHandles(Handles); + else + T::getInstance()->SetTextureUnits(Textures); shadow_custom_unroll_args::template exec(T::getInstance(), t->at(i)); } } @@ -720,15 +808,30 @@ void renderInstancedShadow(const std::vector TextureUnits, const std::ve glUseProgram(T::getInstance()->Program); for (unsigned i = 0; i < t->size(); i++) { + std::vector Handles; std::vector Textures; - const GLMesh *mesh = STK::tuple_get<0>(t->at(i)); + GLMesh *mesh = STK::tuple_get<0>(t->at(i)); glBindVertexArray(mesh->vao_shadow_pass); for (unsigned j = 0; j < TextureUnits.size(); j++) { compressTexture(mesh->textures[TextureUnits[j]], true); - Textures.push_back(getTextureGLuint(mesh->textures[TextureUnits[j]])); + if (UserConfigParams::m_bindless_textures) + { +#ifdef Bindless_Texture_Support + if (!mesh->TextureHandles[TextureUnits[j]]) + mesh->TextureHandles[TextureUnits[j]] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh->textures[TextureUnits[j]]), T::getInstance()->SamplersId[j]); + if (!glIsTextureHandleResidentARB(mesh->TextureHandles[TextureUnits[j]])) + glMakeTextureHandleResidentARB(mesh->TextureHandles[TextureUnits[j]]); +#endif + Handles.push_back(mesh->TextureHandles[TextureUnits[j]]); + } + else + Textures.push_back(getTextureGLuint(mesh->textures[TextureUnits[j]])); } - T::getInstance()->SetTextureUnits(Textures); + if (UserConfigParams::m_bindless_textures) + T::getInstance()->SetTextureHandles(Handles); + else + T::getInstance()->SetTextureUnits(Textures); instanced_shadow_custom_unroll_args::template exec(T::getInstance(), t->at(i)); } } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 3812c28ac..dc357c07f 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -884,11 +884,7 @@ namespace MeshShader GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO")); - AssignSamplerNames(Program, 3, "Albedo"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo"); } InstancedObjectPass2Shader::InstancedObjectPass2Shader() @@ -900,12 +896,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str()); AssignUniforms(); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO")); - - AssignSamplerNames(Program, 3, "Albedo"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); @@ -921,12 +912,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str()); AssignUniforms(); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO")); - - AssignSamplerNames(Program, 3, "Albedo"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); @@ -942,11 +928,7 @@ namespace MeshShader GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO")); - AssignSamplerNames(Program, 3, "Albedo", 4, "Detail"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Detail"); } ObjectUnlitShader::ObjectUnlitShader() @@ -959,7 +941,7 @@ namespace MeshShader GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - AssignSamplerNames(Program, 3, "tex"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex"); } ObjectRefPass2Shader::ObjectRefPass2Shader() @@ -973,11 +955,7 @@ namespace MeshShader GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO")); - AssignSamplerNames(Program, 3, "Albedo"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo"); } GrassPass2Shader::GrassPass2Shader() @@ -988,11 +966,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str()); AssignUniforms("ModelMatrix", "windDir"); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO")); - AssignSamplerNames(Program, 3, "Albedo"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo"); } InstancedGrassPass2Shader::InstancedGrassPass2Shader() @@ -1004,15 +978,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str()); AssignUniforms("windDir", "SunDir"); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO"), - TexUnit(4, "dtex") - ); - - AssignSamplerNames(Program, 3, "Albedo"); - + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "dtex", 4, "Albedo"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); @@ -1030,11 +996,7 @@ namespace MeshShader GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO")); - AssignSamplerNames(Program, 3, "tex"); + AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex"); } SplattingShader::SplattingShader() @@ -1045,11 +1007,10 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting.frag").c_str()); AssignUniforms("ModelMatrix"); - AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), - TexUnit(1, "SpecularMap"), - TexUnit(2, "SSAO")); AssignSamplerNames(Program, + 0, "DiffuseMap", + 1, "SpecularMap", + 2, "SSAO", 3, "tex_layout", 4, "tex_detail0", 5, "tex_detail1", diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 9ab88daa0..33ae728f9 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -395,15 +395,16 @@ private: void AssignTextureNames_impl(GLuint Program, GLuint TexUnit, const char *name, Args...args...) { GLuint location = glGetUniformLocation(Program, name); + TextureLocation.push_back(location); glUniform1i(location, TexUnit); TextureUnits.push_back(TexUnit); AssignTextureNames_impl(Program, args...); } protected: - std::vector SamplersId; std::vector TextureUnits; std::vector TextureType; + std::vector TextureLocation; template void AssignSamplerNames(GLuint Program, Args...args) { @@ -415,6 +416,7 @@ protected: } public: + std::vector SamplersId; void SetTextureUnits(const std::vector &args) { assert(args.size() == sizeof...(tp) && "Too much texture unit provided"); @@ -434,6 +436,16 @@ public: for (unsigned i = 0; i < SamplersId.size(); i++) glDeleteSamplers(1, &SamplersId[i]); } + + void SetTextureHandles(const std::vector &args) + { + for (unsigned i = 0; i < args.size(); i++) + { +#ifdef Bindless_Texture_Support + glUniformHandleui64ARB(TextureLocation[i], args[i]); +#endif + } + } }; namespace MeshShader @@ -486,61 +498,61 @@ public: InstancedNormalMapShader(); }; -class ObjectPass2Shader : public ShaderHelperSingleton, public TextureRead +class ObjectPass2Shader : public ShaderHelperSingleton, public TextureRead { public: ObjectPass2Shader(); }; -class InstancedObjectPass2Shader : public ShaderHelperSingleton, public TextureRead +class InstancedObjectPass2Shader : public ShaderHelperSingleton, public TextureRead { public: InstancedObjectPass2Shader(); }; -class InstancedObjectRefPass2Shader : public ShaderHelperSingleton, public TextureRead +class InstancedObjectRefPass2Shader : public ShaderHelperSingleton, public TextureRead { public: InstancedObjectRefPass2Shader(); }; -class DetailledObjectPass2Shader : public ShaderHelperSingleton, public TextureRead +class DetailledObjectPass2Shader : public ShaderHelperSingleton, public TextureRead { public: DetailledObjectPass2Shader(); }; -class ObjectUnlitShader : public ShaderHelperSingleton, public TextureRead +class ObjectUnlitShader : public ShaderHelperSingleton, public TextureRead { public: ObjectUnlitShader(); }; -class ObjectRefPass2Shader : public ShaderHelperSingleton, public TextureRead +class ObjectRefPass2Shader : public ShaderHelperSingleton, public TextureRead { public: ObjectRefPass2Shader(); }; -class GrassPass2Shader : public ShaderHelperSingleton, public TextureRead +class GrassPass2Shader : public ShaderHelperSingleton, public TextureRead { public: GrassPass2Shader(); }; -class InstancedGrassPass2Shader : public ShaderHelperSingleton, public TextureRead +class InstancedGrassPass2Shader : public ShaderHelperSingleton, public TextureRead { public: InstancedGrassPass2Shader(); }; -class SphereMapShader : public ShaderHelperSingleton, public TextureRead +class SphereMapShader : public ShaderHelperSingleton, public TextureRead { public: SphereMapShader(); }; -class SplattingShader : public ShaderHelperSingleton, public TextureRead +class SplattingShader : public ShaderHelperSingleton, public TextureRead { public: SplattingShader(); diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 43f42c5a3..dd21eb6c6 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -47,6 +47,7 @@ struct GLMesh { size_t vaoBaseVertex; size_t vaoOffset; video::E_VERTEX_TYPE VAOType; + uint64_t TextureHandles[6]; }; GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb); diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 0a8aabddd..1b4f7c737 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -341,7 +341,18 @@ void STKMeshSceneNode::render() tmpcol.getBlue() / 255.0f); compressTexture(mesh.textures[0], true); - MeshShader::TransparentFogShader::getInstance()->SetTextureUnits(std::vector{ getTextureGLuint(mesh.textures[0]) }); + if (UserConfigParams::m_bindless_textures) + { +#ifdef Bindless_Texture_Support + if (!mesh.TextureHandles[0]) + mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), MeshShader::TransparentFogShader::getInstance()->SamplersId[0]); + if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) + glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); + MeshShader::TransparentFogShader::getInstance()->SetTextureHandles(createVector(mesh.TextureHandles[0])); +#endif + } + else + MeshShader::TransparentFogShader::getInstance()->SetTextureUnits(std::vector{ getTextureGLuint(mesh.textures[0]) }); MeshShader::TransparentFogShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, fogmax, startH, endH, start, end, col); assert(mesh.vao); @@ -362,7 +373,18 @@ void STKMeshSceneNode::render() size_t count = mesh.IndexCount; compressTexture(mesh.textures[0], true); - MeshShader::TransparentShader::getInstance()->SetTextureUnits(std::vector{ getTextureGLuint(mesh.textures[0]) }); + if (UserConfigParams::m_bindless_textures) + { +#ifdef Bindless_Texture_Support + if (!mesh.TextureHandles[0]) + mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), MeshShader::TransparentShader::getInstance()->SamplersId[0]); + if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) + glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); + MeshShader::TransparentShader::getInstance()->SetTextureHandles(createVector(mesh.TextureHandles[0])); +#endif + } + else + MeshShader::TransparentShader::getInstance()->SetTextureUnits(std::vector{ getTextureGLuint(mesh.textures[0]) }); MeshShader::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix); assert(mesh.vao);