Implemented KRMeshQuad, representing a stock quad model
Implemented KRSprite --HG-- branch : nfb
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
|
||||
#include "KRMesh.h"
|
||||
#include "KRMeshCube.h"
|
||||
#include "KRMeshQuad.h"
|
||||
#include "KRMeshSphere.h"
|
||||
|
||||
KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context), m_streamer(context) {
|
||||
@@ -45,8 +46,8 @@ KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context), m_s
|
||||
m_vboMemUsed = 0;
|
||||
m_memoryTransferredThisFrame = 0;
|
||||
|
||||
// addModel(new KRMeshCube(context)); // FINDME - HACK! This needs to be fixed, as it currently segfaults
|
||||
|
||||
addModel(new KRMeshCube(context)); // FINDME - HACK! This needs to be fixed, as it currently segfaults
|
||||
addModel(new KRMeshQuad(context)); // FINDME - HACK! This needs to be fixed, as it currently segfaults
|
||||
addModel(new KRMeshSphere(context));
|
||||
m_draw_call_logging_enabled = false;
|
||||
m_draw_call_log_used = false;
|
||||
|
||||
68
KREngine/kraken/KRMeshQuad.cpp
Normal file
68
KREngine/kraken/KRMeshQuad.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// KRMeshQuad.cpp
|
||||
// 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 "KRMeshQuad.h"
|
||||
|
||||
|
||||
KRMeshQuad::KRMeshQuad(KRContext &context) : KRMesh(context, "__quad")
|
||||
{
|
||||
KRMesh::mesh_info mi;
|
||||
|
||||
|
||||
mi.vertices.push_back(KRVector3(1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(KRVector3(-1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(KRVector3(1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(KRVector3(-1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(KRVector3(-1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(KRVector3(-1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(KRVector3(-1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(KRVector3(1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(KRVector3(1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(KRVector3(1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(KRVector3(1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(KRVector3(-1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(KRVector3(1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(KRVector3(-1.0, 1.0,-1.0));
|
||||
|
||||
|
||||
mi.submesh_starts.push_back(0);
|
||||
mi.submesh_lengths.push_back(mi.vertices.size());
|
||||
mi.material_names.push_back("");
|
||||
mi.format = KRENGINE_MODEL_FORMAT_STRIP;
|
||||
|
||||
|
||||
LoadData(mi, true, true);
|
||||
}
|
||||
|
||||
KRMeshQuad::~KRMeshQuad()
|
||||
{
|
||||
|
||||
}
|
||||
44
KREngine/kraken/KRMeshQuad.h
Normal file
44
KREngine/kraken/KRMeshQuad.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// KRMeshQuad.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.
|
||||
//
|
||||
|
||||
#ifndef KRMESHQUAD_H
|
||||
#define KRMESHQUAD_H
|
||||
|
||||
#include "KRMesh.h"
|
||||
|
||||
class KRMeshQuad : public KRMesh {
|
||||
public:
|
||||
KRMeshQuad(KRContext &context);
|
||||
virtual ~KRMeshQuad();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "KRAudioSource.h"
|
||||
#include "KRAmbientZone.h"
|
||||
#include "KRReverbZone.h"
|
||||
#include "KRSprite.h"
|
||||
|
||||
KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext())
|
||||
{
|
||||
@@ -404,6 +405,8 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
|
||||
new_node = new KRSpotLight(scene, szName);
|
||||
} else if(strcmp(szElementName, "particles_newtonian") == 0) {
|
||||
new_node = new KRParticleSystemNewtonian(scene, szName);
|
||||
} else if(strcmp(szElementName, "sprite") == 0) {
|
||||
new_node = new KRSprite(scene, szName);
|
||||
} else if(strcmp(szElementName, "model") == 0) {
|
||||
float lod_min_coverage = 0.0f;
|
||||
if(e->QueryFloatAttribute("lod_min_coverage", &lod_min_coverage) != tinyxml2::XML_SUCCESS) {
|
||||
|
||||
123
KREngine/kraken/KRSprite.cpp
Normal file
123
KREngine/kraken/KRSprite.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// KRSprite.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 12-04-05.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include "KRSprite.h"
|
||||
|
||||
#include "KRNode.h"
|
||||
#include "KRMat4.h"
|
||||
#include "KRVector3.h"
|
||||
#include "KRCamera.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
#include "KRShaderManager.h"
|
||||
#include "KRShader.h"
|
||||
#include "KRStockGeometry.h"
|
||||
#include "KRDirectionalLight.h"
|
||||
#include "KRSpotLight.h"
|
||||
#include "KRPointLight.h"
|
||||
|
||||
|
||||
KRSprite::KRSprite(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||
{
|
||||
m_spriteTexture = "";
|
||||
m_pSpriteTexture = NULL;
|
||||
m_spriteSize = 0.0;
|
||||
}
|
||||
|
||||
KRSprite::~KRSprite()
|
||||
{
|
||||
}
|
||||
|
||||
std::string KRSprite::getElementName() {
|
||||
return "sprite";
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement *KRSprite::saveXML( tinyxml2::XMLNode *parent)
|
||||
{
|
||||
tinyxml2::XMLElement *e = KRNode::saveXML(parent);
|
||||
e->SetAttribute("sprite_size", m_spriteSize);
|
||||
e->SetAttribute("sprite_texture", m_spriteTexture.c_str());
|
||||
return e;
|
||||
}
|
||||
|
||||
void KRSprite::loadXML(tinyxml2::XMLElement *e) {
|
||||
KRNode::loadXML(e);
|
||||
|
||||
if(e->QueryFloatAttribute("sprite_size", &m_spriteSize) != tinyxml2::XML_SUCCESS) {
|
||||
m_spriteSize = 0.0;
|
||||
}
|
||||
|
||||
const char *szSpriteTexture = e->Attribute("sprite_texture");
|
||||
if(szSpriteTexture) {
|
||||
m_spriteTexture = szSpriteTexture;
|
||||
} else {
|
||||
m_spriteTexture = "";
|
||||
}
|
||||
m_pSpriteTexture = NULL;
|
||||
}
|
||||
|
||||
void KRSprite::setSpriteTexture(std::string sprite_texture) {
|
||||
m_spriteTexture = sprite_texture;
|
||||
m_pSpriteTexture = NULL;
|
||||
}
|
||||
|
||||
void KRSprite::setSpriteSize(float sprite_size) {
|
||||
// TODO - Deprecated - This should come from the localScale
|
||||
m_spriteSize = sprite_size;
|
||||
}
|
||||
|
||||
KRAABB KRSprite::getBounds() {
|
||||
return KRAABB(KRVector3(-m_spriteSize), KRVector3(m_spriteSize), getModelMatrix());
|
||||
}
|
||||
|
||||
|
||||
void KRSprite::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) {
|
||||
|
||||
KRNode::render(pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
||||
if(m_spriteTexture.size() && m_spriteSize > 0.0f) {
|
||||
|
||||
|
||||
if(!m_pSpriteTexture && m_spriteTexture.size()) {
|
||||
m_pSpriteTexture = getContext().getTextureManager()->getTexture(m_spriteTexture);
|
||||
}
|
||||
|
||||
if(m_pSpriteTexture) {
|
||||
/*
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
*/
|
||||
|
||||
// TODO - Sprites are currently additive only. Need to expose this and allow for multiple blending modes
|
||||
|
||||
// Enable z-buffer test
|
||||
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||
|
||||
// Render light sprite on transparency pass
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass)) {
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_spriteSize);
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture);
|
||||
m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
39
KREngine/kraken/KRSprite.h
Normal file
39
KREngine/kraken/KRSprite.h
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// KRSprite.h
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 12-04-05.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef KRSPRITE_H
|
||||
#define KRSPRITE_H
|
||||
|
||||
#include "KRResource.h"
|
||||
#include "KRNode.h"
|
||||
#include "KRTexture.h"
|
||||
|
||||
class KRSprite : public KRNode {
|
||||
public:
|
||||
KRSprite(KRScene &scene, std::string name);
|
||||
|
||||
virtual ~KRSprite();
|
||||
virtual std::string getElementName();
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
|
||||
void setSpriteTexture(std::string sprite_texture);
|
||||
void setSpriteSize(float sprite_size);
|
||||
|
||||
virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
|
||||
virtual KRAABB getBounds();
|
||||
|
||||
protected:
|
||||
|
||||
std::string m_spriteTexture;
|
||||
KRTexture *m_pSpriteTexture;
|
||||
float m_spriteSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user