Target available mip

This commit is contained in:
Brad Davis 2018-03-06 11:20:54 -08:00
parent b7d0260a17
commit f9605cffb1
4 changed files with 30 additions and 16 deletions

View file

@ -253,6 +253,9 @@ void GL45Texture::releaseBindless() const {
void GL45Texture::recreateBindless() const { void GL45Texture::recreateBindless() const {
if (isBindless()) { if (isBindless()) {
releaseBindless(); releaseBindless();
} else {
// Once a texture is about to become bindless, it's base mip level MUST be set to 0
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, 0);
} }
_bindless.sampler = SAMPLER_CACHE.getGLSampler(_cachedSampler); _bindless.sampler = SAMPLER_CACHE.getGLSampler(_cachedSampler);
@ -270,16 +273,15 @@ const GL45Texture::Bindless& GL45Texture::getBindless() const {
void GL45Texture::syncSampler() const { void GL45Texture::syncSampler() const {
const Sampler& sampler = _gpuObject.getSampler(); const Sampler& sampler = _gpuObject.getSampler();
bool samplerChanged = _cachedSampler != sampler; if (_cachedSampler == sampler) {
if (samplerChanged) { return;
_cachedSampler = sampler;
} }
_cachedSampler = sampler;
if (isBindless()) { if (isBindless()) {
if (samplerChanged) {
recreateBindless(); recreateBindless();
} } else {
} else if (samplerChanged) {
const auto& fm = FILTER_MODES[sampler.getFilter()]; const auto& fm = FILTER_MODES[sampler.getFilter()];
glTextureParameteri(_id, GL_TEXTURE_MIN_FILTER, fm.minFilter); glTextureParameteri(_id, GL_TEXTURE_MIN_FILTER, fm.minFilter);
glTextureParameteri(_id, GL_TEXTURE_MAG_FILTER, fm.magFilter); glTextureParameteri(_id, GL_TEXTURE_MAG_FILTER, fm.magFilter);

View file

@ -20,6 +20,16 @@ struct GPUTextureTable {
#define TextureTable(index, name) layout (std140) uniform gpu_resourceTextureTable##index { GPUTextureTable name; } #define TextureTable(index, name) layout (std140) uniform gpu_resourceTextureTable##index { GPUTextureTable name; }
#define tableTex(name, slot) sampler2D(name._textures[slot].xy) #define tableTex(name, slot) sampler2D(name._textures[slot].xy)
#define tableTexMinLod(name, slot) float(name._textures[slot].z)
#define tableTexValue(name, slot, uv) \
tableTexValueLod(tableTex(matTex, albedoMap), tableTexMinLod(matTex, albedoMap), uv)
vec4 tableTexValueLod(sampler2D sampler, float minLod, vec2 uv) {
float queryLod = textureQueryLod(sampler, uv).x;
queryLod = max(minLod, queryLod);
return textureLod(sampler, uv, queryLod);
}
#else #else

View file

@ -504,6 +504,8 @@ TexturePointer Texture::build(const ktx::KTXDescriptor& descriptor) {
gpuktxKeyValue._usage = Texture::Usage::Builder().withColor().withAlpha().build(); gpuktxKeyValue._usage = Texture::Usage::Builder().withColor().withAlpha().build();
} }
auto samplerDesc = gpuktxKeyValue._samplerDesc;
samplerDesc._maxMip = gpu::Sampler::MAX_MIP_LEVEL;
auto texture = create(gpuktxKeyValue._usageType, auto texture = create(gpuktxKeyValue._usageType,
type, type,
texelFormat, texelFormat,
@ -513,7 +515,7 @@ TexturePointer Texture::build(const ktx::KTXDescriptor& descriptor) {
1, // num Samples 1, // num Samples
header.getNumberOfSlices(), header.getNumberOfSlices(),
header.getNumberOfLevels(), header.getNumberOfLevels(),
gpuktxKeyValue._samplerDesc); samplerDesc);
texture->setUsage(gpuktxKeyValue._usage); texture->setUsage(gpuktxKeyValue._usage);
// Assing the mips availables // Assing the mips availables

View file

@ -67,42 +67,42 @@ SCATTERING_MAP,
<@if withAlbedo@> <@if withAlbedo@>
#define albedoMap 1 #define albedoMap 1
vec4 fetchAlbedoMap(vec2 uv) { vec4 fetchAlbedoMap(vec2 uv) {
return texture(tableTex(matTex, albedoMap), uv); return tableTexValue(matTex, albedoMap, uv);
} }
<@endif@> <@endif@>
<@if withRoughness@> <@if withRoughness@>
#define roughnessMap 3 #define roughnessMap 3
float fetchRoughnessMap(vec2 uv) { float fetchRoughnessMap(vec2 uv) {
return (texture(tableTex(matTex, roughnessMap), uv).r); return tableTexValue(matTex, roughnessMap, uv).r;
} }
<@endif@> <@endif@>
<@if withNormal@> <@if withNormal@>
#define normalMap 4 #define normalMap 4
vec3 fetchNormalMap(vec2 uv) { vec3 fetchNormalMap(vec2 uv) {
return texture(tableTex(matTex, normalMap), uv).xyz; return tableTexValue(matTex, normalMap, uv).xyz;
} }
<@endif@> <@endif@>
<@if withMetallic@> <@if withMetallic@>
#define metallicMap 2 #define metallicMap 2
float fetchMetallicMap(vec2 uv) { float fetchMetallicMap(vec2 uv) {
return (texture(tableTex(matTex, metallicMap), uv).r); return tableTexValue(matTex, metallicMap, uv).r;
} }
<@endif@> <@endif@>
<@if withEmissive@> <@if withEmissive@>
#define emissiveMap 0 #define emissiveMap 0
vec3 fetchEmissiveMap(vec2 uv) { vec3 fetchEmissiveMap(vec2 uv) {
return texture(tableTex(matTex, emissiveMap), uv).rgb; return tableTexValue(matTex, emissiveMap, uv).rgb;
} }
<@endif@> <@endif@>
<@if withOcclusion@> <@if withOcclusion@>
#define occlusionMap 5 #define occlusionMap 5
float fetchOcclusionMap(vec2 uv) { float fetchOcclusionMap(vec2 uv) {
return texture(tableTex(matTex, occlusionMap), uv).r; return tableTexValue(matTex, occlusionMap, uv).r;
} }
<@endif@> <@endif@>
@ -111,7 +111,7 @@ float fetchOcclusionMap(vec2 uv) {
float fetchScatteringMap(vec2 uv) { float fetchScatteringMap(vec2 uv) {
float scattering = texture(tableTex(matTex, scatteringMap), uv).r; // boolean scattering for now float scattering = texture(tableTex(matTex, scatteringMap), uv).r; // boolean scattering for now
return max(((scattering - 0.1) / 0.9), 0.0); return max(((scattering - 0.1) / 0.9), 0.0);
return texture(tableTex(matTex, scatteringMap), uv).r; // boolean scattering for now return tableTexValue(matTex, scatteringMap, uv).r; // boolean scattering for now
} }
<@endif@> <@endif@>