Don't use texture buffer object if not supported, see #2571

Also allow to use setTextureUnits for texture buffer
This commit is contained in:
Benau
2017-02-12 15:42:22 +08:00
parent 4af255431c
commit ca0a605b0e
7 changed files with 54 additions and 35 deletions

View File

@@ -52,6 +52,7 @@ void CentralVideoSettings::init()
hasGS = false;
hasTextureFilterAnisotropic = false;
hasTextureSwizzle = false;
hasTextureBufferObject = false;
#if defined(USE_GLES2)
hasBGRA = false;
@@ -196,6 +197,11 @@ void CentralVideoSettings::init()
hasTextureSwizzle = true;
Log::info("GLDriver", "ARB Texture Swizzle Present");
}
if (hasGLExtension("GL_ARB_texture_buffer_object"))
{
hasTextureBufferObject = true;
Log::info("GLDriver", "ARB Texture Buffer Object Present");
}
// Only unset the high def textures if they are set as default. If the
// user has enabled them (bit 1 set), then leave them enabled.
if (GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_HIGHDEFINITION_TEXTURES) &&
@@ -476,4 +482,9 @@ bool CentralVideoSettings::isARBTextureSwizzleUsable() const
return m_glsl && hasTextureSwizzle;
}
bool CentralVideoSettings::isARBTextureBufferObjectUsable() const
{
return hasTextureBufferObject;
}
#endif // !SERVER_ONLY

View File

@@ -44,6 +44,7 @@ private:
bool hasMultiDrawIndirect;
bool hasTextureFilterAnisotropic;
bool hasTextureSwizzle;
bool hasTextureBufferObject;
#if defined(USE_GLES2)
bool hasBGRA;
@@ -84,6 +85,7 @@ public:
bool isARBExplicitAttribLocationUsable() const;
bool isEXTTextureFilterAnisotropicUsable() const;
bool isARBTextureSwizzleUsable() const;
bool isARBTextureBufferObjectUsable() const;
#if defined(USE_GLES2)
bool isEXTTextureFormatBGRA8888Usable() const;

View File

@@ -91,13 +91,13 @@ public:
// ============================================================================
/** */
class HeightmapSimulationShader : public Shader <HeightmapSimulationShader,
core::matrix4, int, int,
float,float,float,float,float>
class HeightmapSimulationShader :
public TextureShader<HeightmapSimulationShader, 1,
core::matrix4, int, int,
float, float, float, float,
float>
{
public:
GLuint m_TU_heightmap;
HeightmapSimulationShader()
{
const char *varyings[] = {"new_particle_position", "new_lifetime",
@@ -105,8 +105,7 @@ public:
loadTFBProgram("particlesimheightmap.vert", varyings, 4);
assignUniforms("sourcematrix", "dt", "level", "size_increase_factor",
"track_x", "track_x_len", "track_z", "track_z_len");
m_TU_heightmap = 2;
assignTextureUnit(m_TU_heightmap, "heightmap");
assignSamplerNames(0, "heightmap", ST_TEXTURE_BUFFER);
} // HeightmapSimulationShader
@@ -203,6 +202,7 @@ void ParticleSystemProxy::setHeightmap(const std::vector<std::vector<float> > &h
glBindTexture(GL_TEXTURE_BUFFER, heightmaptexture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, heighmapbuffer);
glBindBuffer(GL_TEXTURE_BUFFER, 0);
glBindTexture(GL_TEXTURE_BUFFER, 0);
delete[] hm_array;
#endif
@@ -475,10 +475,9 @@ void ParticleSystemProxy::simulate()
{
#if !defined(USE_GLES2)
HeightmapSimulationShader::getInstance()->use();
glActiveTexture(GL_TEXTURE0 + HeightmapSimulationShader::getInstance()->m_TU_heightmap);
glBindTexture(GL_TEXTURE_BUFFER, heightmaptexture);
HeightmapSimulationShader::getInstance()->setTextureUnits(heightmaptexture);
HeightmapSimulationShader::getInstance()->setUniforms(matrix, timediff, active_count, size_increase_factor, track_x, track_x_len, track_z, track_z_len);
#endif
#endif
}
else
{

View File

@@ -710,7 +710,7 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
void ParticleEmitter::addHeightMapAffector(Track* t)
{
if (m_is_glsl)
if (m_is_glsl && CVS->isARBTextureBufferObjectUsable())
{
const Vec3* aabb_min;
const Vec3* aabb_max;

View File

@@ -57,21 +57,18 @@ public:
}; // SkyboxShader
class SpecularIBLGenerator : public TextureShader<SpecularIBLGenerator, 1,
class SpecularIBLGenerator : public TextureShader<SpecularIBLGenerator, 2,
core::matrix4, float >
{
public:
GLuint m_tu_samples;
SpecularIBLGenerator()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert",
GL_FRAGMENT_SHADER, "importance_sampling_specular.frag");
assignUniforms("PermutationMatrix", "ViewportSize");
m_tu_samples = 1;
assignSamplerNames(0, "tex", ST_TRILINEAR_CUBEMAP);
assignTextureUnit(m_tu_samples, "samples");
assignSamplerNames(0, "tex", ST_TRILINEAR_CUBEMAP,
1, "samples", ST_TEXTURE_BUFFER);
}
}; // SpecularIBLGenerator
@@ -231,7 +228,7 @@ void Skybox::generateSpecularCubemap()
}
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
if (!CVS->isDefferedEnabled())
if (!CVS->isDefferedEnabled() || !CVS->isARBTextureBufferObjectUsable())
return;
#if !defined(USE_GLES2)
@@ -277,16 +274,15 @@ void Skybox::generateSpecularCubemap()
}
glBindVertexArray(0);
glActiveTexture(GL_TEXTURE0 +
SpecularIBLGenerator::getInstance()->m_tu_samples);
GLuint sampleTex, sampleBuffer;
glGenBuffers(1, &sampleBuffer);
glBindBuffer(GL_TEXTURE_BUFFER, sampleBuffer);
GLuint sample_texture, sample_buffer;
glGenBuffers(1, &sample_buffer);
glBindBuffer(GL_TEXTURE_BUFFER, sample_buffer);
glBufferData(GL_TEXTURE_BUFFER, 2048 * sizeof(float), tmp,
GL_STATIC_DRAW);
glGenTextures(1, &sampleTex);
glBindTexture(GL_TEXTURE_BUFFER, sampleTex);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, sampleBuffer);
glGenTextures(1, &sample_texture);
glBindTexture(GL_TEXTURE_BUFFER, sample_texture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, sample_buffer);
glBindTexture(GL_TEXTURE_BUFFER, 0);
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
for (unsigned face = 0; face < 6; face++)
@@ -298,20 +294,19 @@ void Skybox::generateSpecularCubemap()
GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(status == GL_FRAMEBUFFER_COMPLETE);
SpecularIBLGenerator::getInstance()->setTextureUnits(m_cube_map);
SpecularIBLGenerator::getInstance()
->setTextureUnits(m_cube_map, sample_texture);
SpecularIBLGenerator::getInstance()->setUniforms(M[face],
viewportSize);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
glActiveTexture( GL_TEXTURE0
+ SpecularIBLGenerator::getInstance()->m_tu_samples);
glBindBuffer(GL_TEXTURE_BUFFER, 0);
glBindTexture(GL_TEXTURE_BUFFER, 0);
delete[] tmp;
glDeleteTextures(1, &sampleTex);
glDeleteBuffers(1, &sampleBuffer);
glDeleteTextures(1, &sample_texture);
glDeleteBuffers(1, &sample_buffer);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &fbo);

View File

@@ -33,7 +33,8 @@ TextureShaderBase::BindFunction TextureShaderBase::m_all_bind_functions[] =
/* ST_VOLUME_LINEAR_FILTERED */ &TextureShaderBase::bindTextureVolume,
/* ST_NEARED_CLAMPED_FILTERED */ &TextureShaderBase::bindTextureNearestClamped,
/* ST_BILINEAR_CLAMPED_FILTERED */ &TextureShaderBase::bindTextureBilinearClamped,
/* ST_SEMI_TRILINEAR */ &TextureShaderBase::bindTextureSemiTrilinear
/* ST_SEMI_TRILINEAR */ &TextureShaderBase::bindTextureSemiTrilinear,
/* ST_TEXTURE_BUFFER */ &TextureShaderBase::bindTextureBuffer
};
GLuint TextureShaderBase::m_all_texture_types[] =
@@ -46,7 +47,8 @@ GLuint TextureShaderBase::m_all_texture_types[] =
/* ST_VOLUME_LINEAR_FILTERED */ GL_TEXTURE_3D,
/* ST_NEARED_CLAMPED_FILTERED */ GL_TEXTURE_2D,
/* ST_BILINEAR_CLAMPED_FILTERED */ GL_TEXTURE_2D,
/* ST_SEMI_TRILINEAR */ GL_TEXTURE_2D
/* ST_SEMI_TRILINEAR */ GL_TEXTURE_2D,
/* ST_TEXTURE_BUFFER */ GL_TEXTURE_BUFFER
};
// ----------------------------------------------------------------------------
@@ -116,6 +118,11 @@ void TextureShaderBase::bindTextureNearestClamped(GLuint texture_unit,
} // bindTextureNearestClamped
// ----------------------------------------------------------------------------
void TextureShaderBase::bindTextureBuffer(GLuint texture_unit, GLuint tex_id)
{
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindTexture(GL_TEXTURE_BUFFER, tex_id);
} // bindTextureBuffer
// ----------------------------------------------------------------------------
void TextureShaderBase::bindTextureBilinear(GLuint texture_unit, GLuint tex)
@@ -239,6 +246,8 @@ GLuint TextureShaderBase::createSamplers(SamplerTypeNew sampler_type)
return createBilinearClampedSampler();
case ST_SEMI_TRILINEAR:
return createSemiTrilinearSampler();
case ST_TEXTURE_BUFFER:
return 0;
default:
assert(false);
return 0;

View File

@@ -43,7 +43,8 @@ enum SamplerTypeNew
ST_NEARED_CLAMPED_FILTERED,
ST_BILINEAR_CLAMPED_FILTERED,
ST_SEMI_TRILINEAR,
ST_MAX = ST_SEMI_TRILINEAR
ST_TEXTURE_BUFFER,
ST_MAX = ST_TEXTURE_BUFFER
}; // SamplerTypeNew
// ============================================================================
@@ -68,6 +69,7 @@ protected:
static void bindTextureShadow(GLuint tex_unit, GLuint tex_id);
static void bindTrilinearClampedArrayTexture(GLuint tex_unit, GLuint tex_id);
static void bindTextureVolume(GLuint tex_unit, GLuint tex_id);
static void bindTextureBuffer(GLuint tex_unit, GLuint tex_id);
GLuint createSamplers(SamplerTypeNew sampler_type);
private:
@@ -179,7 +181,8 @@ public:
{
glActiveTexture(GL_TEXTURE0 + m_texture_units[N]);
glBindTexture(m_texture_type[N], tex_id);
glBindSampler(m_texture_units[N], m_sampler_ids[N]);
if (m_sampler_ids[N] != 0)
glBindSampler(m_texture_units[N], m_sampler_ids[N]);
}
else
{