Remove KRMIN, KRMAX, and KRCLAMP helpers
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
This commit is contained in:
@@ -627,8 +627,8 @@ void KRContext::doStreaming()
|
||||
const long KRENGINE_RESERVE_MEMORY = 0x4000000; // 64MB
|
||||
|
||||
getMemoryStats(free_memory);
|
||||
free_memory = KRCLAMP(free_memory - KRENGINE_RESERVE_MEMORY, 0, KRENGINE_GPU_MEM_TARGET);
|
||||
total_memory = KRMIN(KRENGINE_GPU_MEM_MAX, free_memory * 3 / 4 + m_pTextureManager->getMemUsed() + m_pMeshManager->getMemUsed());
|
||||
free_memory = std::clamp(free_memory - KRENGINE_RESERVE_MEMORY, 0, KRENGINE_GPU_MEM_TARGET);
|
||||
total_memory = std::min(KRENGINE_GPU_MEM_MAX, free_memory * 3 / 4 + m_pTextureManager->getMemUsed() + m_pMeshManager->getMemUsed());
|
||||
|
||||
#endif
|
||||
*/
|
||||
|
||||
@@ -38,9 +38,6 @@
|
||||
|
||||
#include "simdjson.h"
|
||||
|
||||
#define KRMIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
#define KRMAX(x,y) ((x) > (y) ? (x) : (y))
|
||||
#define KRCLAMP(x, min, max) (KRMAX(KRMIN(x, max), min))
|
||||
#define KRALIGN(x) ((x + 3) & ~0x03)
|
||||
|
||||
float const PI = 3.141592653589793f;
|
||||
|
||||
@@ -254,7 +254,7 @@ bool KROctreeNode::sphereCast(const Vector3& v0, const Vector3& v1, float radius
|
||||
} else {
|
||||
*/
|
||||
|
||||
AABB swept_bounds = AABB::Create(Vector3::Create(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), Vector3::Create(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius));
|
||||
AABB swept_bounds = AABB::Create(Vector3::Create(std::min(v0.x, v1.x) - radius, std::min(v0.y, v1.y) - radius, std::min(v0.z, v1.z) - radius), Vector3::Create(std::max(v0.x, v1.x) + radius, std::max(v0.y, v1.y) + radius, std::max(v0.z, v1.z) + radius));
|
||||
// FINDME, TODO - Investigate AABB - swept sphere intersections or OBB - AABB intersections: "if(getBounds().intersectsSweptSphere(v0, v1, radius)) {"
|
||||
if (getBounds().intersects(swept_bounds)) {
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ float KRViewport::coverage(const AABB& b) const
|
||||
|
||||
float screen_depth = distance / 1000.0f;
|
||||
|
||||
return KRCLAMP(1.0f - screen_depth, 0.01f, 1.0f);
|
||||
return std::clamp(1.0f - screen_depth, 0.01f, 1.0f);
|
||||
|
||||
/*
|
||||
|
||||
@@ -253,13 +253,13 @@ float KRViewport::coverage(const AABB& b) const
|
||||
}
|
||||
}
|
||||
|
||||
screen_min.x = KRCLAMP(screen_min.x, 0.0f, 1.0f);
|
||||
screen_min.y = KRCLAMP(screen_min.y, 0.0f, 1.0f);
|
||||
screen_max.x = KRCLAMP(screen_max.x, 0.0f, 1.0f);
|
||||
screen_max.y = KRCLAMP(screen_max.y, 0.0f, 1.0f);
|
||||
screen_min.x = std::clamp(screen_min.x, 0.0f, 1.0f);
|
||||
screen_min.y = std::clamp(screen_min.y, 0.0f, 1.0f);
|
||||
screen_max.x = std::clamp(screen_max.x, 0.0f, 1.0f);
|
||||
screen_max.y = std::clamp(screen_max.y, 0.0f, 1.0f);
|
||||
|
||||
float c = (screen_max.x - screen_min.x) * (screen_max.y - screen_min.y);
|
||||
return KRCLAMP(c, 0.01f, 1.0f);
|
||||
return std::clamp(c, 0.01f, 1.0f);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ float KRAmbientZone::getContainment(const Vector3& pos)
|
||||
d = d > 1.0f ? 0.0f : 1.0f;
|
||||
} else {
|
||||
d = (1.0f - d) / m_gradient_distance;
|
||||
d = KRCLAMP(d, 0.0f, 1.0f);
|
||||
d = std::clamp(d, 0.0f, 1.0f);
|
||||
}
|
||||
return d;
|
||||
|
||||
|
||||
@@ -162,8 +162,8 @@ bool KRCollider::sphereCast(const Vector3& v0, const Vector3& v1, float radius,
|
||||
loadModel();
|
||||
if (m_model.val.isBound()) {
|
||||
AABB sphereCastBounds = AABB::Create( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions
|
||||
Vector3::Create(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius),
|
||||
Vector3::Create(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius)
|
||||
Vector3::Create(std::min(v0.x, v1.x) - radius, std::min(v0.y, v1.y) - radius, std::min(v0.z, v1.z) - radius),
|
||||
Vector3::Create(std::max(v0.x, v1.x) + radius, std::max(v0.y, v1.y) + radius, std::max(v0.z, v1.z) + radius)
|
||||
);
|
||||
|
||||
if (getBounds().intersects(sphereCastBounds)) {
|
||||
|
||||
@@ -79,7 +79,7 @@ void KRLODSet::updateLODVisibility(const KRViewport& viewport)
|
||||
for (KRNode* childNode = m_firstChildNode; childNode != nullptr; childNode = childNode->m_nextNode) {
|
||||
KRLODGroup* lod_group = dynamic_cast<KRLODGroup*>(childNode);
|
||||
assert(lod_group != NULL);
|
||||
LodVisibility group_lod_visibility = KRMIN(lod_group->calcLODVisibility(viewport), m_lod_visible);
|
||||
LodVisibility group_lod_visibility = std::min(lod_group->calcLODVisibility(viewport), m_lod_visible);
|
||||
/*
|
||||
// FINDME, TODO, HACK - Disabled streamer delayed LOD load due to performance issues:
|
||||
if(group_lod_visibility == LOD_VISIBILITY_VISIBLE) {
|
||||
@@ -105,7 +105,7 @@ void KRLODSet::updateLODVisibility(const KRViewport& viewport)
|
||||
for (KRNode* childNode = m_firstChildNode; childNode != nullptr; childNode = childNode->m_nextNode) {
|
||||
KRLODGroup* lod_group = dynamic_cast<KRLODGroup*>(childNode);
|
||||
assert(lod_group != NULL);
|
||||
LodVisibility group_lod_visibility = KRMIN(lod_group->calcLODVisibility(viewport), m_lod_visible);
|
||||
LodVisibility group_lod_visibility = std::min(lod_group->calcLODVisibility(viewport), m_lod_visible);
|
||||
lod_group->setLODVisibility(group_lod_visibility);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ kraken_stream_level KRModel::getStreamLevel(const KRViewport& viewport)
|
||||
|
||||
for (int lod = 0; lod < kMeshLODCount; lod++) {
|
||||
if (m_meshes[lod].val.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_meshes[lod].val.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_meshes[lod].val.get()->getStreamLevel());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1167,7 +1167,7 @@ kraken_stream_level KRNode::getStreamLevel(const KRViewport& viewport)
|
||||
kraken_stream_level stream_level = kraken_stream_level::STREAM_LEVEL_IN_HQ;
|
||||
|
||||
for (KRNode* child = m_firstChildNode; child != nullptr; child = child->m_nextNode) {
|
||||
stream_level = KRMIN(stream_level, child->getStreamLevel(viewport));
|
||||
stream_level = std::min(stream_level, child->getStreamLevel(viewport));
|
||||
}
|
||||
|
||||
return stream_level;
|
||||
|
||||
@@ -171,7 +171,7 @@ float KRReverbZone::getContainment(const Vector3& pos)
|
||||
d = d > 1.0f ? 0.0f : 1.0f;
|
||||
} else {
|
||||
d = (1.0f - d) / m_gradient_distance;
|
||||
d = KRCLAMP(d, 0.0f, 1.0f);
|
||||
d = std::clamp(d, 0.0f, 1.0f);
|
||||
}
|
||||
return d;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
KRResourceRequest(KRResource* resource, uint64_t usage, float lodCoverage = 0.0f)
|
||||
: resource(resource)
|
||||
, usage(usage)
|
||||
, coverage(static_cast<uint8_t>(KRCLAMP(lodCoverage / 1.0f * 255.f, 0, 255.f)))
|
||||
, coverage(static_cast<uint8_t>(std::clamp(lodCoverage / 1.0f * 255.f, 0.f, 255.f)))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ void KRAudioManager::renderReverbImpulseResponse(int impulse_response_offset, in
|
||||
for (unordered_map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr = m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) {
|
||||
siren_reverb_zone_weight_info zi = (*zone_itr).second;
|
||||
if (zi.reverb_sample) {
|
||||
if (impulse_response_offset < KRMIN(zi.reverb_sample->getFrameCount(), m_reverb_max_length * 44100)) { // Optimization - when mixing multiple impulse responses (i.e. fading between reverb zones), do not process blocks past the end of a shorter impulse response sample when they differ in length
|
||||
if (impulse_response_offset < std::min((int)zi.reverb_sample->getFrameCount(), (int)m_reverb_max_length * 44100)) { // Optimization - when mixing multiple impulse responses (i.e. fading between reverb zones), do not process blocks past the end of a shorter impulse response sample when they differ in length
|
||||
if (first_sample) {
|
||||
// If this is the first or only sample, write directly to the first half of the FFT input buffer
|
||||
first_sample = false;
|
||||
@@ -313,8 +313,8 @@ void KRAudioManager::renderReverb()
|
||||
for (unordered_map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr = m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) {
|
||||
siren_reverb_zone_weight_info zi = (*zone_itr).second;
|
||||
if (zi.reverb_sample) {
|
||||
int zone_sample_blocks = KRMIN((int)zi.reverb_sample->getFrameCount(), (int)(m_reverb_max_length * 44100.0f)) / KRENGINE_AUDIO_BLOCK_LENGTH + 1;
|
||||
impulse_response_blocks = KRMAX(impulse_response_blocks, zone_sample_blocks);
|
||||
int zone_sample_blocks = std::min((int)zi.reverb_sample->getFrameCount(), (int)(m_reverb_max_length * 44100.0f)) / KRENGINE_AUDIO_BLOCK_LENGTH + 1;
|
||||
impulse_response_blocks = std::max(impulse_response_blocks, zone_sample_blocks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1483,10 +1483,10 @@ void KRAudioManager::startFrame(float deltaTime)
|
||||
Vector3 source_world_position = source->getWorldTranslation();
|
||||
Vector3 diff = source_world_position - m_listener_position;
|
||||
float distance = diff.magnitude();
|
||||
float gain = source->getGain() * m_global_gain / pow(KRMAX(distance / source->getReferenceDistance(), 1.0f), source->getRolloffFactor());
|
||||
float gain = source->getGain() * m_global_gain / pow(std::max(distance / source->getReferenceDistance(), 1.0f), source->getRolloffFactor());
|
||||
|
||||
// apply minimum-cutoff so that we don't waste cycles processing very quiet / distant sound sources
|
||||
gain = KRMAX(gain - KRENGINE_AUDIO_CUTOFF, 0.0f) / (1.0f - KRENGINE_AUDIO_CUTOFF);
|
||||
gain = std::max(gain - KRENGINE_AUDIO_CUTOFF, 0.0f) / (1.0f - KRENGINE_AUDIO_CUTOFF);
|
||||
|
||||
if (gain > 0.0f) {
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ float KRAudioSample::sample(int frame_offset, int frame_rate, int channel)
|
||||
{
|
||||
loadInfo();
|
||||
|
||||
int c = KRMIN(channel, m_channelsPerFrame - 1);
|
||||
int c = std::min(channel, m_channelsPerFrame - 1);
|
||||
|
||||
if (frame_offset < 0) {
|
||||
return 0.0f; // Past the beginning of the recording
|
||||
@@ -154,7 +154,7 @@ void KRAudioSample::sample(__int64_t frame_offset, int frame_count, int channel,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int c = KRMIN(channel, m_channelsPerFrame - 1);
|
||||
int c = std::min(channel, m_channelsPerFrame - 1);
|
||||
|
||||
if (frame_offset + frame_count <= 0) {
|
||||
// Range is entirely before the sample
|
||||
@@ -354,7 +354,7 @@ void KRAudioSample::PopulateBuffer(KRAudioSample* sound, int index, void* data)
|
||||
{
|
||||
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / sound->m_bytesPerFrame;
|
||||
int startFrame = index * maxFramesPerBuffer;
|
||||
__uint32_t frameCount = (__uint32_t)KRMIN(sound->m_totalFrames - startFrame, maxFramesPerBuffer);
|
||||
__uint32_t frameCount = std::min((__uint32_t)sound->m_totalFrames - startFrame, (__uint32_t)maxFramesPerBuffer);
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Audio Toolbox
|
||||
@@ -376,7 +376,7 @@ KRAudioBuffer* KRAudioSample::getBuffer(int index)
|
||||
|
||||
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / m_bytesPerFrame;
|
||||
int startFrame = index * maxFramesPerBuffer;
|
||||
__uint32_t frameCount = (__uint32_t)KRMIN(m_totalFrames - startFrame, maxFramesPerBuffer);
|
||||
__uint32_t frameCount = std::min((__uint32_t)m_totalFrames - startFrame, (__uint32_t)maxFramesPerBuffer);
|
||||
|
||||
KRAudioBuffer* buffer = new KRAudioBuffer(getContext().getAudioManager(), this, index, frameCount, m_frameRate, m_bytesPerFrame, PopulateBuffer);
|
||||
|
||||
|
||||
@@ -697,47 +697,47 @@ kraken_stream_level KRMaterial::getStreamLevel()
|
||||
kraken_stream_level stream_level = kraken_stream_level::STREAM_LEVEL_IN_HQ;
|
||||
|
||||
if (m_baseColorMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_baseColorMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_baseColorMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_normalMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_normalMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_normalMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_occlusionMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_occlusionMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_occlusionMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_metalicRoughnessMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_metalicRoughnessMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_metalicRoughnessMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_anisotropyMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_anisotropyMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_anisotropyMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_clearcoatMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_clearcoatMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_clearcoatMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_clearcoatRoughnessMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_clearcoatRoughnessMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_clearcoatRoughnessMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_clearcoatNormalMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_clearcoatNormalMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_clearcoatNormalMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_specularMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_specularMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_specularMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_specularColorMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_specularColorMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_specularColorMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
if (m_thicknessMap.texture.isBound()) {
|
||||
stream_level = KRMIN(stream_level, m_thicknessMap.texture.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, m_thicknessMap.texture.get()->getStreamLevel());
|
||||
}
|
||||
|
||||
return stream_level;
|
||||
|
||||
@@ -209,7 +209,7 @@ kraken_stream_level KRMesh::getStreamLevel()
|
||||
|
||||
for (KRMaterialBinding& material : m_materials) {
|
||||
if (material.isBound()) {
|
||||
stream_level = KRMIN(stream_level, material.get()->getStreamLevel());
|
||||
stream_level = std::min(stream_level, material.get()->getStreamLevel());
|
||||
}
|
||||
}
|
||||
bool all_vbo_data_loaded = true;
|
||||
|
||||
@@ -641,7 +641,7 @@ void KRMeshManager::KRVBOData::requestResidency(float lodCoverage)
|
||||
|
||||
m_manager->primeVBO(this);
|
||||
}
|
||||
m_last_frame_max_lod_coverage = KRMAX(lodCoverage, m_last_frame_max_lod_coverage);
|
||||
m_last_frame_max_lod_coverage = std::max(lodCoverage, m_last_frame_max_lod_coverage);
|
||||
}
|
||||
|
||||
|
||||
@@ -649,7 +649,7 @@ float KRMeshManager::KRVBOData::getStreamPriority()
|
||||
{
|
||||
long current_frame = m_manager->getContext().getCurrentFrame();
|
||||
if (current_frame > m_last_frame_used + 5) {
|
||||
return 1.0f - KRCLAMP((float)(current_frame - m_last_frame_used) / 60.0f, 0.0f, 1.0f);
|
||||
return 1.0f - std::clamp((float)(current_frame - m_last_frame_used) / 60.0f, 0.0f, 1.0f);
|
||||
} else {
|
||||
return 10000.0f + m_last_frame_max_lod_coverage * 10.0f;
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ kraken_stream_level KRScene::getStreamLevel()
|
||||
|
||||
if (m_pRootNode) {
|
||||
KRViewport viewport; // This isn't used when prime is false
|
||||
stream_level = KRMIN(stream_level, m_pRootNode->getStreamLevel(viewport));
|
||||
stream_level = std::min(stream_level, m_pRootNode->getStreamLevel(viewport));
|
||||
}
|
||||
|
||||
return stream_level;
|
||||
|
||||
@@ -122,7 +122,7 @@ void KRTexture::resize(int lod)
|
||||
|
||||
if (!m_haveNewHandles) {
|
||||
if (lod != -1) {
|
||||
int target_lod = KRMIN(lod, m_lod_count - 1);
|
||||
int target_lod = std::min(lod, m_lod_count - 1);
|
||||
|
||||
if (m_new_lod != target_lod || m_handles.empty()) {
|
||||
assert(m_newTextureMemUsed == 0);
|
||||
@@ -161,7 +161,7 @@ void KRTexture::requestResidency(float lodCoverage, KRTexture::texture_usage_t t
|
||||
|
||||
getContext().getTextureManager()->primeTexture(this);
|
||||
}
|
||||
m_last_frame_max_lod_coverage = KRMAX(lodCoverage, m_last_frame_max_lod_coverage);
|
||||
m_last_frame_max_lod_coverage = std::max(lodCoverage, m_last_frame_max_lod_coverage);
|
||||
m_last_frame_usage = static_cast<texture_usage_t>(static_cast<int>(m_last_frame_usage) | static_cast<int>(textureUsage));
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ float KRTexture::getStreamPriority()
|
||||
{
|
||||
long current_frame = getContext().getCurrentFrame();
|
||||
if (current_frame > m_last_frame_used + 5) {
|
||||
return 1.0f - KRCLAMP((float)(current_frame - m_last_frame_used) / 60.0f, 0.0f, 1.0f);
|
||||
return 1.0f - std::clamp((float)(current_frame - m_last_frame_used) / 60.0f, 0.0f, 1.0f);
|
||||
} else {
|
||||
float priority = 100.0f;
|
||||
if (m_last_frame_usage & (TEXTURE_USAGE_UI | TEXTURE_USAGE_SHADOW_DEPTH)) {
|
||||
@@ -294,7 +294,7 @@ bool KRTexture::allocate(KRDevice& device, int target_lod, VkImageCreateFlags im
|
||||
#endif
|
||||
)
|
||||
{
|
||||
int min_mip = KRMIN(target_lod, m_lod_count - 1);
|
||||
int min_mip = std::min(target_lod, m_lod_count - 1);
|
||||
int mip_count = m_lod_count - min_mip;
|
||||
hydra::Vector3i dimensions = getDimensions() / (1 << target_lod);
|
||||
|
||||
@@ -335,8 +335,8 @@ bool KRTexture::allocate(KRDevice& device, int target_lod, VkImageCreateFlags im
|
||||
|
||||
long KRTexture::getMemRequiredForLodRange(int min_lod, int max_lod /* = 0xff */)
|
||||
{
|
||||
int target_max_lod = KRMIN(max_lod, m_lod_count - 1);
|
||||
int target_min_lod = KRMIN(min_lod, m_lod_count - 1);
|
||||
int target_max_lod = std::min(max_lod, m_lod_count - 1);
|
||||
int target_min_lod = std::min(min_lod, m_lod_count - 1);
|
||||
|
||||
long memRequired = 0;
|
||||
for (int lod = target_min_lod; lod <= target_max_lod; lod++) {
|
||||
|
||||
@@ -84,7 +84,7 @@ bool KRTexture2D::createGPUTexture(int targetLod)
|
||||
break;
|
||||
}
|
||||
|
||||
int min_mip = KRMIN(targetLod, m_lod_count - 1);
|
||||
int min_mip = std::min(targetLod, m_lod_count - 1);
|
||||
int mip_count = m_lod_count - min_mip;
|
||||
|
||||
VkImageViewCreateInfo viewInfo{};
|
||||
|
||||
@@ -62,7 +62,7 @@ KRTextureKTX::KRTextureKTX(KRContext& context, Block* data, std::string name) :
|
||||
uint32_t blockStart = sizeof(KTXHeader) + m_header.bytesOfKeyValueData;
|
||||
uint32_t width = m_header.pixelWidth, height = m_header.pixelHeight;
|
||||
|
||||
for (int mipmap_level = 0; mipmap_level < (int)KRMAX(m_header.numberOfMipmapLevels, 1); mipmap_level++) {
|
||||
for (int mipmap_level = 0; mipmap_level < (int)std::max(m_header.numberOfMipmapLevels, (__uint32_t)1); mipmap_level++) {
|
||||
uint32_t blockLength;
|
||||
data->copy(&blockLength, blockStart, 4);
|
||||
blockStart += 4;
|
||||
@@ -82,7 +82,7 @@ KRTextureKTX::KRTextureKTX(KRContext& context, Block* data, std::string name) :
|
||||
}
|
||||
}
|
||||
|
||||
m_lod_count = (int)KRMAX(m_header.numberOfMipmapLevels, 1);
|
||||
m_lod_count = (int)std::max(m_header.numberOfMipmapLevels, (__uint32_t)1);
|
||||
}
|
||||
|
||||
KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<Block*>& blocks) : KRTexture2D(context, new Block(), name)
|
||||
@@ -362,7 +362,7 @@ VkFormat KRTextureKTX::getFormat() const
|
||||
|
||||
long KRTextureKTX::getMemRequiredForLod(int lod)
|
||||
{
|
||||
int target_lod = KRMIN(lod, m_lod_count - 1);
|
||||
int target_lod = std::min(lod, m_lod_count - 1);
|
||||
return (long)m_blocks[target_lod]->getSize();
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ bool KRTextureKTX::getLodData(void* buffer, int lod)
|
||||
return false;
|
||||
}
|
||||
|
||||
int target_lod = KRMIN(lod, m_lod_count - 1);
|
||||
int target_lod = std::min(lod, m_lod_count - 1);
|
||||
m_blocks[target_lod]->copy(buffer);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -68,7 +68,7 @@ KRTextureKTX2::KRTextureKTX2(KRContext& context, Block* data, std::string name)
|
||||
if (height < 1) {
|
||||
height = 1;
|
||||
}
|
||||
m_lod_count = (int)KRMAX(m_header.levelCount, 1);
|
||||
m_lod_count = (int)std::max(m_header.levelCount, (__uint32_t)1);
|
||||
}
|
||||
|
||||
KRTextureKTX2::~KRTextureKTX2()
|
||||
@@ -82,7 +82,7 @@ Vector3i KRTextureKTX2::getDimensions() const
|
||||
|
||||
long KRTextureKTX2::getMemRequiredForLod(int lod)
|
||||
{
|
||||
int target_lod = KRMIN(lod, m_lod_count - 1);
|
||||
int target_lod = std::min(lod, m_lod_count - 1);
|
||||
|
||||
KTX2LevelIndex levelIndex;
|
||||
m_pData->copy(&levelIndex, sizeof(m_header) + sizeof(KTX2LevelIndex) * target_lod, sizeof(KTX2LevelIndex));
|
||||
@@ -93,7 +93,7 @@ long KRTextureKTX2::getMemRequiredForLod(int lod)
|
||||
bool KRTextureKTX2::getLodData(void* buffer, int lod)
|
||||
{
|
||||
unsigned char* converted_image = (unsigned char*)buffer;
|
||||
int target_lod = KRMIN(lod, m_lod_count - 1);
|
||||
int target_lod = std::min(lod, m_lod_count - 1);
|
||||
|
||||
KTX2LevelIndex levelIndex;
|
||||
m_pData->copy(&levelIndex, sizeof(m_header) + sizeof(KTX2LevelIndex) * target_lod, sizeof(KTX2LevelIndex));
|
||||
|
||||
@@ -302,7 +302,7 @@ void KRTextureManager::balanceTextureMemory(long& memoryRemaining, long& memoryR
|
||||
|
||||
for (auto itr = m_activeTextures_streamer.begin(); itr != m_activeTextures_streamer.end(); itr++) {
|
||||
KRTexture* texture = (*itr).second;
|
||||
int min_lod_level = KRMIN(getContext().KRENGINE_TEXTURE_LQ_LOD, texture->getLodCount() - 1);
|
||||
int min_lod_level = std::min(getContext().KRENGINE_TEXTURE_LQ_LOD, texture->getLodCount() - 1);
|
||||
long minLodMem = texture->getMemRequiredForLodRange(min_lod_level);
|
||||
memoryRemaining -= minLodMem;
|
||||
|
||||
@@ -331,8 +331,8 @@ void KRTextureManager::balanceTextureMemory(long& memoryRemaining, long& memoryR
|
||||
}
|
||||
|
||||
KRTexture* texture = (*itr).second;
|
||||
int min_lod_level = KRMIN(getContext().KRENGINE_TEXTURE_LQ_LOD, texture->getLodCount());
|
||||
int target_lod_level = KRMIN(getContext().KRENGINE_TEXTURE_HQ_LOD + mip_drop, texture->getLodCount());
|
||||
int min_lod_level = std::min(getContext().KRENGINE_TEXTURE_LQ_LOD, texture->getLodCount());
|
||||
int target_lod_level = std::min(getContext().KRENGINE_TEXTURE_HQ_LOD + mip_drop, texture->getLodCount());
|
||||
long targetMem = texture->getMemRequiredForLodRange(target_lod_level);
|
||||
long additionalMemRequired = targetMem - texture->getMemRequiredForLodRange(min_lod_level);
|
||||
memoryRemainingThisMip -= additionalMemRequired;
|
||||
|
||||
@@ -174,7 +174,7 @@ VkFormat KRTexturePVR::getFormat() const
|
||||
|
||||
long KRTexturePVR::getMemRequiredForLod(int lod)
|
||||
{
|
||||
int target_lod = KRMIN(lod, m_lod_count - 1);
|
||||
int target_lod = std::min(lod, m_lod_count - 1);
|
||||
return m_blocks[target_lod]->getSize();
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ bool KRTexturePVR::getLodData(void* buffer, int lod)
|
||||
return false;
|
||||
}
|
||||
|
||||
int target_lod = KRMIN(lod, m_lod_count - 1);
|
||||
int target_lod = std::min(lod, m_lod_count - 1);
|
||||
m_blocks[target_lod]->copy(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user