From 24308ced03a7885044e7ad9d23993c596311c9ad Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 13 Jan 2018 14:49:33 +0800 Subject: [PATCH] Remove features in SP that give no performance boost at all gl_Layer in vertex shader, bindless and array textures --- data/shaders/sp_grass_pass.vert | 41 ---- data/shaders/sp_grass_shadow.vert | 45 ---- data/shaders/sp_pass.vert | 41 ---- data/shaders/sp_shadow.vert | 45 ---- data/shaders/sp_skinning.vert | 41 ---- data/shaders/sp_skinning_shadow.vert | 46 ---- data/shaders/utils/getLightFactor.frag | 28 --- data/shaders/utils/sp_texture_sampling.frag | 41 ---- src/graphics/central_settings.cpp | 27 --- src/graphics/central_settings.hpp | 8 - src/graphics/frame_buffer_layer.cpp | 65 ++---- src/graphics/shader_based_renderer.cpp | 20 +- src/graphics/shader_files_manager.cpp | 16 -- src/graphics/sp/sp_base.cpp | 47 +--- src/graphics/sp/sp_base.hpp | 2 +- src/graphics/sp/sp_dynamic_draw_call.cpp | 62 +---- src/graphics/sp/sp_dynamic_draw_call.hpp | 6 +- src/graphics/sp/sp_mesh_buffer.cpp | 78 +------ src/graphics/sp/sp_mesh_buffer.hpp | 26 +-- src/graphics/sp/sp_shader.cpp | 5 +- src/graphics/sp/sp_texture.cpp | 247 ++++---------------- src/graphics/sp/sp_texture.hpp | 30 +-- src/graphics/sp/sp_texture_manager.cpp | 109 +-------- src/graphics/sp/sp_texture_manager.hpp | 21 +- 24 files changed, 100 insertions(+), 997 deletions(-) delete mode 100644 data/shaders/utils/getLightFactor.frag diff --git a/data/shaders/sp_grass_pass.vert b/data/shaders/sp_grass_pass.vert index 9b9cca9ff..1164ae5f1 100644 --- a/data/shaders/sp_grass_pass.vert +++ b/data/shaders/sp_grass_pass.vert @@ -21,37 +21,12 @@ layout(location = 9) in vec4 i_rotation; layout(location = 10) in vec4 i_scale; layout(location = 12) in ivec2 i_misc_data; -#if defined(Use_Bindless_Texture) -layout(location = 13) in uvec4 i_bindless_texture_0; -layout(location = 14) in uvec4 i_bindless_texture_1; -layout(location = 15) in uvec4 i_bindless_texture_2; -#elif defined(Use_Array_Texture) -layout(location = 13) in uvec4 i_array_texture_0; -layout(location = 14) in uvec2 i_array_texture_1; -#endif - #stk_include "utils/get_world_location.vert" out vec3 normal; out vec2 uv; flat out float hue_change; -#if defined(Use_Bindless_Texture) -flat out sampler2D tex_layer_0; -flat out sampler2D tex_layer_1; -flat out sampler2D tex_layer_2; -flat out sampler2D tex_layer_3; -flat out sampler2D tex_layer_4; -flat out sampler2D tex_layer_5; -#elif defined(Use_Array_Texture) -flat out float array_0; -flat out float array_1; -flat out float array_2; -flat out float array_3; -flat out float array_4; -flat out float array_5; -#endif - void main() { @@ -60,22 +35,6 @@ void main() vec4 i_rotation = convert10BitVector(i_rotation_orig); #endif -#if defined(Use_Bindless_Texture) - tex_layer_0 = sampler2D(i_bindless_texture_0.xy); - tex_layer_1 = sampler2D(i_bindless_texture_0.zw); - tex_layer_2 = sampler2D(i_bindless_texture_1.xy); - tex_layer_3 = sampler2D(i_bindless_texture_1.zw); - tex_layer_4 = sampler2D(i_bindless_texture_2.xy); - tex_layer_5 = sampler2D(i_bindless_texture_2.zw); -#elif defined(Use_Array_Texture) - array_0 = float(i_array_texture_0.x); - array_1 = float(i_array_texture_0.y); - array_2 = float(i_array_texture_0.z); - array_3 = float(i_array_texture_0.w); - array_4 = float(i_array_texture_1.x); - array_5 = float(i_array_texture_1.y); -#endif - vec3 test = sin(wind_direction * (i_position.y * 0.1)); test += cos(wind_direction) * 0.7; diff --git a/data/shaders/sp_grass_shadow.vert b/data/shaders/sp_grass_shadow.vert index cc238b805..af7db4ef2 100644 --- a/data/shaders/sp_grass_shadow.vert +++ b/data/shaders/sp_grass_shadow.vert @@ -14,35 +14,10 @@ layout(location = 9) in vec4 i_rotation; layout(location = 10) in vec4 i_scale; -#if defined(Use_Bindless_Texture) -layout(location = 13) in uvec4 i_bindless_texture_0; -layout(location = 14) in uvec4 i_bindless_texture_1; -layout(location = 15) in uvec4 i_bindless_texture_2; -#elif defined(Use_Array_Texture) -layout(location = 13) in uvec4 i_array_texture_0; -layout(location = 14) in uvec2 i_array_texture_1; -#endif - #stk_include "utils/get_world_location.vert" out vec2 uv; -#if defined(Use_Bindless_Texture) -flat out sampler2D tex_layer_0; -flat out sampler2D tex_layer_1; -flat out sampler2D tex_layer_2; -flat out sampler2D tex_layer_3; -flat out sampler2D tex_layer_4; -flat out sampler2D tex_layer_5; -#elif defined(Use_Array_Texture) -flat out float array_0; -flat out float array_1; -flat out float array_2; -flat out float array_3; -flat out float array_4; -flat out float array_5; -#endif - void main() { @@ -50,26 +25,6 @@ void main() vec4 i_rotation = convert10BitVector(i_rotation_orig); #endif -#if defined(Use_Bindless_Texture) - tex_layer_0 = sampler2D(i_bindless_texture_0.xy); - tex_layer_1 = sampler2D(i_bindless_texture_0.zw); - tex_layer_2 = sampler2D(i_bindless_texture_1.xy); - tex_layer_3 = sampler2D(i_bindless_texture_1.zw); - tex_layer_4 = sampler2D(i_bindless_texture_2.xy); - tex_layer_5 = sampler2D(i_bindless_texture_2.zw); -#elif defined(Use_Array_Texture) - array_0 = float(i_array_texture_0.x); - array_1 = float(i_array_texture_0.y); - array_2 = float(i_array_texture_0.z); - array_3 = float(i_array_texture_0.w); - array_4 = float(i_array_texture_1.x); - array_5 = float(i_array_texture_1.y); -#endif - -#ifdef VSLayer - gl_Layer = layer; -#endif - vec3 test = sin(wind_direction * (i_position.y * 0.1)); test += cos(wind_direction) * 0.7; diff --git a/data/shaders/sp_pass.vert b/data/shaders/sp_pass.vert index e88e3fc60..c3a2f6e93 100644 --- a/data/shaders/sp_pass.vert +++ b/data/shaders/sp_pass.vert @@ -28,15 +28,6 @@ layout(location = 10) in vec4 i_scale; layout(location = 11) in vec2 i_texture_trans; layout(location = 12) in ivec2 i_misc_data; -#if defined(Use_Bindless_Texture) -layout(location = 13) in uvec4 i_bindless_texture_0; -layout(location = 14) in uvec4 i_bindless_texture_1; -layout(location = 15) in uvec4 i_bindless_texture_2; -#elif defined(Use_Array_Texture) -layout(location = 13) in uvec4 i_array_texture_0; -layout(location = 14) in uvec2 i_array_texture_1; -#endif - #stk_include "utils/get_world_location.vert" out vec3 tangent; @@ -48,22 +39,6 @@ out vec4 color; out float camdist; flat out float hue_change; -#if defined(Use_Bindless_Texture) -flat out sampler2D tex_layer_0; -flat out sampler2D tex_layer_1; -flat out sampler2D tex_layer_2; -flat out sampler2D tex_layer_3; -flat out sampler2D tex_layer_4; -flat out sampler2D tex_layer_5; -#elif defined(Use_Array_Texture) -flat out float array_0; -flat out float array_1; -flat out float array_2; -flat out float array_3; -flat out float array_4; -flat out float array_5; -#endif - void main() { @@ -73,22 +48,6 @@ void main() vec4 i_rotation = convert10BitVector(i_rotation_orig); #endif -#if defined(Use_Bindless_Texture) - tex_layer_0 = sampler2D(i_bindless_texture_0.xy); - tex_layer_1 = sampler2D(i_bindless_texture_0.zw); - tex_layer_2 = sampler2D(i_bindless_texture_1.xy); - tex_layer_3 = sampler2D(i_bindless_texture_1.zw); - tex_layer_4 = sampler2D(i_bindless_texture_2.xy); - tex_layer_5 = sampler2D(i_bindless_texture_2.zw); -#elif defined(Use_Array_Texture) - array_0 = float(i_array_texture_0.x); - array_1 = float(i_array_texture_0.y); - array_2 = float(i_array_texture_0.z); - array_3 = float(i_array_texture_0.w); - array_4 = float(i_array_texture_1.x); - array_5 = float(i_array_texture_1.y); -#endif - vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w)); vec4 world_position = getWorldPosition(i_origin, quaternion, i_scale.xyz, i_position); diff --git a/data/shaders/sp_shadow.vert b/data/shaders/sp_shadow.vert index 755c9ce42..ec6f3c7bb 100644 --- a/data/shaders/sp_shadow.vert +++ b/data/shaders/sp_shadow.vert @@ -12,35 +12,10 @@ layout(location = 9) in vec4 i_rotation; layout(location = 10) in vec4 i_scale; -#if defined(Use_Bindless_Texture) -layout(location = 13) in uvec4 i_bindless_texture_0; -layout(location = 14) in uvec4 i_bindless_texture_1; -layout(location = 15) in uvec4 i_bindless_texture_2; -#elif defined(Use_Array_Texture) -layout(location = 13) in uvec4 i_array_texture_0; -layout(location = 14) in uvec2 i_array_texture_1; -#endif - #stk_include "utils/get_world_location.vert" out vec2 uv; -#if defined(Use_Bindless_Texture) -flat out sampler2D tex_layer_0; -flat out sampler2D tex_layer_1; -flat out sampler2D tex_layer_2; -flat out sampler2D tex_layer_3; -flat out sampler2D tex_layer_4; -flat out sampler2D tex_layer_5; -#elif defined(Use_Array_Texture) -flat out float array_0; -flat out float array_1; -flat out float array_2; -flat out float array_3; -flat out float array_4; -flat out float array_5; -#endif - void main() { @@ -48,26 +23,6 @@ void main() vec4 i_rotation = convert10BitVector(i_rotation_orig); #endif -#if defined(Use_Bindless_Texture) - tex_layer_0 = sampler2D(i_bindless_texture_0.xy); - tex_layer_1 = sampler2D(i_bindless_texture_0.zw); - tex_layer_2 = sampler2D(i_bindless_texture_1.xy); - tex_layer_3 = sampler2D(i_bindless_texture_1.zw); - tex_layer_4 = sampler2D(i_bindless_texture_2.xy); - tex_layer_5 = sampler2D(i_bindless_texture_2.zw); -#elif defined(Use_Array_Texture) - array_0 = float(i_array_texture_0.x); - array_1 = float(i_array_texture_0.y); - array_2 = float(i_array_texture_0.z); - array_3 = float(i_array_texture_0.w); - array_4 = float(i_array_texture_1.x); - array_5 = float(i_array_texture_1.y); -#endif - -#ifdef VSLayer - gl_Layer = layer; -#endif - vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w)); vec4 world_position = getWorldPosition(i_origin, quaternion, i_scale.xyz, i_position); diff --git a/data/shaders/sp_skinning.vert b/data/shaders/sp_skinning.vert index 832d36d8b..28824111a 100644 --- a/data/shaders/sp_skinning.vert +++ b/data/shaders/sp_skinning.vert @@ -35,15 +35,6 @@ layout(location = 10) in vec4 i_scale; layout(location = 11) in vec2 i_texture_trans; layout(location = 12) in ivec2 i_misc_data; -#if defined(Use_Bindless_Texture) -layout(location = 13) in uvec4 i_bindless_texture_0; -layout(location = 14) in uvec4 i_bindless_texture_1; -layout(location = 15) in uvec4 i_bindless_texture_2; -#elif defined(Use_Array_Texture) -layout(location = 13) in uvec4 i_array_texture_0; -layout(location = 14) in uvec2 i_array_texture_1; -#endif - #stk_include "utils/get_world_location.vert" out vec3 tangent; @@ -55,22 +46,6 @@ out vec4 color; out float camdist; flat out float hue_change; -#if defined(Use_Bindless_Texture) -flat out sampler2D tex_layer_0; -flat out sampler2D tex_layer_1; -flat out sampler2D tex_layer_2; -flat out sampler2D tex_layer_3; -flat out sampler2D tex_layer_4; -flat out sampler2D tex_layer_5; -#elif defined(Use_Array_Texture) -flat out float array_0; -flat out float array_1; -flat out float array_2; -flat out float array_3; -flat out float array_4; -flat out float array_5; -#endif - void main() { @@ -80,22 +55,6 @@ void main() vec4 i_rotation = convert10BitVector(i_rotation_orig); #endif -#if defined(Use_Bindless_Texture) - tex_layer_0 = sampler2D(i_bindless_texture_0.xy); - tex_layer_1 = sampler2D(i_bindless_texture_0.zw); - tex_layer_2 = sampler2D(i_bindless_texture_1.xy); - tex_layer_3 = sampler2D(i_bindless_texture_1.zw); - tex_layer_4 = sampler2D(i_bindless_texture_2.xy); - tex_layer_5 = sampler2D(i_bindless_texture_2.zw); -#elif defined(Use_Array_Texture) - array_0 = float(i_array_texture_0.x); - array_1 = float(i_array_texture_0.y); - array_2 = float(i_array_texture_0.z); - array_3 = float(i_array_texture_0.w); - array_4 = float(i_array_texture_1.x); - array_5 = float(i_array_texture_1.y); -#endif - vec4 idle_position = vec4(i_position, 1.0); vec4 idle_normal = vec4(i_normal.xyz, 0.0); vec4 idle_tangent = vec4(i_tangent.xyz, 0.0); diff --git a/data/shaders/sp_skinning_shadow.vert b/data/shaders/sp_skinning_shadow.vert index 309b0899e..81e0b6c3f 100644 --- a/data/shaders/sp_skinning_shadow.vert +++ b/data/shaders/sp_skinning_shadow.vert @@ -6,7 +6,6 @@ uniform sampler2D skinning_tex; uniform samplerBuffer skinning_tex; #endif - layout(location = 0) in vec3 i_position; layout(location = 3) in vec2 i_uv; layout(location = 6) in ivec4 i_joint; @@ -22,35 +21,10 @@ layout(location = 9) in vec4 i_rotation; layout(location = 10) in vec4 i_scale; layout(location = 12) in ivec2 i_misc_data; -#if defined(Use_Bindless_Texture) -layout(location = 13) in uvec4 i_bindless_texture_0; -layout(location = 14) in uvec4 i_bindless_texture_1; -layout(location = 15) in uvec4 i_bindless_texture_2; -#elif defined(Use_Array_Texture) -layout(location = 13) in uvec4 i_array_texture_0; -layout(location = 14) in uvec2 i_array_texture_1; -#endif - #stk_include "utils/get_world_location.vert" out vec2 uv; -#if defined(Use_Bindless_Texture) -flat out sampler2D tex_layer_0; -flat out sampler2D tex_layer_1; -flat out sampler2D tex_layer_2; -flat out sampler2D tex_layer_3; -flat out sampler2D tex_layer_4; -flat out sampler2D tex_layer_5; -#elif defined(Use_Array_Texture) -flat out float array_0; -flat out float array_1; -flat out float array_2; -flat out float array_3; -flat out float array_4; -flat out float array_5; -#endif - void main() { @@ -58,26 +32,6 @@ void main() vec4 i_rotation = convert10BitVector(i_rotation_orig); #endif -#if defined(Use_Bindless_Texture) - tex_layer_0 = sampler2D(i_bindless_texture_0.xy); - tex_layer_1 = sampler2D(i_bindless_texture_0.zw); - tex_layer_2 = sampler2D(i_bindless_texture_1.xy); - tex_layer_3 = sampler2D(i_bindless_texture_1.zw); - tex_layer_4 = sampler2D(i_bindless_texture_2.xy); - tex_layer_5 = sampler2D(i_bindless_texture_2.zw); -#elif defined(Use_Array_Texture) - array_0 = float(i_array_texture_0.x); - array_1 = float(i_array_texture_0.y); - array_2 = float(i_array_texture_0.z); - array_3 = float(i_array_texture_0.w); - array_4 = float(i_array_texture_1.x); - array_5 = float(i_array_texture_1.y); -#endif - -#ifdef VSLayer - gl_Layer = layer; -#endif - vec4 idle_position = vec4(i_position, 1.0); vec4 skinned_position = vec4(0.0); int skinning_offset = i_misc_data.x; diff --git a/data/shaders/utils/getLightFactor.frag b/data/shaders/utils/getLightFactor.frag deleted file mode 100644 index 472feeed1..000000000 --- a/data/shaders/utils/getLightFactor.frag +++ /dev/null @@ -1,28 +0,0 @@ -#ifdef Use_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(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue) -{ -#if defined(Advanced_Lighting_Enabled) - vec2 tc = gl_FragCoord.xy / u_screen; - vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz; - vec3 SpecularComponent = texture(SpecularMap, tc).xyz; - float ao = texture(SSAO, tc).x; - vec3 tmp = diffuseMatColor * DiffuseComponent * (1. - specMapValue) + specularMatColor * SpecularComponent * specMapValue; - vec3 emitCol = diffuseMatColor.xyz * diffuseMatColor.xyz * diffuseMatColor.xyz * 15.; - return tmp * ao + (emitMapValue * emitCol); -#else -#if !defined(sRGB_Framebuffer_Usable) - return diffuseMatColor * 0.73; // 0.5 ^ (1. / 2.2) -#else - return diffuseMatColor * 0.5; -#endif -#endif -} diff --git a/data/shaders/utils/sp_texture_sampling.frag b/data/shaders/utils/sp_texture_sampling.frag index e85adeb7d..04f9d4121 100644 --- a/data/shaders/utils/sp_texture_sampling.frag +++ b/data/shaders/utils/sp_texture_sampling.frag @@ -1,78 +1,37 @@ // Wrapper to allow easy sampling for material texture slots -#if defined(Use_Array_Texture) -flat in float array_0; -flat in float array_1; -flat in float array_2; -flat in float array_3; -flat in float array_4; -flat in float array_5; -uniform sampler2DArray tex_array; -#elif defined(Use_Bindless_Texture) -flat in sampler2D tex_layer_0; -flat in sampler2D tex_layer_1; -flat in sampler2D tex_layer_2; -flat in sampler2D tex_layer_3; -flat in sampler2D tex_layer_4; -flat in sampler2D tex_layer_5; -#else uniform sampler2D tex_layer_0; uniform sampler2D tex_layer_1; uniform sampler2D tex_layer_2; uniform sampler2D tex_layer_3; uniform sampler2D tex_layer_4; uniform sampler2D tex_layer_5; -#endif vec4 sampleTextureSlot0(vec2 uv) { -#ifdef Use_Array_Texture - return texture(tex_array, vec3(uv, array_0)); -#else return texture(tex_layer_0, uv); -#endif } vec4 sampleTextureSlot1(vec2 uv) { -#ifdef Use_Array_Texture - return texture(tex_array, vec3(uv, array_1)); -#else return texture(tex_layer_1, uv); -#endif } vec4 sampleTextureSlot2(vec2 uv) { -#ifdef Use_Array_Texture - return texture(tex_array, vec3(uv, array_2)); -#else return texture(tex_layer_2, uv); -#endif } vec4 sampleTextureSlot3(vec2 uv) { -#ifdef Use_Array_Texture - return texture(tex_array, vec3(uv, array_3)); -#else return texture(tex_layer_3, uv); -#endif } vec4 sampleTextureSlot4(vec2 uv) { -#ifdef Use_Array_Texture - return texture(tex_array, vec3(uv, array_4)); -#else return texture(tex_layer_4, uv); -#endif } vec4 sampleTextureSlot5(vec2 uv) { -#ifdef Use_Array_Texture - return texture(tex_array, vec3(uv, array_5)); -#else return texture(tex_layer_5, uv); -#endif } diff --git a/src/graphics/central_settings.cpp b/src/graphics/central_settings.cpp index 9bfeb9a02..433b16c13 100644 --- a/src/graphics/central_settings.cpp +++ b/src/graphics/central_settings.cpp @@ -39,7 +39,6 @@ void CentralVideoSettings::init() hasArraysOfArrays = false; hasTextureStorage = false; hasTextureView = false; - hasBindlessTexture = false; hasAtomics = false; hasSSBO = false; hasImageLoadStore = false; @@ -96,16 +95,6 @@ void CentralVideoSettings::init() } #if !defined(USE_GLES2) - if (hasGLExtension("GL_AMD_vertex_shader_layer")) - { - m_vs_layer_extension = "GL_AMD_vertex_shader_layer"; - Log::info("GLDriver", "AMD Vertex Shader Layer Present"); - } - if (hasGLExtension("GL_ARB_shader_viewport_layer_array")) - { - m_vs_layer_extension = "GL_ARB_shader_viewport_layer_array"; - Log::info("GLDriver", "ARB Shader Viewport Layer Array Present"); - } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_BUFFER_STORAGE) && hasGLExtension("GL_ARB_buffer_storage") ) { @@ -317,10 +306,6 @@ bool CentralVideoSettings::isEXTTextureCompressionS3TCUsable() const return hasTextureCompression; } -bool CentralVideoSettings::supportsGLLayerInVertexShader() const -{ - return !m_vs_layer_extension.empty(); -} bool CentralVideoSettings::isARBBufferStorageUsable() const { @@ -347,11 +332,6 @@ bool CentralVideoSettings::isARBTextureViewUsable() const return hasTextureView; } -bool CentralVideoSettings::isARBBindlessTextureUsable() const -{ - return false; -} - bool CentralVideoSettings::isARBShaderAtomicCountersUsable() const { return hasAtomics; @@ -442,11 +422,4 @@ bool CentralVideoSettings::isARBInstancedArraysUsable() const (m_gl_major_version > 3 || (m_gl_major_version == 3 && m_gl_minor_version >= 2)); } -bool CentralVideoSettings::useArrayTextures() const -{ - return false; - //return (UserConfigParams::m_high_definition_textures & 0x01) == 0 && - // UserConfigParams::m_max_texture_size <= 256; -} - #endif // !SERVER_ONLY diff --git a/src/graphics/central_settings.hpp b/src/graphics/central_settings.hpp index 4a84b77a5..5639ffb3c 100644 --- a/src/graphics/central_settings.hpp +++ b/src/graphics/central_settings.hpp @@ -27,13 +27,11 @@ private: bool m_glsl; int m_gl_major_version, m_gl_minor_version; - std::string m_vs_layer_extension; bool hasBufferStorage; bool hasComputeShaders; bool hasArraysOfArrays; bool hasTextureStorage; bool hasTextureView; - bool hasBindlessTexture; bool hasUBO; bool hasExplicitAttribLocation; bool hasGS; @@ -72,7 +70,6 @@ public: bool isARBTextureStorageUsable() const; bool isARBComputeShaderUsable() const; bool isARBArraysOfArraysUsable() const; - bool isARBBindlessTextureUsable() const; bool isARBBufferStorageUsable() const; bool isARBShaderAtomicCountersUsable() const; bool isARBShaderStorageBufferObjectUsable() const; @@ -83,11 +80,8 @@ public: bool isARBPixelBufferObjectUsable() const; bool isARBSamplerObjectsUsable() const; bool isARBVertexType2101010RevUsable() const; - bool useArrayTextures() const; bool isARBInstancedArraysUsable() const; - const std::string& getVSLayerExtension() const { return m_vs_layer_extension; } - #if defined(USE_GLES2) bool isEXTTextureFormatBGRA8888Usable() const; bool isEXTColorBufferFloatUsable() const; @@ -98,8 +92,6 @@ public: bool supportsHardwareSkinning() const; bool supportsTextureCompression() const; - bool supportsGLLayerInVertexShader() const; - // "Macro" around feature support and user config bool isShadowEnabled() const; bool isTextureCompressionEnabled() const; diff --git a/src/graphics/frame_buffer_layer.cpp b/src/graphics/frame_buffer_layer.cpp index 64ec2da88..acd4c91ac 100644 --- a/src/graphics/frame_buffer_layer.cpp +++ b/src/graphics/frame_buffer_layer.cpp @@ -28,37 +28,19 @@ FrameBufferLayer::FrameBufferLayer(const std::vector &rtts, unsigned w, m_width = w; m_height = h; - // When vertex shader gl_layer issupported, only 1 fbo will be created -#ifndef USE_GLES2 - if (CVS->supportsGLLayerInVertexShader()) + m_fbo_layer.resize(layer_count); + glGenFramebuffers(layer_count, m_fbo_layer.data()); + for (unsigned layer = 0; layer < layer_count; layer++) { - glGenFramebuffers(1, &m_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, m_fbo_layer[layer]); for (unsigned i = 0; i < rtts.size(); i++) { - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, - rtts[i], 0); + glFramebufferTextureLayer(GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0 + i, rtts[i], 0, layer); } assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE_EXT); } - else -#endif - { - m_fbo_layer.resize(layer_count); - glGenFramebuffers(layer_count, m_fbo_layer.data()); - for (unsigned layer = 0; layer < layer_count; layer++) - { - glBindFramebuffer(GL_FRAMEBUFFER, m_fbo_layer[layer]); - for (unsigned i = 0; i < rtts.size(); i++) - { - glFramebufferTextureLayer(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0 + i, rtts[i], 0, layer); - } - assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == - GL_FRAMEBUFFER_COMPLETE_EXT); - } - } } // FrameBufferLayer // ---------------------------------------------------------------------------- @@ -72,40 +54,21 @@ FrameBufferLayer::FrameBufferLayer(const std::vector &rtts, m_width = w; m_height = h; -#ifndef USE_GLES2 - if (CVS->supportsGLLayerInVertexShader()) + m_fbo_layer.resize(layer_count); + glGenFramebuffers(layer_count, m_fbo_layer.data()); + for (unsigned layer = 0; layer < layer_count; layer++) { - glGenFramebuffers(1, &m_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, m_fbo_layer[layer]); for (unsigned i = 0; i < rtts.size(); i++) { - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, - rtts[i], 0); + glFramebufferTextureLayer(GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0 + i, rtts[i], 0, layer); } - glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, - depth_stencil, 0); + glFramebufferTextureLayer(GL_FRAMEBUFFER, + GL_DEPTH_STENCIL_ATTACHMENT, depth_stencil, 0, layer); assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE_EXT); } - else -#endif - { - m_fbo_layer.resize(layer_count); - glGenFramebuffers(layer_count, m_fbo_layer.data()); - for (unsigned layer = 0; layer < layer_count; layer++) - { - glBindFramebuffer(GL_FRAMEBUFFER, m_fbo_layer[layer]); - for (unsigned i = 0; i < rtts.size(); i++) - { - glFramebufferTextureLayer(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0 + i, rtts[i], 0, layer); - } - glFramebufferTextureLayer(GL_FRAMEBUFFER, - GL_DEPTH_STENCIL_ATTACHMENT, depth_stencil, 0, layer); - assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == - GL_FRAMEBUFFER_COMPLETE_EXT); - } - } } // FrameBufferLayer #endif \ No newline at end of file diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index 170ae18f2..53c28211f 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -182,28 +182,18 @@ void ShaderBasedRenderer::renderShadows() glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.5, 50.); + glPolygonOffset(1.5f, 50.0f); - if (CVS->supportsGLLayerInVertexShader()) - { - m_rtts->getShadowFrameBuffer().bindDepthOnly(); - glClearColor(1., 1., 1., 1.); - glClear(GL_DEPTH_BUFFER_BIT); - glClearColor(0., 0., 0., 0.); - } + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); for (unsigned cascade = 0; cascade < 4; cascade++) { - if (!CVS->supportsGLLayerInVertexShader()) - { - m_rtts->getShadowFrameBuffer().bindLayerDepthOnly(cascade); - glClearColor(1., 1., 1., 1.); - glClear(GL_DEPTH_BUFFER_BIT); - glClearColor(0., 0., 0., 0.); - } + m_rtts->getShadowFrameBuffer().bindLayerDepthOnly(cascade); + glClear(GL_DEPTH_BUFFER_BIT); SP::sp_cur_shadow_cascade = cascade; ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_SHADOWS_CASCADE0 + cascade)); SP::draw(SP::RP_SHADOW, (SP::DrawCallType)(SP::DCT_SHADOW1 + cascade)); } + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glDisable(GL_POLYGON_OFFSET_FILL); PROFILER_POP_CPU_MARKER(); } diff --git a/src/graphics/shader_files_manager.cpp b/src/graphics/shader_files_manager.cpp index ff4889318..f35c884b0 100644 --- a/src/graphics/shader_files_manager.cpp +++ b/src/graphics/shader_files_manager.cpp @@ -142,9 +142,6 @@ GLuint ShaderFilesManager::loadShader(const std::string &file, unsigned type) } #endif - if (CVS->supportsGLLayerInVertexShader()) - code << "#extension " << CVS->getVSLayerExtension() << " : enable\n"; - if (CVS->isARBExplicitAttribLocationUsable()) { #if !defined(USE_GLES2) @@ -153,17 +150,6 @@ GLuint ShaderFilesManager::loadShader(const std::string &file, unsigned type) code << "#define Explicit_Attrib_Location_Usable\n"; } - if (CVS->useArrayTextures()) - { - code << "#define Use_Array_Texture\n"; - } - else if (CVS->isARBBindlessTextureUsable()) - { - code << "#extension GL_ARB_bindless_texture : enable\n"; - code << "#extension GL_NV_gpu_shader5 : require\n"; - code << "#define Use_Bindless_Texture\n"; - } - if (GraphicsRestrictions::isDisabled (GraphicsRestrictions::GR_CORRECT_10BIT_NORMALIZATION)) { @@ -173,8 +159,6 @@ GLuint ShaderFilesManager::loadShader(const std::string &file, unsigned type) code << "//" << file << "\n"; if (!CVS->isARBUniformBufferObjectUsable()) code << "#define UBO_DISABLED\n"; - if (CVS->supportsGLLayerInVertexShader()) - code << "#define VSLayer\n"; if (CVS->needsVertexIdWorkaround()) code << "#define Needs_Vertex_Id_Workaround\n"; if (CVS->isDefferedEnabled()) diff --git a/src/graphics/sp/sp_base.cpp b/src/graphics/sp/sp_base.cpp index 25c166f6d..0daec9cf6 100644 --- a/src/graphics/sp/sp_base.cpp +++ b/src/graphics/sp/sp_base.cpp @@ -89,7 +89,8 @@ std::unordered_set g_instances; // ---------------------------------------------------------------------------- std::array g_samplers; // ---------------------------------------------------------------------------- -std::vector sp_prefilled_tex (2); +// Check sp_shader.cpp for the name +std::array sp_prefilled_tex; // ---------------------------------------------------------------------------- std::vector g_bounding_boxes; // ---------------------------------------------------------------------------- @@ -313,7 +314,7 @@ void initSkinning() #endif resizeSkinning(stk_config->m_max_skinning_bones); - sp_prefilled_tex[1] = g_skinning_tex; + sp_prefilled_tex[0] = g_skinning_tex; } // initSkinning // ---------------------------------------------------------------------------- @@ -1292,17 +1293,9 @@ void addObject(SPMeshNode* node) if (dc_type == 0) { auto& ret = g_draw_calls[DCT_TRANSPARENT][shader]; - if (CVS->isARBBindlessTextureUsable() || - CVS->useArrayTextures()) + for (auto& p : mb->getTextureCompare()) { - ret[""].insert(mb); - } - else - { - for (auto& p : mb->getTextureCompare()) - { - ret[p.first].insert(mb); - } + ret[p.first].insert(mb); } mb->addInstanceData(id, DCT_TRANSPARENT); } @@ -1316,9 +1309,7 @@ void addObject(SPMeshNode* node) // Check if shader for render pass uses mesh samplers const RenderPass check_pass = dc_type == DCT_NORMAL ? RP_1ST : RP_SHADOW; - const bool sampler_less = shader->samplerLess(check_pass) || - CVS->isARBBindlessTextureUsable() || - CVS->useArrayTextures(); + const bool sampler_less = shader->samplerLess(check_pass); auto& ret = g_draw_calls[dc_type][shader]; if (sampler_less) { @@ -1443,17 +1434,9 @@ void handleDynamicDrawCall() if (dc_type == 0) { auto& ret = g_draw_calls[DCT_TRANSPARENT][shader]; - if (CVS->isARBBindlessTextureUsable() || - CVS->useArrayTextures()) + for (auto& p : dydc->getTextureCompare()) { - ret[""].insert(dydc); - } - else - { - for (auto& p : dydc->getTextureCompare()) - { - ret[p.first].insert(dydc); - } + ret[p.first].insert(dydc); } } else @@ -1466,9 +1449,7 @@ void handleDynamicDrawCall() // Check if shader for render pass uses mesh samplers const RenderPass check_pass = dc_type == DCT_NORMAL ? RP_1ST : RP_SHADOW; - const bool sampler_less = shader->samplerLess(check_pass) || - CVS->isARBBindlessTextureUsable() || - CVS->useArrayTextures(); + const bool sampler_less = shader->samplerLess(check_pass); auto& ret = g_draw_calls[dc_type][shader]; if (sampler_less) { @@ -1724,20 +1705,14 @@ void draw(RenderPass rp, DrawCallType dct) p.first->bindPrefilledTextures(rp); for (unsigned j = 0; j < p.second.size(); j++) { - if (!(CVS->isARBBindlessTextureUsable() || - CVS->useArrayTextures())) - { - p.first->bindTextures(p.second[j].first, rp); - } + p.first->bindTextures(p.second[j].first, rp); for (unsigned k = 0; k < p.second[j].second.size(); k++) { static std::vector draw_call_uniforms; p.first->setUniformsPerObject(static_cast (p.second[j].second[k].first), &draw_call_uniforms, rp); p.second[j].second[k].first->draw(dct, - p.second[j].second[k].second/*material_id*/, - CVS->isARBBindlessTextureUsable() || - CVS->useArrayTextures()); + p.second[j].second[k].second/*material_id*/); for (SPUniformAssigner* ua : draw_call_uniforms) { ua->reset(); diff --git a/src/graphics/sp/sp_base.hpp b/src/graphics/sp/sp_base.hpp index 607867d8d..134690373 100644 --- a/src/graphics/sp/sp_base.hpp +++ b/src/graphics/sp/sp_base.hpp @@ -87,7 +87,7 @@ class SPMeshBuffer; extern GLuint sp_mat_ubo[MAX_PLAYER_COUNT][3]; extern GLuint sp_fog_ubo; extern bool sp_first_frame; -extern std::vector sp_prefilled_tex; +extern std::array sp_prefilled_tex; extern unsigned sp_solid_poly_count; extern unsigned sp_shadow_poly_count; extern int sp_cur_shadow_cascade; diff --git a/src/graphics/sp/sp_dynamic_draw_call.cpp b/src/graphics/sp/sp_dynamic_draw_call.cpp index e47c3e552..cfe9e841c 100644 --- a/src/graphics/sp/sp_dynamic_draw_call.cpp +++ b/src/graphics/sp/sp_dynamic_draw_call.cpp @@ -54,8 +54,7 @@ SPDynamicDrawCall::SPDynamicDrawCall(scene::E_PRIMITIVE_TYPE pt, glBufferData(GL_ARRAY_BUFFER, 4 * 48, NULL, GL_DYNAMIC_DRAW); glGenBuffers(1, &m_ibo); glBindBuffer(GL_ARRAY_BUFFER, m_ibo); - glBufferData(GL_ARRAY_BUFFER, 32 + 48/*Max textures handles*/, NULL, - GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, 32, NULL, GL_DYNAMIC_DRAW); SPInstancedData id = SPInstancedData(m_trans, 0.0f, 0.0f, 0.0f, 0); glBufferSubData(GL_ARRAY_BUFFER, 0, 32, &id); SPTextureManager::get()->increaseGLCommandFunctionCount(1); @@ -119,53 +118,27 @@ SPDynamicDrawCall::SPDynamicDrawCall(scene::E_PRIMITIVE_TYPE pt, glBindBuffer(GL_ARRAY_BUFFER, m_ibo); // Origin glEnableVertexAttribArray(8); - glVertexAttribPointer(8, 3, GL_FLOAT, GL_FALSE, 32 + 48, (void*)0); + glVertexAttribPointer(8, 3, GL_FLOAT, GL_FALSE, 32, (void*)0); glVertexAttribDivisorARB(8, 1); // Rotation (quaternion .xyz) glEnableVertexAttribArray(9); glVertexAttribPointer(9, 4, GL_INT_2_10_10_10_REV, GraphicsRestrictions::isDisabled (GraphicsRestrictions::GR_CORRECT_10BIT_NORMALIZATION) ? - GL_FALSE : GL_TRUE, 32 + 48, (void*)12); + GL_FALSE : GL_TRUE, 32, (void*)12); glVertexAttribDivisorARB(9, 1); // Scale (3 half floats and .w for quaternion .w) glEnableVertexAttribArray(10); - glVertexAttribPointer(10, 4, GL_HALF_FLOAT, GL_FALSE, 32 + 48, (void*)16); + glVertexAttribPointer(10, 4, GL_HALF_FLOAT, GL_FALSE, 32, (void*)16); glVertexAttribDivisorARB(10, 1); // Texture translation glEnableVertexAttribArray(11); - glVertexAttribPointer(11, 2, GL_HALF_FLOAT, GL_FALSE, 32 + 48, (void*)24); + glVertexAttribPointer(11, 2, GL_HALF_FLOAT, GL_FALSE, 32, (void*)24); glVertexAttribDivisorARB(11, 1); // Misc data (skinning offset and hue change) glEnableVertexAttribArray(12); - glVertexAttribIPointer(12, 2, GL_SHORT, 32 + 48, (void*)28); + glVertexAttribIPointer(12, 2, GL_SHORT, 32, (void*)28); glVertexAttribDivisorARB(12, 1); - - if (CVS->useArrayTextures()) - { - // uvec4 + uvec2 for 6 texture array indices - glEnableVertexAttribArray(13); - glVertexAttribIPointer(13, 4, GL_UNSIGNED_SHORT, 32 + 48, (void*)32); - glVertexAttribDivisorARB(13, 1); - glEnableVertexAttribArray(14); - glVertexAttribIPointer(14, 2, GL_UNSIGNED_SHORT, 32 + 48, (void*)40); - glVertexAttribDivisorARB(14, 1); - glDisableVertexAttribArray(15); - } - else if (CVS->isARBBindlessTextureUsable()) - { - // 3 * 2 uvec2 for bindless samplers - glEnableVertexAttribArray(13); - glVertexAttribIPointer(13, 4, GL_UNSIGNED_INT, 32 + 48, (void*)32); - glVertexAttribDivisorARB(13, 1); - glEnableVertexAttribArray(14); - glVertexAttribIPointer(14, 4, GL_UNSIGNED_INT, 32 + 48, (void*)48); - glVertexAttribDivisorARB(14, 1); - glEnableVertexAttribArray(15); - glVertexAttribIPointer(15, 4, GL_UNSIGNED_INT, 32 + 48, (void*)64); - glVertexAttribDivisorARB(15, 1); - } - glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); #endif @@ -185,29 +158,6 @@ bool SPDynamicDrawCall::initTextureDyDc() } } } - if (!(CVS->useArrayTextures() || CVS->isARBBindlessTextureUsable())) - { - return true; - } - glBindBuffer(GL_ARRAY_BUFFER, m_ibo); - if (CVS->useArrayTextures()) - { - for (unsigned i = 0; i < 6; i++) - { - uint16_t array_index = (uint16_t) - m_textures[0][i]->getTextureArrayIndex(); - glBufferSubData(GL_ARRAY_BUFFER, 32 + (i * 2), 2, &array_index); - } - } - else - { - for (unsigned i = 0; i < 6; i++) - { - glBufferSubData(GL_ARRAY_BUFFER, 32 + (i * 8), 8, - m_textures[0][i]->getTextureHandlePointer()); - } - } - glBindBuffer(GL_ARRAY_BUFFER, 0); #endif return true; } // initTextureDyDc diff --git a/src/graphics/sp/sp_dynamic_draw_call.hpp b/src/graphics/sp/sp_dynamic_draw_call.hpp index ef68795c7..34a17f863 100644 --- a/src/graphics/sp/sp_dynamic_draw_call.hpp +++ b/src/graphics/sp/sp_dynamic_draw_call.hpp @@ -70,8 +70,8 @@ public: // ------------------------------------------------------------------------ ~SPDynamicDrawCall() {} // ------------------------------------------------------------------------ - virtual void draw(DrawCallType dct = DCT_NORMAL, int material_id = -1, - bool bindless_texture = false) const + virtual void draw(DrawCallType dct = DCT_NORMAL, + int material_id = -1) const { #ifndef SERVER_ONLY glBindVertexArray(m_vao[0]); @@ -92,7 +92,7 @@ public: SPInstancedData id = SPInstancedData(getAbsoluteTransformation(), m_texture_trans.X, m_texture_trans.Y, 0.0f, 0); glBindBuffer(GL_ARRAY_BUFFER, m_ibo); - glBufferSubData(GL_ARRAY_BUFFER, 0, 32, &id); + glBufferSubData(GL_ARRAY_BUFFER, 0, 32, id.getData()); glBindBuffer(GL_ARRAY_BUFFER, 0); } if (m_update_offset >= 0 && !m_vertices.empty()) diff --git a/src/graphics/sp/sp_mesh_buffer.cpp b/src/graphics/sp/sp_mesh_buffer.cpp index 6531dc08c..9283827bc 100644 --- a/src/graphics/sp/sp_mesh_buffer.cpp +++ b/src/graphics/sp/sp_mesh_buffer.cpp @@ -98,48 +98,6 @@ bool SPMeshBuffer::initTexture() } } } - if (!(CVS->useArrayTextures() || CVS->isARBBindlessTextureUsable())) - { - return true; - } - glBindBuffer(GL_ARRAY_BUFFER, m_vbo); - std::set used_vertices; - for (unsigned int j = 0; j < getIndexCount(); j += 3) - { - for (unsigned int k = 0; k < 3; k++) - { - const uint16_t vertex_id = m_indices[j + k]; - auto ret = used_vertices.find(vertex_id); - if (ret == used_vertices.end()) - { - used_vertices.insert(vertex_id); - std::array, 6> textures = - getSPTextures(j); - if (CVS->useArrayTextures()) - { - for (unsigned i = 0; i < 6; i++) - { - uint16_t array_index = (uint16_t) - textures[i]->getTextureArrayIndex(); - glBufferSubData(GL_ARRAY_BUFFER, - (vertex_id * m_pitch) + (m_pitch - 12) + (i * 2), - 2, &array_index); - } - } - else - { - for (unsigned i = 0; i < 6; i++) - { - glBufferSubData(GL_ARRAY_BUFFER, - (vertex_id * m_pitch) + (m_pitch - 48) + (i * 8), - 8, textures[i]->getTextureHandlePointer()); - } - } - } - } - } - assert(used_vertices.size() == m_vertices.size()); - glBindBuffer(GL_ARRAY_BUFFER, 0); #endif return true; } // initTexture @@ -176,8 +134,7 @@ void SPMeshBuffer::uploadGLMesh() std::get<2>(m_stk_material[0])->getShaderName() == "normalmap" && CVS->isDefferedEnabled(); const unsigned pitch = 48 - (use_tangents ? 0 : 4) - (use_2_uv ? 0 : 4) - - (m_skinned ? 0 : 16) + (CVS->useArrayTextures() ? 12 : - CVS->isARBBindlessTextureUsable() ? 48 : 0); + (m_skinned ? 0 : 16); m_pitch = pitch; if (m_vbo != 0) @@ -373,36 +330,9 @@ void SPMeshBuffer::recreateVAO(unsigned i) glDisableVertexAttribArray(6); glDisableVertexAttribArray(7); } - - if (CVS->useArrayTextures()) - { - // uvec4 + uvec2 for 6 texture array indices - glEnableVertexAttribArray(13); - glVertexAttribIPointer(13, 4, GL_UNSIGNED_SHORT, pitch, (void*)offset); - offset += 8; - glEnableVertexAttribArray(14); - glVertexAttribIPointer(14, 2, GL_UNSIGNED_SHORT, pitch, (void*)offset); - offset += 4; - glDisableVertexAttribArray(15); - } - else if (CVS->isARBBindlessTextureUsable()) - { - // 3 * 2 uvec2 for bindless samplers - glEnableVertexAttribArray(13); - glVertexAttribIPointer(13, 4, GL_UNSIGNED_INT, pitch, (void*)offset); - offset += 16; - glEnableVertexAttribArray(14); - glVertexAttribIPointer(14, 4, GL_UNSIGNED_INT, pitch, (void*)offset); - offset += 16; - glEnableVertexAttribArray(15); - glVertexAttribIPointer(15, 4, GL_UNSIGNED_INT, pitch, (void*)offset); - } - else - { - glDisableVertexAttribArray(13); - glDisableVertexAttribArray(14); - glDisableVertexAttribArray(15); - } + glDisableVertexAttribArray(13); + glDisableVertexAttribArray(14); + glDisableVertexAttribArray(15); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); glBindBuffer(GL_ARRAY_BUFFER, m_ins_array[i]); diff --git a/src/graphics/sp/sp_mesh_buffer.hpp b/src/graphics/sp/sp_mesh_buffer.hpp index 332688df5..0f2ae3c3d 100644 --- a/src/graphics/sp/sp_mesh_buffer.hpp +++ b/src/graphics/sp/sp_mesh_buffer.hpp @@ -109,31 +109,15 @@ public: // ------------------------------------------------------------------------ ~SPMeshBuffer(); // ------------------------------------------------------------------------ - virtual void draw(DrawCallType dct = DCT_NORMAL, int material_id = -1, - bool bindless_texture = false) const + virtual void draw(DrawCallType dct = DCT_NORMAL, int material_id = -1) const { #ifndef SERVER_ONLY glBindVertexArray(m_vao[dct]); - if (material_id == -1 || bindless_texture) + if (material_id == -1) { - /*if (bindless_texture) - // Only nvidia gpu allow texture with non-dynamically-uniform - // handles (texture handles that aren't constant within a same draw) - { - for (unsigned i = 0; i < m_stk_material.size(); i++) - { - glDrawElementsInstanced(GL_TRIANGLES, - std::get<1>(m_stk_material[i]), - GL_UNSIGNED_SHORT, - (void*)(std::get<0>(m_stk_material[i]) << 1), - (unsigned)m_ins_dat[dct].size()); - } - } - else*/ - { - glDrawElementsInstanced(GL_TRIANGLES, getIndexCount(), - GL_UNSIGNED_SHORT, 0, (unsigned)m_ins_dat[dct].size()); - } + // Draw whole mesh buffer, usually in shadow pass + glDrawElementsInstanced(GL_TRIANGLES, getIndexCount(), + GL_UNSIGNED_SHORT, 0, (unsigned)m_ins_dat[dct].size()); } else { diff --git a/src/graphics/sp/sp_shader.cpp b/src/graphics/sp/sp_shader.cpp index 4fe0181b4..63b2188bc 100644 --- a/src/graphics/sp/sp_shader.cpp +++ b/src/graphics/sp/sp_shader.cpp @@ -30,11 +30,10 @@ namespace SP std::unordered_map > g_prefilled_names = { - { "tex_array", { 0, ST_TRILINEAR } } #ifdef USE_GLES2 - ,{ "skinning_tex", { 1, ST_NEAREST_CLAMPED } } + { "skinning_tex", { 0, ST_NEAREST_CLAMPED } } #else - ,{ "skinning_tex", { 1, ST_TEXTURE_BUFFER } } + { "skinning_tex", { 0, ST_TEXTURE_BUFFER } } #endif }; diff --git a/src/graphics/sp/sp_texture.cpp b/src/graphics/sp/sp_texture.cpp index e399ea106..610b665b3 100644 --- a/src/graphics/sp/sp_texture.cpp +++ b/src/graphics/sp/sp_texture.cpp @@ -53,15 +53,11 @@ namespace SP { // ---------------------------------------------------------------------------- SPTexture::SPTexture(const std::string& path, Material* m, bool undo_srgb, - int ta_idx, const std::string& container_id) - : m_path(path), m_texture_array_idx(ta_idx), m_width(0), m_height(0), - m_material(m), m_undo_srgb(undo_srgb) + const std::string& container_id) + : m_path(path), m_width(0), m_height(0), m_material(m), + m_undo_srgb(undo_srgb) { #ifndef SERVER_ONLY - if (CVS->useArrayTextures()) - { - return; - } glGenTextures(1, &m_texture_name); createWhite(false/*private_init*/); @@ -89,18 +85,10 @@ SPTexture::SPTexture(const std::string& path, Material* m, bool undo_srgb, } // SPTexture // ---------------------------------------------------------------------------- -SPTexture::SPTexture(bool white, int ta_idx) - : m_texture_array_idx(ta_idx), m_width(0), m_height(0), - m_undo_srgb(false) +SPTexture::SPTexture(bool white) + : m_width(0), m_height(0), m_undo_srgb(false) { #ifndef SERVER_ONLY - if (CVS->useArrayTextures()) - { - m_width.store(irr_driver->getVideoDriver()->getDriverAttributes() - .getAttributeAsDimension2d("MAX_TEXTURE_SIZE").Width); - m_height.store(m_width.load()); - return; - } glGenTextures(1, &m_texture_name); if (white) { @@ -110,7 +98,6 @@ SPTexture::SPTexture(bool white, int ta_idx) { createTransparent(); } - addTextureHandle(); #endif } // SPTexture @@ -118,12 +105,6 @@ SPTexture::SPTexture(bool white, int ta_idx) SPTexture::~SPTexture() { #ifndef SERVER_ONLY -#if !(defined(SERVER_ONLY) || defined(USE_GLES2)) - if (m_texture_handle != 0 && CVS->isARBBindlessTextureUsable()) - { - glMakeTextureHandleNonResidentARB(m_texture_handle); - } -#endif if (m_texture_name != 0) { glDeleteTextures(1, &m_texture_name); @@ -131,19 +112,6 @@ SPTexture::~SPTexture() #endif } // ~SPTexture -// ---------------------------------------------------------------------------- -void SPTexture::addTextureHandle() -{ -#if !(defined(SERVER_ONLY) || defined(USE_GLES2)) - if (CVS->isARBBindlessTextureUsable()) - { - m_texture_handle = glGetTextureSamplerHandleARB(m_texture_name, - getSampler(ST_TRILINEAR)); - glMakeTextureHandleResidentARB(m_texture_handle); - } -#endif -} // addTextureHandle - // ---------------------------------------------------------------------------- std::shared_ptr SPTexture::getImageFromPath (const std::string& path) const @@ -192,11 +160,11 @@ std::shared_ptr SPTexture::getTextureImage() const const core::dimension2du& max_size = irr_driver->getVideoDriver() ->getDriverAttributes().getAttributeAsDimension2d("MAX_TEXTURE_SIZE"); - if (tex_size.Width > max_size.Width || CVS->useArrayTextures()) + if (tex_size.Width > max_size.Width) { tex_size.Width = max_size.Width; } - if (tex_size.Height > max_size.Height || CVS->useArrayTextures()) + if (tex_size.Height > max_size.Height) { tex_size.Height = max_size.Height; } @@ -254,7 +222,7 @@ bool SPTexture::compressedTexImage2d(std::shared_ptr texture, #ifndef SERVER_ONLY unsigned format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; #ifndef USE_GLES2 - if (m_undo_srgb && !CVS->useArrayTextures()) + if (m_undo_srgb) { format = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; } @@ -273,96 +241,12 @@ bool SPTexture::compressedTexImage2d(std::shared_ptr texture, compressed += cur_mipmap_size; } glBindTexture(GL_TEXTURE_2D, 0); - addTextureHandle(); m_width.store(mipmap_sizes[0].first.Width); m_height.store(mipmap_sizes[0].first.Height); #endif return true; } // compressedTexImage2d -// ---------------------------------------------------------------------------- -bool SPTexture::compressedTexImage3d(std::shared_ptr texture, - const std::vector >& - mipmap_sizes) -{ -#ifndef SERVER_ONLY - assert(m_texture_array_idx != -1); - glBindTexture(GL_TEXTURE_2D_ARRAY, - SPTextureManager::get()->getTextureArrayName()); - uint8_t* compressed = (uint8_t*)texture->lock(); - unsigned cur_mipmap_size = 0; - for (unsigned i = 0; i < mipmap_sizes.size(); i++) - { - cur_mipmap_size = mipmap_sizes[i].second; - glCompressedTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, - 0, 0, m_texture_array_idx, - mipmap_sizes[i].first.Width, mipmap_sizes[i].first.Height, 1, - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, cur_mipmap_size, compressed); - compressed += cur_mipmap_size; - } - glBindTexture(GL_TEXTURE_2D_ARRAY, 0); - m_width.store(mipmap_sizes[0].first.Width); - m_height.store(mipmap_sizes[0].first.Height); -#endif - return true; -} // compressedTexImage3d - -// ---------------------------------------------------------------------------- -bool SPTexture::texImage3d(std::shared_ptr texture, - std::shared_ptr mipmaps) -{ -#ifndef SERVER_ONLY - assert(m_texture_array_idx != -1); - if (texture) - { -#ifdef USE_GLES2 - unsigned upload_format = GL_RGBA; -#else - unsigned upload_format = GL_BGRA; -#endif - glBindTexture(GL_TEXTURE_2D_ARRAY, - SPTextureManager::get()->getTextureArrayName()); - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, m_texture_array_idx, - texture->getDimension().Width, texture->getDimension().Height, - 1, upload_format, GL_UNSIGNED_BYTE, texture->lock()); - - assert(mipmaps); - std::vector > - mipmap_sizes; - unsigned width = texture->getDimension().Width; - unsigned height = texture->getDimension().Height; - mipmap_sizes.emplace_back(core::dimension2du(width, height), - width * height * 4); - while (true) - { - width = width < 2 ? 1 : width >> 1; - height = height < 2 ? 1 : height >> 1; - mipmap_sizes.emplace_back - (core::dimension2du(width, height), width * height * 4); - if (width == 1 && height == 1) - { - break; - } - } - uint8_t* ptr = (uint8_t*)mipmaps->lock(); - for (unsigned i = 1; i < mipmap_sizes.size(); i++) - { - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, 0, 0, m_texture_array_idx, - mipmap_sizes[i].first.Width, mipmap_sizes[i].first.Height, - 1, upload_format, GL_UNSIGNED_BYTE, ptr); - ptr += mipmap_sizes[i].second; - } - - glBindTexture(GL_TEXTURE_2D_ARRAY, 0); - } - m_width.store(irr_driver->getVideoDriver()->getDriverAttributes() - .getAttributeAsDimension2d("MAX_TEXTURE_SIZE").Width); - m_height.store(m_width.load()); -#endif - return true; -} // texImage3d - // ---------------------------------------------------------------------------- bool SPTexture::texImage2d(std::shared_ptr texture, std::shared_ptr mipmaps) @@ -415,7 +299,6 @@ bool SPTexture::texImage2d(std::shared_ptr texture, } glBindTexture(GL_TEXTURE_2D, 0); } - addTextureHandle(); if (texture) { m_width.store(texture->getDimension().Width); @@ -565,29 +448,45 @@ bool SPTexture::threadedLoad() applyMask(image.get(), mask.get()); } std::shared_ptr mipmaps; - if (CVS->useArrayTextures()) + + if (!m_cache_directory.empty() && + CVS->isTextureCompressionEnabled() && image && + image->getDimension().Width >= 4 && + image->getDimension().Height >= 4) { - if (CVS->isTextureCompressionEnabled()) + auto r = compressTexture(image); + SPTextureManager::get()->increaseGLCommandFunctionCount(1); + SPTextureManager::get()->addGLCommandFunction( + [this, image, r]()->bool + { return compressedTexImage2d(image, r); }); + if (!cache_loc.empty()) { - auto r = compressTexture(image); - SPTextureManager::get()->increaseGLCommandFunctionCount(1); - SPTextureManager::get()->addGLCommandFunction( - [this, image, r]()->bool - { return compressedTexImage3d(image, r); }); + SPTextureManager::get()->addThreadedFunction( + [this, image, r, cache_loc]()->bool + { + return saveCompressedTexture(image, r, cache_loc); + }); } - else + } + else + { +#ifndef USE_GLES2 + if (UserConfigParams::m_hq_mipmap && image && + image->getDimension().Width > 1 && + image->getDimension().Height > 1) { std::vector > mipmap_sizes; unsigned width = image->getDimension().Width; unsigned height = image->getDimension().Height; - mipmap_sizes.emplace_back(core::dimension2du(width, height), 0); + mipmap_sizes.emplace_back(core::dimension2du(width, height), + 0); while (true) { width = width < 2 ? 1 : width >> 1; height = height < 2 ? 1 : height >> 1; - mipmap_sizes.emplace_back(core::dimension2du(width, height), - 0); + mipmap_sizes.emplace_back + (core::dimension2du(width, height), 0); if (width == 1 && height == 1) { break; @@ -595,71 +494,16 @@ bool SPTexture::threadedLoad() } mipmaps.reset(irr_driver->getVideoDriver()->createImage (video::ECF_A8R8G8B8, mipmap_sizes[0].first)); - generateQuickMipmap(image, mipmap_sizes, + generateHQMipmap(image->lock(), mipmap_sizes, (uint8_t*)mipmaps->lock()); - SPTextureManager::get()->increaseGLCommandFunctionCount(1); - SPTextureManager::get()->addGLCommandFunction( - [this, image, mipmaps]()->bool - { return texImage3d(image, mipmaps); }); } - } - else - { - if (!m_cache_directory.empty() && - CVS->isTextureCompressionEnabled() && image && - image->getDimension().Width >= 4 && - image->getDimension().Height >= 4) - { - auto r = compressTexture(image); - SPTextureManager::get()->increaseGLCommandFunctionCount(1); - SPTextureManager::get()->addGLCommandFunction( - [this, image, r]()->bool - { return compressedTexImage2d(image, r); }); - if (!cache_loc.empty()) - { - SPTextureManager::get()->addThreadedFunction( - [this, image, r, cache_loc]()->bool - { - return saveCompressedTexture(image, r, cache_loc); - }); - } - } - else - { -#ifndef USE_GLES2 - if (UserConfigParams::m_hq_mipmap && image && - image->getDimension().Width > 1 && - image->getDimension().Height > 1) - { - std::vector > - mipmap_sizes; - unsigned width = image->getDimension().Width; - unsigned height = image->getDimension().Height; - mipmap_sizes.emplace_back(core::dimension2du(width, height), - 0); - while (true) - { - width = width < 2 ? 1 : width >> 1; - height = height < 2 ? 1 : height >> 1; - mipmap_sizes.emplace_back - (core::dimension2du(width, height), 0); - if (width == 1 && height == 1) - { - break; - } - } - mipmaps.reset(irr_driver->getVideoDriver()->createImage - (video::ECF_A8R8G8B8, mipmap_sizes[0].first)); - generateHQMipmap(image->lock(), mipmap_sizes, - (uint8_t*)mipmaps->lock()); - } #endif - SPTextureManager::get()->increaseGLCommandFunctionCount(1); - SPTextureManager::get()->addGLCommandFunction( - [this, image, mipmaps]()->bool - { return texImage2d(image, mipmaps); }); - } + SPTextureManager::get()->increaseGLCommandFunctionCount(1); + SPTextureManager::get()->addGLCommandFunction( + [this, image, mipmaps]()->bool + { return texImage2d(image, mipmaps); }); } + #endif return true; } // threadedLoad @@ -798,12 +642,6 @@ void SPTexture::applyMask(video::IImage* texture, video::IImage* mask) // ---------------------------------------------------------------------------- bool SPTexture::initialized() const { -#ifndef SERVER_ONLY - if (CVS->isARBBindlessTextureUsable()) - { - return m_texture_handle != 0; - } -#endif return m_width.load() != 0 && m_height.load() != 0; } // initialized @@ -931,9 +769,8 @@ std::vector > break; } } - // For array textures all textures need to have a same internal format + const unsigned tc_flag = squish::kDxt5 | stk_config->m_tc_quality; -// | (m_undo_srgb && CVS->useArrayTextures() ? squish::kToLinear : 0); const unsigned compressed_size = squish::GetStorageRequirements( mipmap_sizes[0].first.Width, mipmap_sizes[0].first.Height, tc_flag); diff --git a/src/graphics/sp/sp_texture.hpp b/src/graphics/sp/sp_texture.hpp index 78ca8df39..cd1508246 100644 --- a/src/graphics/sp/sp_texture.hpp +++ b/src/graphics/sp/sp_texture.hpp @@ -48,16 +48,12 @@ private: std::string m_cache_directory; - int m_texture_array_idx; - GLuint m_texture_name = 0; std::atomic_uint m_width; std::atomic_uint m_height; - uint64_t m_texture_handle = 0; - Material* m_material; const bool m_undo_srgb; @@ -141,22 +137,15 @@ private: #endif } // ------------------------------------------------------------------------ - SPTexture(bool white, int ta_idx); + SPTexture(bool white); // ------------------------------------------------------------------------ bool texImage2d(std::shared_ptr texture, std::shared_ptr mipmaps); // ------------------------------------------------------------------------ - bool texImage3d(std::shared_ptr texture, - std::shared_ptr mipmaps); - // ------------------------------------------------------------------------ bool compressedTexImage2d(std::shared_ptr texture, const std::vector >& mipmap_sizes); // ------------------------------------------------------------------------ - bool compressedTexImage3d(std::shared_ptr texture, - const std::vector >& mipmap_sizes); - // ------------------------------------------------------------------------ bool saveCompressedTexture(std::shared_ptr texture, const std::vector >& sizes, @@ -174,19 +163,19 @@ public: // ------------------------------------------------------------------------ static std::shared_ptr getWhiteTexture() { - SPTexture* tex = new SPTexture(true/*white*/, 0); + SPTexture* tex = new SPTexture(true/*white*/); tex->m_path = "unicolor_white"; return std::shared_ptr(tex); } // ------------------------------------------------------------------------ static std::shared_ptr getTransparentTexture() { - SPTexture* tex = new SPTexture(false/*white*/, 1); + SPTexture* tex = new SPTexture(false/*white*/); return std::shared_ptr(tex); } // ------------------------------------------------------------------------ SPTexture(const std::string& path, Material* m, bool undo_srgb, - int ta_idx, const std::string& container_id); + const std::string& container_id); // ------------------------------------------------------------------------ ~SPTexture(); // ------------------------------------------------------------------------ @@ -196,14 +185,6 @@ public: // ------------------------------------------------------------------------ GLuint getOpenGLTextureName() const { return m_texture_name; } // ------------------------------------------------------------------------ - uint64_t getTextureHandle() const { return m_texture_handle; } - // ------------------------------------------------------------------------ - const uint64_t* getTextureHandlePointer() const - { - assert(m_texture_handle != 0); - return &m_texture_handle; - } - // ------------------------------------------------------------------------ bool initialized() const; // ------------------------------------------------------------------------ unsigned getWidth() const { return m_width.load(); } @@ -211,8 +192,7 @@ public: unsigned getHeight() const { return m_height.load(); } // ------------------------------------------------------------------------ bool threadedLoad(); - // ------------------------------------------------------------------------ - int getTextureArrayIndex() const { return m_texture_array_idx; } + }; diff --git a/src/graphics/sp/sp_texture_manager.cpp b/src/graphics/sp/sp_texture_manager.cpp index ef135cc1b..c89dc179f 100644 --- a/src/graphics/sp/sp_texture_manager.cpp +++ b/src/graphics/sp/sp_texture_manager.cpp @@ -27,11 +27,6 @@ #include -const int MAX_TA = 256; -#ifndef USE_GLES2 -#include -#endif - namespace SP { SPTextureManager* SPTextureManager::m_sptm = NULL; @@ -76,17 +71,6 @@ SPTextureManager::SPTextureManager() } }); } - - if (CVS->useArrayTextures()) - { - Log::info("SPTextureManager", "Enable array textures, size %d", - irr_driver->getVideoDriver()->getDriverAttributes() - .getAttributeAsDimension2d("MAX_TEXTURE_SIZE").Width); - glGenTextures(1, &m_all_textures_array); - sp_prefilled_tex[0] = m_all_textures_array; - initTextureArray(); - } - m_textures["unicolor_white"] = SPTexture::getWhiteTexture(); m_textures[""] = SPTexture::getTransparentTexture(); } // SPTextureManager @@ -104,81 +88,8 @@ SPTextureManager::~SPTextureManager() t.join(); } m_threaded_load_obj.clear(); - if (m_all_textures_array != 0) - { - glDeleteTextures(1, &m_all_textures_array); - } } // ~SPTextureManager -// ---------------------------------------------------------------------------- -void SPTextureManager::initTextureArray() -{ -#ifdef USE_GLES2 - unsigned upload_format = GL_RGBA; -#else - unsigned upload_format = GL_BGRA; -#endif - const unsigned size = irr_driver->getVideoDriver()->getDriverAttributes() - .getAttributeAsDimension2d("MAX_TEXTURE_SIZE").Width; - std::vector white, transparent; - white.resize(size * size, -1); - transparent.resize(size * size, 0); - glBindTexture(GL_TEXTURE_2D_ARRAY, m_all_textures_array); -#if !(defined(SERVER_ONLY) || defined(USE_GLES2)) - if (CVS->isTextureCompressionEnabled()) - { - std::vector > mipmap_sizes; - unsigned width = size; - unsigned height = size; - mipmap_sizes.emplace_back(core::dimension2du(width, height), - squish::GetStorageRequirements(width, height, squish::kDxt5)); - while (true) - { - width = width < 2 ? 1 : width >> 1; - height = height < 2 ? 1 : height >> 1; - mipmap_sizes.emplace_back(core::dimension2du(width, height), - squish::GetStorageRequirements(width, height, squish::kDxt5)); - if (width == 1 && height == 1) - { - break; - } - } - unsigned cur_mipmap_size = 0; - for (unsigned i = 0; i < mipmap_sizes.size(); i++) - { - cur_mipmap_size = mipmap_sizes[i].second; - glCompressedTexImage3D(GL_TEXTURE_2D_ARRAY, i, - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, - mipmap_sizes[i].first.Width, mipmap_sizes[i].first.Height, - MAX_TA, 0, cur_mipmap_size * MAX_TA, NULL); - glCompressedTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, - 0, 0, 0, - mipmap_sizes[i].first.Width, mipmap_sizes[i].first.Height, 1, - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, cur_mipmap_size, - white.data()); - glCompressedTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, - 0, 0, 1, - mipmap_sizes[i].first.Width, mipmap_sizes[i].first.Height, 1, - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, cur_mipmap_size, - transparent.data()); - } - } - else -#endif - { - glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, - size, size, MAX_TA, 0, upload_format, GL_UNSIGNED_BYTE, NULL); - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, - size, size, 1, upload_format, GL_UNSIGNED_BYTE, - white.data()); - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, - size, size, 1, upload_format, GL_UNSIGNED_BYTE, - transparent.data()); - glGenerateMipmap(GL_TEXTURE_2D_ARRAY); - } - glBindTexture(GL_TEXTURE_2D_ARRAY, 0); -} // initTextureArray - // ---------------------------------------------------------------------------- void SPTextureManager::checkForGLCommand(bool before_scene) { @@ -234,21 +145,8 @@ std::shared_ptr SPTextureManager::getTexture(const std::string& p, { return ret->second; } - int ta_idx = -1; - - if (CVS->useArrayTextures()) - { - ta_idx = getTextureArrayIndex(); - if (ta_idx > MAX_TA) - { - Log::error("SPTextureManager", "Too many textures"); - // Give user a transparent texture - return m_textures.at(""); - } - } - std::shared_ptr t = - std::make_shared(p, m, undo_srgb, ta_idx, cid); + std::make_shared(p, m, undo_srgb, cid); addThreadedFunction(std::bind(&SPTexture::threadedLoad, t)); m_textures[p] = t; return t; @@ -261,11 +159,6 @@ void SPTextureManager::removeUnusedTextures() { if (it->second.use_count() == 1) { - int ta_idx = it->second->getTextureArrayIndex(); - if (ta_idx != -1) - { - m_freed_texture_array_idx.push_back(ta_idx); - } it = m_textures.erase(it); } else diff --git a/src/graphics/sp/sp_texture_manager.hpp b/src/graphics/sp/sp_texture_manager.hpp index 5f5a2d461..21707a1ac 100644 --- a/src/graphics/sp/sp_texture_manager.hpp +++ b/src/graphics/sp/sp_texture_manager.hpp @@ -47,8 +47,6 @@ class SPTextureManager : public NoCopy private: static SPTextureManager* m_sptm; - GLuint m_all_textures_array = 0; - std::unordered_map > m_textures; std::atomic_uint m_max_threaded_load_obj; @@ -65,11 +63,6 @@ private: std::list m_threaded_load_obj; - std::list m_freed_texture_array_idx; - - // ------------------------------------------------------------------------ - void initTextureArray(); - public: // ------------------------------------------------------------------------ static SPTextureManager* get() @@ -118,19 +111,7 @@ public: int dumpTextureUsage(); // ------------------------------------------------------------------------ void dumpAllTexture(); - // ------------------------------------------------------------------------ - int getTextureArrayIndex() - { - if (!m_freed_texture_array_idx.empty()) - { - int ret = m_freed_texture_array_idx.front(); - m_freed_texture_array_idx.pop_front(); - return ret; - } - return (int)m_textures.size(); - } - // ------------------------------------------------------------------------ - GLuint getTextureArrayName() const { return m_all_textures_array; } + }; }