Cleanup warnings and bugs found through static analysis
This commit is contained in:
@@ -233,11 +233,11 @@ bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const
|
||||
quadrant[i] = LEFT;
|
||||
candidatePlane[i] = min.c[i];
|
||||
inside = false;
|
||||
}else if (v1.c[i] > max.c[i]) {
|
||||
} else if(v1.c[i] > max.c[i]) {
|
||||
quadrant[i] = RIGHT;
|
||||
candidatePlane[i] = max.c[i];
|
||||
inside = false;
|
||||
}else {
|
||||
} else {
|
||||
quadrant[i] = MIDDLE;
|
||||
}
|
||||
|
||||
|
||||
@@ -872,12 +872,11 @@ KRVector2 KRAudioManager::getNearestHRTFSample(const KRVector2 &dir)
|
||||
|
||||
KRVector2 min_direction;
|
||||
bool first = true;
|
||||
float min_distance;
|
||||
float min_distance = 360.0f;
|
||||
for(std::vector<KRVector2>::iterator itr = m_hrtf_sample_locations.begin(); itr != m_hrtf_sample_locations.end(); itr++) {
|
||||
if(first) {
|
||||
first = false;
|
||||
min_direction = (*itr);
|
||||
min_distance = 360.0f;
|
||||
} else if((*itr).x == elevation) {
|
||||
float distance = fabs(dir_deg.y - (*itr).y);
|
||||
if(min_distance > distance) {
|
||||
|
||||
@@ -507,6 +507,7 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
||||
|
||||
|
||||
#if GL_EXT_discard_framebuffer
|
||||
|
||||
GLenum attachments[2] = {GL_DEPTH_ATTACHMENT, GL_COLOR_ATTACHMENT0};
|
||||
GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments));
|
||||
#endif
|
||||
@@ -671,6 +672,8 @@ void KRCamera::renderPost()
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
|
||||
|
||||
/*
|
||||
FINDME - Determine if we still need this...
|
||||
|
||||
static const GLfloat squareVerticesShadow[3][8] = {{
|
||||
-1.0f, -1.0f,
|
||||
@@ -688,6 +691,7 @@ void KRCamera::renderPost()
|
||||
0.00f, -0.60f,
|
||||
0.40f, -0.60f,
|
||||
}};
|
||||
*/
|
||||
|
||||
|
||||
GLDEBUG(glViewport(0, 0, m_viewport.getSize().x, m_viewport.getSize().y));
|
||||
|
||||
@@ -44,11 +44,15 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
const float KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE = 1.25f; // Scale to apply to view frustrum bounds so that we don't need to refresh shadows on every frame
|
||||
int cShadows = 1;
|
||||
for(int iShadow=0; iShadow < cShadows; iShadow++) {
|
||||
/*
|
||||
TODO - Determine if we still need this...
|
||||
|
||||
GLfloat shadowMinDepths[3][3] = {{0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f},{0.0f, 0.05f, 0.3f}};
|
||||
GLfloat shadowMaxDepths[3][3] = {{0.0f, 0.0f, 1.0f},{0.1f, 0.0f, 0.0f},{0.1f, 0.3f, 1.0f}};
|
||||
|
||||
float min_depth = 0.0f;
|
||||
float max_depth = 1.0f;
|
||||
*/
|
||||
|
||||
KRAABB worldSpacefrustrumSliceBounds = KRAABB(KRVector3(-1.0f, -1.0f, -1.0f), KRVector3(1.0f, 1.0f, 1.0f), KRMat4::Invert(viewport.getViewProjectionMatrix()));
|
||||
worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "KRMaterial.h"
|
||||
#include "KRTextureManager.h"
|
||||
|
||||
#include "KRcontext.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(context, szName) {
|
||||
m_name = szName;
|
||||
|
||||
@@ -173,11 +173,14 @@ void KRMesh::getMaterials()
|
||||
|
||||
for(std::vector<KRMesh::Submesh *>::iterator itr = m_submeshes.begin(); itr != m_submeshes.end(); itr++) {
|
||||
const char *szMaterialName = (*itr)->szMaterialName;
|
||||
KRMaterial *pMaterial = getContext().getMaterialManager()->getMaterial(szMaterialName);
|
||||
KRMaterial *pMaterial = nullptr;
|
||||
if(*szMaterialName != '\0') {
|
||||
pMaterial = getContext().getMaterialManager()->getMaterial(szMaterialName);
|
||||
}
|
||||
m_materials.push_back(pMaterial);
|
||||
if(pMaterial) {
|
||||
m_uniqueMaterials.insert(pMaterial);
|
||||
} else {
|
||||
} else if(*szMaterialName != '\0') {
|
||||
KRContext::Log(KRContext::LOG_LEVEL_WARNING, "Missing material: %s", szMaterialName);
|
||||
}
|
||||
}
|
||||
@@ -1456,7 +1459,7 @@ void KRMesh::convertToIndexed()
|
||||
}
|
||||
}
|
||||
|
||||
delete szKey;
|
||||
delete[] szKey;
|
||||
|
||||
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Convert to indexed, before: %i after: %i (%.2f%% saving)", getHeader()->vertex_count, mi.vertices.size(), ((float)getHeader()->vertex_count - (float)mi.vertices.size()) / (float)getHeader()->vertex_count * 100.0f);
|
||||
|
||||
@@ -1533,7 +1536,7 @@ void KRMesh::optimizeIndexes()
|
||||
pack_header *header = getHeader();
|
||||
|
||||
__uint16_t *index_data = getIndexData();
|
||||
unsigned char *vertex_data = getVertexData();
|
||||
// unsigned char *vertex_data = getVertexData(); // Uncomment when re-enabling Step 2 below
|
||||
|
||||
for(int submesh_index=0; submesh_index < header->submesh_count; submesh_index++) {
|
||||
pack_material *submesh = getSubmesh(submesh_index);
|
||||
|
||||
@@ -402,9 +402,9 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
|
||||
const char *szName = e->Attribute("name");
|
||||
if(strcmp(szElementName, "node") == 0) {
|
||||
new_node = new KRNode(scene, szName);
|
||||
} if(strcmp(szElementName, "lod_set") == 0) {
|
||||
} else if(strcmp(szElementName, "lod_set") == 0) {
|
||||
new_node = new KRLODSet(scene, szName);
|
||||
} if(strcmp(szElementName, "lod_group") == 0) {
|
||||
} else if(strcmp(szElementName, "lod_group") == 0) {
|
||||
new_node = new KRLODGroup(scene, szName);
|
||||
} else if(strcmp(szElementName, "point_light") == 0) {
|
||||
new_node = new KRPointLight(scene, szName);
|
||||
|
||||
@@ -128,11 +128,12 @@ KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::st
|
||||
GLDEBUG(glCompileShader(vertexShader));
|
||||
|
||||
// Report any compile issues to stderr
|
||||
GLint logLength;
|
||||
GLint logLength = 0;
|
||||
GLDEBUG(glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength + 1);
|
||||
assert(log != NULL);
|
||||
log[0] = '\0'; // In case glGetShaderInfoLog fails
|
||||
GLDEBUG(glGetShaderInfoLog(vertexShader, logLength, &logLength, log));
|
||||
log[logLength] = '\0';
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KREngine - Failed to compile vertex shader: %s\nShader compile log:\n%s", szKey, log);
|
||||
@@ -146,10 +147,12 @@ KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::st
|
||||
GLDEBUG(glCompileShader(fragShader));
|
||||
|
||||
// Report any compile issues to stderr
|
||||
logLength = 0; // In case glGetShaderiv fails
|
||||
GLDEBUG(glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength + 1);
|
||||
assert(log != NULL);
|
||||
log[0] = '\0'; // In case glGetShaderInfoLog fails
|
||||
GLDEBUG(glGetShaderInfoLog(fragShader, logLength, &logLength, log));
|
||||
log[logLength] = '\0';
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KREngine - Failed to compile fragment shader: %s\nShader compile log:\n%s", szKey, log);
|
||||
@@ -181,12 +184,13 @@ KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::st
|
||||
if(link_success != GL_TRUE) {
|
||||
// Report any linking issues to stderr
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KREngine - Failed to link shader program: %s", szKey);
|
||||
|
||||
logLength = 0; // In case glGetProgramiv fails
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0)
|
||||
{
|
||||
GLchar *log = (GLchar *)malloc(logLength + 1);
|
||||
assert(log != NULL);
|
||||
log[0] = '\0'; // In case glGetProgramInfoLog fails
|
||||
GLDEBUG(glGetProgramInfoLog(m_iProgram, logLength, &logLength, log));
|
||||
log[logLength] = '\0';
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Program link log:\n%s", log);
|
||||
@@ -363,8 +367,8 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
setUniform(KRENGINE_UNIFORM_ABSOLUTE_TIME, getContext().getAbsoluteTime());
|
||||
|
||||
int light_directional_count = 0;
|
||||
int light_point_count = 0;
|
||||
int light_spot_count = 0;
|
||||
//int light_point_count = 0;
|
||||
//int light_spot_count = 0;
|
||||
// TODO - Need to support multiple lights and more light types in forward rendering
|
||||
if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && renderPass != KRNode::RENDER_PASS_DEFERRED_GBUFFER && renderPass != KRNode::RENDER_PASS_DEFERRED_OPAQUE && renderPass != KRNode::RENDER_PASS_GENERATE_SHADOWMAPS) {
|
||||
|
||||
@@ -422,8 +426,8 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
light_directional_count++;
|
||||
}
|
||||
|
||||
light_point_count = point_lights.size();
|
||||
light_spot_count = spot_lights.size();
|
||||
//light_point_count = point_lights.size();
|
||||
//light_spot_count = spot_lights.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -566,11 +570,13 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_VALIDATE_STATUS, &validate_status));
|
||||
if(validate_status != GL_TRUE) {
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KREngine - Failed to validate shader program: %s", m_szKey);
|
||||
logLength = 0; // In case glGetProgramiv fails
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0)
|
||||
{
|
||||
GLchar *log = (GLchar *)malloc(logLength + 1);
|
||||
assert(log != NULL);
|
||||
log[0] = '\0'; // In case glGetProgramInfoLog fails
|
||||
GLDEBUG(glGetProgramInfoLog(m_iProgram, logLength, &logLength, log));
|
||||
log[logLength] = '\0';
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Program validate log:\n%s", log);
|
||||
|
||||
@@ -65,8 +65,8 @@ long KRTexture::getReferencedMemSize() {
|
||||
|
||||
void KRTexture::resize(int max_dim)
|
||||
{
|
||||
while(m_handle_lock.test_and_set()); // Spin lock
|
||||
{
|
||||
while(m_handle_lock.test_and_set()) {}; // Spin lock
|
||||
|
||||
if(m_iHandle == m_iNewHandle) {
|
||||
if(max_dim == 0) {
|
||||
m_iNewHandle = 0;
|
||||
@@ -91,7 +91,6 @@ void KRTexture::resize(int max_dim)
|
||||
}
|
||||
|
||||
m_handle_lock.clear();
|
||||
}
|
||||
}
|
||||
|
||||
GLuint KRTexture::getHandle() {
|
||||
|
||||
@@ -148,15 +148,6 @@ KRTexture *KRTextureManager::getTextureCube(const char *szName) {
|
||||
if(itr == m_textures.end()) {
|
||||
|
||||
// Defer resolving the texture cube until its referenced textures are ready
|
||||
const GLenum TARGETS[6] = {
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
||||
};
|
||||
|
||||
const char *SUFFIXES[6] = {
|
||||
"_positive_x",
|
||||
"_negative_x",
|
||||
|
||||
@@ -96,12 +96,6 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
TGA_HEADER *pHeader = (TGA_HEADER *)m_pData->getStart();
|
||||
unsigned char *pData = (unsigned char *)pHeader + (long)pHeader->idlength + (long)pHeader->colourmaplength * (long)pHeader->colourmaptype + sizeof(TGA_HEADER);
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
GLenum base_internal_format = GL_BGRA;
|
||||
#else
|
||||
GLenum base_internal_format = pHeader->bitsperpixel == 24 ? GL_BGR : GL_BGRA;
|
||||
#endif
|
||||
|
||||
GLenum internal_format = GL_RGBA;
|
||||
|
||||
#if !TARGET_OS_IPHONE
|
||||
@@ -115,8 +109,6 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
return false; // Mapped colors not supported
|
||||
}
|
||||
|
||||
GLenum err;
|
||||
|
||||
switch(pHeader->imagetype) {
|
||||
case 2: // rgb
|
||||
switch(pHeader->bitsperpixel) {
|
||||
|
||||
Reference in New Issue
Block a user