Remove synchronization that became unnecessary since C++11.
This commit is contained in:
parent
8ebb622057
commit
2ef0d36569
|
@ -56,28 +56,6 @@
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
sf::Mutex maxTextureUnitsMutex;
|
|
||||||
sf::Mutex isAvailableMutex;
|
|
||||||
|
|
||||||
GLint checkMaxTextureUnits()
|
|
||||||
{
|
|
||||||
GLint maxUnits = 0;
|
|
||||||
glCheck(glGetIntegerv(GLEXT_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxUnits));
|
|
||||||
|
|
||||||
return maxUnits;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve the maximum number of texture units available
|
|
||||||
GLint getMaxTextureUnits()
|
|
||||||
{
|
|
||||||
// TODO: Remove this lock when it becomes unnecessary in C++11
|
|
||||||
sf::Lock lock(maxTextureUnitsMutex);
|
|
||||||
|
|
||||||
static GLint maxUnits = checkMaxTextureUnits();
|
|
||||||
|
|
||||||
return maxUnits;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the contents of a file into an array of char
|
// Read the contents of a file into an array of char
|
||||||
bool getFileContents(const std::string& filename, std::vector<char>& buffer)
|
bool getFileContents(const std::string& filename, std::vector<char>& buffer)
|
||||||
{
|
{
|
||||||
|
@ -556,7 +534,15 @@ void Shader::setUniform(const std::string& name, const Texture& texture)
|
||||||
if (it == m_textures.end())
|
if (it == m_textures.end())
|
||||||
{
|
{
|
||||||
// New entry, make sure there are enough texture units
|
// New entry, make sure there are enough texture units
|
||||||
GLint maxUnits = getMaxTextureUnits();
|
const static auto maxUnits = []
|
||||||
|
{
|
||||||
|
// Retrieve the maximum number of texture units available
|
||||||
|
GLint maxUnits = 0;
|
||||||
|
glCheck(glGetIntegerv(GLEXT_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxUnits));
|
||||||
|
|
||||||
|
return maxUnits;
|
||||||
|
}();
|
||||||
|
|
||||||
if (m_textures.size() + 1 >= static_cast<std::size_t>(maxUnits))
|
if (m_textures.size() + 1 >= static_cast<std::size_t>(maxUnits))
|
||||||
{
|
{
|
||||||
err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl;
|
err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl;
|
||||||
|
@ -773,26 +759,19 @@ void Shader::bind(const Shader* shader)
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool Shader::isAvailable()
|
bool Shader::isAvailable()
|
||||||
{
|
{
|
||||||
Lock lock(isAvailableMutex);
|
const static auto available = []
|
||||||
|
|
||||||
static bool checked = false;
|
|
||||||
static bool available = false;
|
|
||||||
|
|
||||||
if (!checked)
|
|
||||||
{
|
{
|
||||||
checked = true;
|
|
||||||
|
|
||||||
TransientContextLock contextLock;
|
TransientContextLock contextLock;
|
||||||
|
|
||||||
// Make sure that extensions are initialized
|
// Make sure that extensions are initialized
|
||||||
sf::priv::ensureExtensionsInit();
|
sf::priv::ensureExtensionsInit();
|
||||||
|
|
||||||
available = GLEXT_multitexture &&
|
return GLEXT_multitexture &&
|
||||||
GLEXT_shading_language_100 &&
|
GLEXT_shading_language_100 &&
|
||||||
GLEXT_shader_objects &&
|
GLEXT_shader_objects &&
|
||||||
GLEXT_vertex_shader &&
|
GLEXT_vertex_shader &&
|
||||||
GLEXT_fragment_shader;
|
GLEXT_fragment_shader;
|
||||||
}
|
}();
|
||||||
|
|
||||||
return available;
|
return available;
|
||||||
}
|
}
|
||||||
|
@ -801,22 +780,15 @@ bool Shader::isAvailable()
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool Shader::isGeometryAvailable()
|
bool Shader::isGeometryAvailable()
|
||||||
{
|
{
|
||||||
Lock lock(isAvailableMutex);
|
const static auto available = []
|
||||||
|
|
||||||
static bool checked = false;
|
|
||||||
static bool available = false;
|
|
||||||
|
|
||||||
if (!checked)
|
|
||||||
{
|
{
|
||||||
checked = true;
|
|
||||||
|
|
||||||
TransientContextLock contextLock;
|
TransientContextLock contextLock;
|
||||||
|
|
||||||
// Make sure that extensions are initialized
|
// Make sure that extensions are initialized
|
||||||
sf::priv::ensureExtensionsInit();
|
sf::priv::ensureExtensionsInit();
|
||||||
|
|
||||||
available = isAvailable() && GLEXT_geometry_shader4;
|
return isAvailable() && GLEXT_geometry_shader4;
|
||||||
}
|
}();
|
||||||
|
|
||||||
return available;
|
return available;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
sf::Mutex idMutex;
|
sf::Mutex idMutex;
|
||||||
sf::Mutex maximumSizeMutex;
|
|
||||||
|
|
||||||
// Thread-safe unique identifier generator,
|
// Thread-safe unique identifier generator,
|
||||||
// is used for states cache (see RenderTarget)
|
// is used for states cache (see RenderTarget)
|
||||||
|
@ -776,21 +775,17 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType)
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int Texture::getMaximumSize()
|
unsigned int Texture::getMaximumSize()
|
||||||
{
|
{
|
||||||
Lock lock(maximumSizeMutex);
|
const static auto size = []
|
||||||
|
|
||||||
static bool checked = false;
|
|
||||||
static GLint size = 0;
|
|
||||||
|
|
||||||
if (!checked)
|
|
||||||
{
|
{
|
||||||
checked = true;
|
|
||||||
|
|
||||||
TransientContextLock lock;
|
TransientContextLock lock;
|
||||||
|
|
||||||
|
GLint size;
|
||||||
glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size));
|
glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size));
|
||||||
}
|
|
||||||
|
|
||||||
return static_cast<unsigned int>(size);
|
return static_cast<unsigned int>(size);
|
||||||
|
}();
|
||||||
|
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue