[drape] compilation on android and review fixes

This commit is contained in:
ExMix 2015-07-05 16:13:55 +03:00 committed by r.kuznetsov
parent fba6407706
commit bf45912588
2 changed files with 60 additions and 77 deletions

View file

@ -13,68 +13,50 @@ GLFunctionsCache & GLFunctionsCache::Instance()
void GLFunctionsCache::glBindTexture(uint32_t textureID)
{
if (INST.CheckAndSetValue(textureID, INST.m_glBindTextureCache))
if (INST.m_glBindTextureCache.Assign(textureID))
GLFunctions::glBindTextureImpl(textureID);
}
void GLFunctionsCache::glActiveTexture(glConst texBlock)
{
if (INST.CheckAndSetValue(texBlock, INST.m_glActiveTextureCache))
if (INST.m_glActiveTextureCache.Assign(texBlock))
GLFunctions::glActiveTextureImpl(texBlock);
}
void GLFunctionsCache::glUseProgram(uint32_t programID)
{
if (INST.CheckAndSetValue(programID, INST.m_glUseProgramCache))
if (INST.m_glUseProgramCache.Assign(programID))
GLFunctions::glUseProgramImpl(programID);
}
void GLFunctionsCache::glEnable(glConst mode)
{
EnablableParam & param = INST.m_glEnableCache[mode];
bool const initialized = param.m_initialized;
if (!initialized || (initialized && !param.m_isEnabled))
{
param = true;
if (INST.m_glStateCache[mode].Assign(true))
GLFunctions::glEnableImpl(mode);
}
}
void GLFunctionsCache::glDisable(glConst mode)
{
EnablableParam & param = INST.m_glEnableCache[mode];
bool const initialized = param.m_initialized;
if (!initialized || (initialized && param.m_isEnabled))
{
param = false;
if (INST.m_glStateCache[mode].Assign(false))
GLFunctions::glDisableImpl(mode);
}
}
GLFunctionsCache::UniformsCache & GLFunctionsCache::GetCacheForCurrentProgram()
{
GLFunctionsCache & cache = INST;
ASSERT(cache.m_glUseProgramCache.m_inited, ());
return cache.m_uniformsCache[cache.m_glUseProgramCache.m_value];
}
void GLFunctionsCache::glUniformValuei(int8_t location, int32_t v)
{
ASSERT(INST.m_glUseProgramCache.m_initialized, ());
UniformsCache & cache = INST.m_uniformsCache[INST.m_glUseProgramCache.m_param];
CachedParam<int32_t> & param = cache.m_glUniform1iCache[location];
bool const initialized = param.m_initialized;
if (!initialized || (initialized && param != v))
{
param = v;
if (GetCacheForCurrentProgram().Assign(location, v))
GLFunctions::glUniformValueiImpl(location, v);
}
}
void GLFunctionsCache::glUniformValuef(int8_t location, float v)
{
ASSERT(INST.m_glUseProgramCache.m_initialized, ());
UniformsCache & cache = INST.m_uniformsCache[INST.m_glUseProgramCache.m_param];
CachedParam<float> & param = cache.m_glUniform1fCache[location];
bool const initialized = param.m_initialized;
if (!initialized || (initialized && param != v))
{
param = v;
if (GetCacheForCurrentProgram().Assign(location, v))
GLFunctions::glUniformValuefImpl(location, v);
}
}

View file

@ -21,72 +21,73 @@ public:
private:
static GLFunctionsCache & Instance();
template<typename TParam>
GLFunctionsCache() = default;
template<typename TValue>
struct CachedParam
{
TParam m_param;
bool m_initialized = false;
TValue m_value;
bool m_inited;
CachedParam() : m_param(TParam()) {}
explicit CachedParam(TParam const & param) : m_param(param) {}
bool operator!=(TParam const & param)
CachedParam()
: m_value(TValue())
, m_inited(false)
{
return m_param != param;
}
CachedParam & operator=(TParam const & param)
explicit CachedParam(TValue const & value)
: m_value(value)
, m_inited(true)
{
m_param = param;
m_initialized = true;
}
bool Assign(TValue const & newValue)
{
if (m_inited && newValue == m_value)
return false;
m_value = newValue;
m_inited = true;
return true;
}
bool operator!=(TValue const & value) const
{
return m_value != value;
}
CachedParam & operator=(TValue const & param)
{
m_value = param;
m_inited = true;
return *this;
}
};
struct EnablableParam
{
bool m_isEnabled = false;
bool m_initialized = false;
EnablableParam(){}
explicit EnablableParam(bool enabled) : m_isEnabled(enabled) {}
bool operator!=(bool enabled)
{
return m_isEnabled != enabled;
}
EnablableParam & operator=(bool enabled)
{
m_isEnabled = enabled;
m_initialized = true;
return *this;
}
};
template<typename TParam> using UniformCache = map<int8_t, CachedParam<TParam>>;
template<typename TValue> using UniformCache = map<int8_t, CachedParam<TValue>>;
using StateParams = map<glConst, CachedParam<bool>>;
struct UniformsCache
{
UniformCache<int32_t> m_glUniform1iCache;
UniformCache<float> m_glUniform1fCache;
bool Assign(int8_t location, int32_t value) { return Assign(location, value, m_glUniform1iCache); }
bool Assign(int8_t location, float value) { return Assign(location, value, m_glUniform1fCache); }
template<typename TValue>
bool Assign(int8_t location, TValue const & value, UniformCache<TValue> & cache)
{
return cache[location].Assign(value);
}
};
template<typename TParamInternal, typename TParam>
bool CheckAndSetValue(TParamInternal const & newValue, TParam & cachedValue)
{
if (!cachedValue.m_initialized || cachedValue != newValue)
{
cachedValue = newValue;
return true;
}
return false;
}
static UniformsCache & GetCacheForCurrentProgram();
CachedParam<uint32_t> m_glBindTextureCache;
CachedParam<glConst> m_glActiveTextureCache;
CachedParam<uint32_t> m_glUseProgramCache;
map<glConst, EnablableParam> m_glEnableCache;
StateParams m_glStateCache;
map<uint32_t, UniformsCache> m_uniformsCache;
};