Migrated more TextureReads to the new shader infrastructure.
This commit is contained in:
@@ -662,19 +662,6 @@ void BindTextureTrilinearAnisotropic(GLuint TU, GLuint tex)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso);
|
||||
}
|
||||
|
||||
void BindCubemapTrilinear(unsigned TU, unsigned tex)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + TU);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
int aniso = UserConfigParams::m_anisotropic;
|
||||
if (aniso == 0) aniso = 1;
|
||||
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso);
|
||||
}
|
||||
|
||||
GLuint createShadowSampler()
|
||||
{
|
||||
@@ -760,7 +747,7 @@ namespace UtilShader
|
||||
GL_FRAGMENT_SHADER, "importance_sampling_specular.frag");
|
||||
assignUniforms("PermutationMatrix", "ViewportSize");
|
||||
TU_Samples = 1;
|
||||
assignSamplerNames(m_program, 0, "tex");
|
||||
assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_CUBEMAP);
|
||||
assignTextureUnit(TU_Samples, "samples");
|
||||
}
|
||||
}
|
||||
@@ -1242,7 +1229,7 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, "sky.vert",
|
||||
GL_FRAGMENT_SHADER, "sky.frag");
|
||||
assignUniforms();
|
||||
assignSamplerNames(m_program, 0, "tex");
|
||||
assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_CUBEMAP);
|
||||
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
@@ -1457,7 +1444,9 @@ namespace FullScreenShader
|
||||
GL_FRAGMENT_SHADER, "utils/SpecularIBL.frag",
|
||||
GL_FRAGMENT_SHADER, "IBL.frag");
|
||||
assignUniforms();
|
||||
assignSamplerNames(m_program, 0, "ntex", 1, "dtex", 2, "probe");
|
||||
assignSamplerNames(m_program, 0, "ntex", ST_NEAREST_FILTERED,
|
||||
1, "dtex", ST_NEAREST_FILTERED,
|
||||
2, "probe", ST_TRILINEAR_CUBEMAP);
|
||||
}
|
||||
|
||||
DegradedIBLShader::DegradedIBLShader()
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
};
|
||||
|
||||
class SpecularIBLGenerator : public Shader<SpecularIBLGenerator, core::matrix4, float >,
|
||||
public TextureRead<Trilinear_cubemap>
|
||||
public TextureReadNew<ST_TRILINEAR_CUBEMAP>
|
||||
{
|
||||
public:
|
||||
GLuint TU_Samples;
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
DisplaceShader();
|
||||
};
|
||||
|
||||
class SkyboxShader : public Shader<SkyboxShader>, public TextureRead<Trilinear_cubemap>
|
||||
class SkyboxShader : public Shader<SkyboxShader>, public TextureReadNew<ST_TRILINEAR_CUBEMAP>
|
||||
{
|
||||
public:
|
||||
SkyboxShader();
|
||||
@@ -395,7 +395,8 @@ public:
|
||||
SunLightShader();
|
||||
};
|
||||
|
||||
class IBLShader : public Shader<IBLShader>, public TextureRead<Nearest_Filtered, Nearest_Filtered, Trilinear_cubemap>
|
||||
class IBLShader : public Shader<IBLShader>,
|
||||
public TextureReadNew<ST_NEAREST_FILTERED, ST_NEAREST_FILTERED, ST_TRILINEAR_CUBEMAP>
|
||||
{
|
||||
public:
|
||||
IBLShader();
|
||||
|
||||
@@ -51,7 +51,6 @@ enum SamplerType {
|
||||
Nearest_Filtered,
|
||||
Shadow_Sampler,
|
||||
Volume_Linear_Filtered,
|
||||
Trilinear_cubemap,
|
||||
Trilinear_Clamped_Array2D,
|
||||
};
|
||||
|
||||
@@ -233,30 +232,6 @@ struct CreateSamplers<Trilinear_Anisotropic_Filtered, tp...>
|
||||
|
||||
void BindTextureTrilinearAnisotropic(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Trilinear_cubemap, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createTrilinearSampler());
|
||||
e.push_back(GL_TEXTURE_CUBE_MAP);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindCubemapTrilinear(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Trilinear_cubemap, tp...>
|
||||
{
|
||||
template<int N, typename...Args>
|
||||
static void exec(const std::vector<unsigned> &TU, GLuint TexId, Args... args)
|
||||
{
|
||||
BindCubemapTrilinear(TU[N], TexId);
|
||||
BindTexture<tp...>::template exec<N + 1>(TU, args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Trilinear_Anisotropic_Filtered, tp...>
|
||||
{
|
||||
|
||||
@@ -21,26 +21,15 @@
|
||||
#include "config/user_config.hpp"
|
||||
|
||||
TextureReadBaseNew::BindFunction TextureReadBaseNew::m_all_bind_functions[] =
|
||||
{ &TextureReadBaseNew::bindTextureNearest,
|
||||
&TextureReadBaseNew::bindTextureTrilinearAnisotropic };
|
||||
{ /* ST_NEAREST_FILTERED */ &TextureReadBaseNew::bindTextureNearest,
|
||||
/* ST_TRILINEAR_ANISOTROPIC_FILTERED */ &TextureReadBaseNew::bindTextureTrilinearAnisotropic,
|
||||
/* ST_TRILINEAR_CUBEMAP */ &TextureReadBaseNew::bindCubemapTrilinear
|
||||
};
|
||||
|
||||
GLuint TextureReadBaseNew::m_all_texture_types[] = { GL_TEXTURE_2D, GL_TEXTURE_2D };
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GLuint TextureReadBaseNew::createSamplers(SamplerTypeNew sampler_type)
|
||||
{
|
||||
switch (sampler_type)
|
||||
{
|
||||
case ST_NEAREST_FILTERED:
|
||||
return createNearestSampler();
|
||||
case ST_TRILINEAR_ANISOTROPIC_FILTERED:
|
||||
return createTrilinearSampler();
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
} // switch
|
||||
} // createSamplers
|
||||
GLuint TextureReadBaseNew::m_all_texture_types[] =
|
||||
{ /* ST_NEAREST_FILTERED */ GL_TEXTURE_2D,
|
||||
/* ST_TRILINEAR_ANISOTROPIC_FILTERED */ GL_TEXTURE_2D,
|
||||
/* ST_TRILINEAR_CUBEMAP */ GL_TEXTURE_CUBE_MAP };
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void TextureReadBaseNew::bindTextureNearest(GLuint texture_unit, GLuint tex)
|
||||
@@ -70,23 +59,24 @@ void TextureReadBaseNew::bindTextureTrilinearAnisotropic(GLuint tex_unit, GLuint
|
||||
} // bindTextureTrilinearAnisotropic
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GLuint TextureReadBaseNew::createNearestSampler()
|
||||
void TextureReadBaseNew::bindCubemapTrilinear(unsigned tex_unit, unsigned tex)
|
||||
{
|
||||
#ifdef GL_VERSION_3_3
|
||||
unsigned id;
|
||||
glGenSamplers(1, &id);
|
||||
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.);
|
||||
return id;
|
||||
#endif
|
||||
} // createNearestSampler
|
||||
glActiveTexture(GL_TEXTURE0 + tex_unit);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
int aniso = UserConfigParams::m_anisotropic;
|
||||
if (aniso == 0) aniso = 1;
|
||||
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
(float)aniso);
|
||||
} // bindCubemapTrilinear
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void TextureReadBaseNew::bindTextureNearestClamped(GLuint texture_unit,
|
||||
GLuint tex_id)
|
||||
GLuint tex_id)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + texture_unit);
|
||||
glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||
@@ -133,6 +123,38 @@ void TextureReadBaseNew::bindTextureSemiTrilinear(GLuint tex_unit, GLuint tex)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.);
|
||||
} // bindTextureSemiTrilinear
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GLuint TextureReadBaseNew::createSamplers(SamplerTypeNew sampler_type)
|
||||
{
|
||||
switch (sampler_type)
|
||||
{
|
||||
case ST_NEAREST_FILTERED:
|
||||
return createNearestSampler();
|
||||
case ST_TRILINEAR_ANISOTROPIC_FILTERED:
|
||||
return createTrilinearSampler();
|
||||
case ST_TRILINEAR_CUBEMAP:
|
||||
return createTrilinearSampler();
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
} // switch
|
||||
} // createSamplers
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GLuint TextureReadBaseNew::createNearestSampler()
|
||||
{
|
||||
#ifdef GL_VERSION_3_3
|
||||
unsigned id;
|
||||
glGenSamplers(1, &id);
|
||||
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.);
|
||||
return id;
|
||||
#endif
|
||||
} // createNearestSampler
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GLuint TextureReadBaseNew::createTrilinearSampler()
|
||||
{
|
||||
|
||||
@@ -24,16 +24,19 @@
|
||||
|
||||
|
||||
enum SamplerTypeNew {
|
||||
ST_NEAREST_FILTERED,
|
||||
ST_MIN,
|
||||
ST_NEAREST_FILTERED = ST_MIN,
|
||||
ST_TRILINEAR_ANISOTROPIC_FILTERED,
|
||||
ST_TRILINEAR_CUBEMAP,
|
||||
ST_MAX = ST_TRILINEAR_CUBEMAP,
|
||||
|
||||
ST_SEMI_TRILINEAR,
|
||||
ST_BILINEAR_FILTERED,
|
||||
ST_BILINEAR_CLAMPED_FILTERED,
|
||||
ST_NEARED_CLAMPED_FILTERED,
|
||||
ST_SHADOW_SAMPLER,
|
||||
ST_VOLUME_LINEAR_FILTERED,
|
||||
ST_TRILINEAR_CUBEMAP,
|
||||
ST_TRILINEAR_CLAMPED_ARRAY2D,
|
||||
ST_TRILINEAR_CLAMPED_ARRAY2D
|
||||
};
|
||||
|
||||
|
||||
@@ -49,6 +52,7 @@ protected:
|
||||
static void bindTextureNearestClamped(GLuint tex_unit, GLuint tex_id);
|
||||
static void bindTextureTrilinearAnisotropic(GLuint tex_unit, GLuint tex_id);
|
||||
static void bindTextureSemiTrilinear(GLuint tex_unit, GLuint tex_id);
|
||||
static void bindCubemapTrilinear(unsigned tex_unit, unsigned tex);
|
||||
|
||||
GLuint createSamplers(SamplerTypeNew sampler_type);
|
||||
private:
|
||||
@@ -57,7 +61,7 @@ private:
|
||||
static GLuint createTrilinearSampler();
|
||||
|
||||
protected:
|
||||
static BindFunction m_all_bind_functions[2];
|
||||
static BindFunction m_all_bind_functions[];
|
||||
std::vector<BindFunction> m_bind_functions;
|
||||
static GLuint m_all_texture_types[];
|
||||
|
||||
@@ -100,12 +104,19 @@ private:
|
||||
{
|
||||
|
||||
m_sampler_ids.push_back(createSamplers(sampler_type));
|
||||
|
||||
assert(sampler_type >= ST_MIN && sampler_type <= ST_MAX);
|
||||
m_texture_type.push_back(m_all_texture_types[sampler_type]);
|
||||
|
||||
GLuint location = glGetUniformLocation(program, name);
|
||||
m_texture_location.push_back(location);
|
||||
glUniform1i(location, tex_unit);
|
||||
m_texture_units.push_back(tex_unit);
|
||||
|
||||
// Duplicated assert
|
||||
assert(sampler_type >= ST_MIN && sampler_type <= ST_MAX);
|
||||
m_bind_functions.push_back( m_all_bind_functions[sampler_type]);
|
||||
|
||||
assignTextureNamesImpl<N + 1>(program, args...);
|
||||
} // assignTextureNamesImpl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user