From 5096b391deca4f636ac68ba62bdf83be288972e3 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Mon, 14 Jan 2019 21:07:32 -0800 Subject: [PATCH] Fix more warnings in MSVC --- CMakeLists.txt | 13 ++- kraken/KRAudioSource.cpp | 2 +- kraken/KRLight.cpp | 6 +- kraken/KRMesh.cpp | 6 +- kraken/KRMeshManager.cpp | 14 ++-- kraken/KRMeshManager.h | 2 +- kraken/KRNode.cpp | 14 ++-- kraken/KRShaderManager.cpp | 22 +++--- kraken/KRShaderManager.h | 158 ++++++++++++++++++------------------- 9 files changed, 121 insertions(+), 116 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75c5423..ce49efa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,12 @@ -cmake_minimum_required (VERSION 2.6) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) +cmake_minimum_required (VERSION 2.8) + +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) +else(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) MESSAGE( "64 bits compiler detected" ) diff --git a/kraken/KRAudioSource.cpp b/kraken/KRAudioSource.cpp index 2a02ac2..0d15444 100755 --- a/kraken/KRAudioSource.cpp +++ b/kraken/KRAudioSource.cpp @@ -433,7 +433,7 @@ float KRAudioSource::getAudioTime() void KRAudioSource::setAudioTime(float new_position) { // Sets the audio playback position with units of floating point seconds. - setAudioFrame(new_position * 44100.0f); + setAudioFrame((__int64_t)(new_position * 44100.0f)); } void KRAudioSource::sample(int frame_count, int channel, float *buffer, float gain) diff --git a/kraken/KRLight.cpp b/kraken/KRLight.cpp index 389157c..9242131 100755 --- a/kraken/KRLight.cpp +++ b/kraken/KRLight.cpp @@ -191,7 +191,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light float particle_range = 600.0f; - int particle_count = m_dust_particle_density * pow(particle_range, 3); + int particle_count = (int)(m_dust_particle_density * pow(particle_range, 3)); if(particle_count > KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES) particle_count = KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES; // Enable z-buffer test @@ -421,12 +421,12 @@ void KRLight::renderShadowBuffers(KRCamera *pCamera) GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, shadowFramebuffer[iShadow])); GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowDepthTexture[iShadow], 0)); - GLDEBUG(glViewport(0, 0, m_shadowViewports[iShadow].getSize().x, m_shadowViewports[iShadow].getSize().y)); + GLDEBUG(glViewport(0, 0, (GLsizei)m_shadowViewports[iShadow].getSize().x, (GLsizei)m_shadowViewports[iShadow].getSize().y)); GLDEBUG(glClearDepthf(0.0f)); GLDEBUG(glClear(GL_DEPTH_BUFFER_BIT)); - GLDEBUG(glViewport(1, 1, m_shadowViewports[iShadow].getSize().x - 2, m_shadowViewports[iShadow].getSize().y - 2)); + GLDEBUG(glViewport(1, 1, (GLsizei)m_shadowViewports[iShadow].getSize().x - 2, (GLsizei)m_shadowViewports[iShadow].getSize().y - 2)); GLDEBUG(glClearDepthf(1.0f)); diff --git a/kraken/KRMesh.cpp b/kraken/KRMesh.cpp index f5158d0..edf9fde 100755 --- a/kraken/KRMesh.cpp +++ b/kraken/KRMesh.cpp @@ -1053,15 +1053,15 @@ void KRMesh::updateAttributeOffsets() { pack_header *header = getHeader(); int mask = 0; - for(int i=0; i < KRENGINE_NUM_ATTRIBUTES; i++) { + for(size_t i=0; i < KRENGINE_NUM_ATTRIBUTES; i++) { if(has_vertex_attribute((vertex_attrib_t)i)) { - m_vertex_attribute_offset[i] = VertexSizeForAttributes(header->vertex_attrib_flags & mask); + m_vertex_attribute_offset[i] = (int)VertexSizeForAttributes(header->vertex_attrib_flags & mask); } else { m_vertex_attribute_offset[i] = -1; } mask = (mask << 1) | 1; } - m_vertex_size = VertexSizeForAttributes(header->vertex_attrib_flags); + m_vertex_size = (int)VertexSizeForAttributes(header->vertex_attrib_flags); } size_t KRMesh::AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_flags) diff --git a/kraken/KRMeshManager.cpp b/kraken/KRMeshManager.cpp index 77eb19e..a71605c 100755 --- a/kraken/KRMeshManager.cpp +++ b/kraken/KRMeshManager.cpp @@ -401,32 +401,32 @@ KRDataBlock &KRMeshManager::getVolumetricLightingVertexes() for(int iPlane=0; iPlane < KRENGINE_MAX_VOLUMETRIC_PLANES; iPlane++) { vertex_data[iVertex].vertex.x = -1.0f; vertex_data[iVertex].vertex.y = -1.0f; - vertex_data[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.z = (GLfloat)iPlane; iVertex++; vertex_data[iVertex].vertex.x = 1.0f; vertex_data[iVertex].vertex.y = -1.0f; - vertex_data[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.z = (GLfloat)iPlane; iVertex++; vertex_data[iVertex].vertex.x = -1.0f; vertex_data[iVertex].vertex.y = 1.0f; - vertex_data[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.z = (GLfloat)iPlane; iVertex++; vertex_data[iVertex].vertex.x = -1.0f; vertex_data[iVertex].vertex.y = 1.0f; - vertex_data[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.z = (GLfloat)iPlane; iVertex++; vertex_data[iVertex].vertex.x = 1.0f; vertex_data[iVertex].vertex.y = -1.0f; - vertex_data[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.z = (GLfloat)iPlane; iVertex++; vertex_data[iVertex].vertex.x = 1.0f; vertex_data[iVertex].vertex.y = 1.0f; - vertex_data[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.z = (GLfloat)iPlane; iVertex++; } @@ -481,7 +481,7 @@ long KRMeshManager::getMemoryTransferedThisFrame() } -int KRMeshManager::getActiveVBOCount() +size_t KRMeshManager::getActiveVBOCount() { return m_vbosActive.size(); } diff --git a/kraken/KRMeshManager.h b/kraken/KRMeshManager.h index 660b150..74842e0 100755 --- a/kraken/KRMeshManager.h +++ b/kraken/KRMeshManager.h @@ -150,7 +150,7 @@ public: long getMemoryTransferedThisFrame(); - int getActiveVBOCount(); + size_t getActiveVBOCount(); struct draw_call_info { KRNode::RenderPass pass; diff --git a/kraken/KRNode.cpp b/kraken/KRNode.cpp index 48f6384..94f2320 100755 --- a/kraken/KRNode.cpp +++ b/kraken/KRNode.cpp @@ -125,13 +125,13 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) { e->SetAttribute("name", m_name.c_str()); kraken::setXMLAttribute("translate", e, m_localTranslation, Vector3::Zero()); kraken::setXMLAttribute("scale", e, m_localScale, Vector3::One()); - kraken::setXMLAttribute("rotate", e, (m_localRotation * (180.0f / M_PI)), Vector3::Zero()); + kraken::setXMLAttribute("rotate", e, (m_localRotation * (180.0f / (float)M_PI)), Vector3::Zero()); kraken::setXMLAttribute("rotate_offset", e, m_rotationOffset, Vector3::Zero()); kraken::setXMLAttribute("scale_offset", e, m_scalingOffset, Vector3::Zero()); kraken::setXMLAttribute("rotate_pivot", e, m_rotationPivot, Vector3::Zero()); kraken::setXMLAttribute("scale_pivot", e, m_scalingPivot, Vector3::Zero()); - kraken::setXMLAttribute("pre_rotate", e, (m_preRotation * (180.0f / M_PI)), Vector3::Zero()); - kraken::setXMLAttribute("post_rotate", e, (m_postRotation * (180.0f / M_PI)), Vector3::Zero()); + kraken::setXMLAttribute("pre_rotate", e, (m_preRotation * (180.0f / (float)M_PI)), Vector3::Zero()); + kraken::setXMLAttribute("post_rotate", e, (m_postRotation * (180.0f / (float)M_PI)), Vector3::Zero()); for(std::set::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) { KRNode *child = (*itr); @@ -145,11 +145,11 @@ void KRNode::loadXML(tinyxml2::XMLElement *e) { m_localTranslation = kraken::getXMLAttribute("translate", e, Vector3::Zero()); m_localScale = kraken::getXMLAttribute("scale", e, Vector3::One()); m_localRotation = kraken::getXMLAttribute("rotate", e, Vector3::Zero()); - m_localRotation *= M_PI / 180.0f; // Convert degrees to radians + m_localRotation *= (float)M_PI / 180.0f; // Convert degrees to radians m_preRotation = kraken::getXMLAttribute("pre_rotate", e, Vector3::Zero()); - m_preRotation *= M_PI / 180.0f; // Convert degrees to radians + m_preRotation *= (float)M_PI / 180.0f; // Convert degrees to radians m_postRotation = kraken::getXMLAttribute("post_rotate", e, Vector3::Zero()); - m_postRotation *= M_PI / 180.0f; // Convert degrees to radians + m_postRotation *= (float)M_PI / 180.0f; // Convert degrees to radians m_rotationOffset = kraken::getXMLAttribute("rotate_offset", e, Vector3::Zero()); m_scalingOffset = kraken::getXMLAttribute("scale_offset", e, Vector3::Zero()); @@ -763,7 +763,7 @@ void KRNode::SetAttribute(node_attribute_type attrib, float v) { if(m_animation_mask[attrib]) return; - const float DEGREES_TO_RAD = M_PI / 180.0f; + const float DEGREES_TO_RAD = (float)M_PI / 180.0f; //printf("%s - ", m_name.c_str()); switch(attrib) { diff --git a/kraken/KRShaderManager.cpp b/kraken/KRShaderManager.cpp index 157f89d..7345d83 100755 --- a/kraken/KRShaderManager.cpp +++ b/kraken/KRShaderManager.cpp @@ -57,9 +57,9 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p int light_point_count = 0; int light_spot_count = 0; 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) { - light_directional_count = directional_lights.size(); - light_point_count = point_lights.size(); - light_spot_count = spot_lights.size(); + light_directional_count = (int)directional_lights.size(); + light_point_count = (int)point_lights.size(); + light_spot_count = (int)spot_lights.size(); for(std::vector::const_iterator light_itr=directional_lights.begin(); light_itr != directional_lights.end(); light_itr++) { KRDirectionalLight *directional_light =(*light_itr); iShadowQuality = directional_light->getShadowBufferCount(); @@ -109,13 +109,13 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p key.second.push_back(pCamera->settings.dof_quality); key.second.push_back(pCamera->settings.bEnableFlash); key.second.push_back(pCamera->settings.bEnableVignette); - key.second.push_back(pCamera->settings.dof_depth * 1000.0f); - key.second.push_back(pCamera->settings.dof_falloff * 1000.0f); - key.second.push_back(pCamera->settings.flash_depth * 1000.0f); - key.second.push_back(pCamera->settings.flash_falloff * 1000.0f); - key.second.push_back(pCamera->settings.flash_intensity * 1000.0f); - key.second.push_back(pCamera->settings.vignette_radius * 1000.0f); - key.second.push_back(pCamera->settings.vignette_falloff * 1000.0f); + key.second.push_back((int)(pCamera->settings.dof_depth * 1000.0f)); + key.second.push_back((int)(pCamera->settings.dof_falloff * 1000.0f)); + key.second.push_back((int)(pCamera->settings.flash_depth * 1000.0f)); + key.second.push_back((int)(pCamera->settings.flash_falloff * 1000.0f)); + key.second.push_back((int)(pCamera->settings.flash_intensity * 1000.0f)); + key.second.push_back((int)(pCamera->settings.vignette_radius * 1000.0f)); + key.second.push_back((int)(pCamera->settings.vignette_falloff * 1000.0f)); key.second.push_back(bRimColor); key.second.push_back(bFadeColorEnabled); @@ -278,6 +278,6 @@ const std::string &KRShaderManager::getVertShaderSource(const std::string &name) return m_vertShaderSource[name]; } -long KRShaderManager::getShaderHandlesUsed() { +size_t KRShaderManager::getShaderHandlesUsed() { return m_shaders.size(); } diff --git a/kraken/KRShaderManager.h b/kraken/KRShaderManager.h index e456b24..ee2798d 100755 --- a/kraken/KRShaderManager.h +++ b/kraken/KRShaderManager.h @@ -1,79 +1,79 @@ -// -// KRShaderManager.h -// KREngine -// -// Copyright 2012 Kearwood Gilbert. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other materials -// provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and documentation are those of the -// authors and should not be interpreted as representing official policies, either expressed -// or implied, of Kearwood Gilbert. -// - - -#include "KREngine-common.h" - -#include "KRCamera.h" -#include "KRDataBlock.h" -#include "KRNode.h" - -using std::map; -using std::vector; - -#include "KRShader.h" - -#ifndef KRSHADERMANAGER_H -#define KRSHADERMANAGER_H - -class KRShader; -class KRCamera; - -class KRShaderManager : public KRContextObject { -public: - KRShaderManager(KRContext &context); - virtual ~KRShaderManager(); - - void loadFragmentShader(const std::string &name, KRDataBlock *data); - void loadVertexShader(const std::string &name, KRDataBlock *data); - const std::string &getFragShaderSource(const std::string &name); - const std::string &getVertShaderSource(const std::string &name); - - - KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false); - - bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const Matrix4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); - - bool selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const Matrix4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); - - long getShaderHandlesUsed(); - - KRShader *m_active_shader; - -private: - //unordered_map m_shaders; - std::map >, KRShader *> m_shaders; - - unordered_map m_fragShaderSource; - unordered_map m_vertShaderSource; -}; - -#endif +// +// KRShaderManager.h +// KREngine +// +// Copyright 2012 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + + +#include "KREngine-common.h" + +#include "KRCamera.h" +#include "KRDataBlock.h" +#include "KRNode.h" + +using std::map; +using std::vector; + +#include "KRShader.h" + +#ifndef KRSHADERMANAGER_H +#define KRSHADERMANAGER_H + +class KRShader; +class KRCamera; + +class KRShaderManager : public KRContextObject { +public: + KRShaderManager(KRContext &context); + virtual ~KRShaderManager(); + + void loadFragmentShader(const std::string &name, KRDataBlock *data); + void loadVertexShader(const std::string &name, KRDataBlock *data); + const std::string &getFragShaderSource(const std::string &name); + const std::string &getVertShaderSource(const std::string &name); + + + KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false); + + bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const Matrix4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); + + bool selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const Matrix4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); + + size_t getShaderHandlesUsed(); + + KRShader *m_active_shader; + +private: + //unordered_map m_shaders; + std::map >, KRShader *> m_shaders; + + unordered_map m_fragShaderSource; + unordered_map m_vertShaderSource; +}; + +#endif