Skip to content

Commit

Permalink
Guarantee 2048 bones
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed May 29, 2024
1 parent 7320f2e commit 84dff44
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
4 changes: 2 additions & 2 deletions data/shaders/sp_skinning.vert
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef TBO_DISABLED
#ifdef SKINNING_TBO_DISABLED
uniform sampler2D skinning_tex;
#else
uniform samplerBuffer skinning_tex;
Expand Down Expand Up @@ -58,7 +58,7 @@ void main()
vec4 skinned_tangent = vec4(0.0);
int skinning_offset = i_misc_data.x;

#ifdef TBO_DISABLED
#ifdef SKINNING_TBO_DISABLED
mat4 joint_matrix =
i_weight[0] * mat4(
texelFetch(skinning_tex, ivec2(0, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES)), 0),
Expand Down
4 changes: 2 additions & 2 deletions data/shaders/sp_skinning_shadow.vert
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uniform int layer;

#ifdef GL_ES
#ifdef SKINNING_TBO_DISABLED
uniform sampler2D skinning_tex;
#else
uniform samplerBuffer skinning_tex;
Expand All @@ -25,7 +25,7 @@ void main()
vec4 skinned_position = vec4(0.0);
int skinning_offset = i_misc_data.x;

#ifdef GL_ES
#ifdef SKINNING_TBO_DISABLED
mat4 joint_matrix =
i_weight[0] * mat4(
texelFetch(skinning_tex, ivec2(0, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES)), 0),
Expand Down
5 changes: 3 additions & 2 deletions data/stk_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,9 @@
<!-- Maximum bones from all animated meshes in each frame to be uploaded for
hardware skinning, For gles 3.0 the specification guarantees at least 2048, for
TBO in desktop at least 65536 (max buffer size) / 64, SSBO at least 2^24 / 64,
so 1024 will work everywhere. -->
<skinning max-bones="1024"/>
and for cases TBO doesn't support equal or more than 2048, use texture instead,
so 2048 will work everywhere. -->
<skinning max-bones="2048"/>

<!-- For users with libsquish:
Use a slow but high quality colour compressor.
Expand Down
5 changes: 3 additions & 2 deletions src/graphics/shader_files_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "config/stk_config.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/graphics_restrictions.hpp"
#include "graphics/sp/sp_base.hpp"
#include "guiengine/message_queue.hpp"
#include "io/file_manager.hpp"
#include "utils/file_utils.hpp"
Expand Down Expand Up @@ -179,8 +180,8 @@ ShaderFilesManager::SharedShader ShaderFilesManager::loadShader
code << "//" << full_path << "\n";
if (!CVS->isARBUniformBufferObjectUsable())
code << "#define UBO_DISABLED\n";
if (!CVS->isARBTextureBufferObjectUsable())
code << "#define TBO_DISABLED\n";
if (!SP::skinningUseTBO())
code << "#define SKINNING_TBO_DISABLED\n";
if (CVS->needsVertexIdWorkaround())
code << "#define Needs_Vertex_Id_Workaround\n";
if (CVS->isDeferredEnabled())
Expand Down
38 changes: 25 additions & 13 deletions src/graphics/sp/sp_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ unsigned g_skinning_offset = 0;
// ----------------------------------------------------------------------------
std::vector<SPMeshNode*> g_skinning_mesh;
// ----------------------------------------------------------------------------
int g_skinning_tbo_limit = 0;
// ----------------------------------------------------------------------------
int sp_cur_shadow_cascade = 0;
// ----------------------------------------------------------------------------
void initSTKRenderer(ShaderBasedRenderer* sbr)
Expand Down Expand Up @@ -251,9 +253,7 @@ void resizeSkinning(unsigned number)
const irr::core::matrix4 m;
g_skinning_size = number;



if (!CVS->isARBTextureBufferObjectUsable())
if (!skinningUseTBO())
{
glBindTexture(GL_TEXTURE_2D, g_skinning_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 4, number, 0, GL_RGBA,
Expand Down Expand Up @@ -302,7 +302,7 @@ void initSkinning()

int max_size = 0;

if (!CVS->isARBTextureBufferObjectUsable())
if (!skinningUseTBO())
{
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);

Expand All @@ -319,12 +319,12 @@ void initSkinning()
else
{
#ifndef USE_GLES2
glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &max_size);
if (stk_config->m_max_skinning_bones << 6 > (unsigned)max_size)
glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &g_skinning_tbo_limit);
if (stk_config->m_max_skinning_bones << 6 > (unsigned)g_skinning_tbo_limit)
{
Log::warn("SharedGPUObjects", "Too many bones for skinning, max: %d",
max_size >> 6);
stk_config->m_max_skinning_bones = max_size >> 6;
g_skinning_tbo_limit >> 6);
stk_config->m_max_skinning_bones = g_skinning_tbo_limit >> 6;
}
Log::info("SharedGPUObjects", "Hardware Skinning enabled, method: TBO, "
"max bones: %u", stk_config->m_max_skinning_bones);
Expand All @@ -337,7 +337,7 @@ void initSkinning()
const irr::core::matrix4 m;
glGenTextures(1, &g_skinning_tex);
#ifndef USE_GLES2
if (CVS->isARBTextureBufferObjectUsable())
if (skinningUseTBO())
{
glGenBuffers(1, &g_skinning_buf);
}
Expand Down Expand Up @@ -442,6 +442,11 @@ void init()
return;
}

if (CVS->isARBTextureBufferObjectUsable())
{
glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_ARB, &g_skinning_tbo_limit);
}

initSkinning();
for (unsigned i = 0; i < MAX_PLAYER_COUNT; i++)
{
Expand Down Expand Up @@ -605,7 +610,7 @@ void destroy()
SPTextureManager::destroy();

#ifndef USE_GLES2
if (CVS->isARBTextureBufferObjectUsable() &&
if (skinningUseTBO() &&
CVS->isARBBufferStorageUsable())
{
glBindBuffer(GL_TEXTURE_BUFFER, g_skinning_buf);
Expand Down Expand Up @@ -647,6 +652,13 @@ SPShader* getNormalVisualizer()
return g_normal_visualizer;
} // getNormalVisualizer

// ----------------------------------------------------------------------------
bool skinningUseTBO()
{
return CVS->isARBTextureBufferObjectUsable()
&& g_skinning_tbo_limit >= 64 * stk_config->m_max_skinning_bones;
}


// ----------------------------------------------------------------------------
inline core::vector3df getCorner(const core::aabbox3df& bbox, unsigned n)
Expand Down Expand Up @@ -1127,7 +1139,7 @@ void uploadSkinningMatrices()

unsigned buffer_offset = 0;
#ifndef USE_GLES2
if (CVS->isARBTextureBufferObjectUsable() &&
if (skinningUseTBO() &&
!CVS->isARBBufferStorageUsable())
{
glBindBuffer(GL_TEXTURE_BUFFER, g_skinning_buf);
Expand All @@ -1146,7 +1158,7 @@ void uploadSkinningMatrices()
buffer_offset += g_skinning_mesh[i]->getTotalJoints();
}

if (!CVS->isARBTextureBufferObjectUsable())
if (!skinningUseTBO())
{
glBindTexture(GL_TEXTURE_2D, g_skinning_tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 1, 4, buffer_offset, GL_RGBA,
Expand All @@ -1155,7 +1167,7 @@ void uploadSkinningMatrices()
}

#ifndef USE_GLES2
if (CVS->isARBTextureBufferObjectUsable() &&
if (skinningUseTBO() &&
!CVS->isARBBufferStorageUsable())
{
glUnmapBuffer(GL_TEXTURE_BUFFER);
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/sp/sp_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ SPShader* getNormalVisualizer();
// ----------------------------------------------------------------------------
SPShader* getGlowShader();
// ----------------------------------------------------------------------------
bool skinningUseTBO();
// ----------------------------------------------------------------------------
void prepareDrawCalls();
// ----------------------------------------------------------------------------
void draw(RenderPass, DrawCallType dct = DCT_NORMAL);
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/sp/sp_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SPShader::SPShader(const std::string& name,
m_use_tangents(use_tangents), m_srgb(srgb)
{
#ifndef SERVER_ONLY
if (CVS->isARBTextureBufferObjectUsable())
if (skinningUseTBO())
{
#ifndef USE_GLES2
m_prefilled_names["skinning_tex"] = std::make_pair<unsigned,
Expand Down

0 comments on commit 84dff44

Please sign in to comment.