From a68ae2fdfb7f22793d3cca04e9f03299cd28e3e2 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 10 May 2010 19:35:56 +0000 Subject: [PATCH] fixed teamcolor bug from last code checkins dealing with threaded interpolation --- source/glest_game/graphics/renderer.cpp | 25 ++++---- source/glest_game/graphics/renderer.h | 27 ++++++++- .../include/graphics/model_renderer.h | 58 +++++++++++++++++++ 3 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 source/shared_lib/include/graphics/model_renderer.h diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index c24a0b838..de2f4e518 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -41,15 +41,6 @@ namespace Glest { namespace Game{ // class MeshCallbackTeamColor // ===================================================== -class MeshCallbackTeamColor: public MeshCallback{ -private: - const Texture *teamTexture; - -public: - void setTeamTexture(const Texture *teamTexture) {this->teamTexture= teamTexture;} - virtual void execute(const Mesh *mesh); -}; - void MeshCallbackTeamColor::execute(const Mesh *mesh){ //team color @@ -1687,7 +1678,7 @@ void Renderer::renderUnits(){ std::vector vctEntity; for(int i=0; igetFactionCount(); ++i){ - meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture()); +// meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture()); for(int j=0; jgetFaction(i)->getUnitCount(); ++j){ unit= world->getFaction(i)->getUnit(j); if(world->toRenderUnit(unit, visibleQuad)) { @@ -1728,7 +1719,7 @@ void Renderer::renderUnits(){ unit->setVisible(true); */ - vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit)); + vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,world->getFaction(i)->getTexture())); } else { @@ -1738,7 +1729,7 @@ void Renderer::renderUnits(){ } modelRenderer->begin(true, true, true, &meshCallbackTeamColor); - renderUnitList(vctEntity); + renderUnitList(vctEntity,&meshCallbackTeamColor); modelRenderer->end(); //restore @@ -1749,7 +1740,7 @@ void Renderer::renderUnits(){ assertGl(); } -void Renderer::renderUnitList(std::vector &vctEntity) { +void Renderer::renderUnitList(std::vector &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] vctEntity.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,vctEntity.size()); // Run interpolation threaded if the thread is created @@ -1778,7 +1769,7 @@ void Renderer::renderUnitList(std::vector &vctEntity) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] idx = %d\n",__FILE__,__FUNCTION__,__LINE__,idx); - renderUnit(entity); + renderUnit(entity,meshCallbackTeamColor); entityPendingLookup[idx] = true; renderedUnitCount++; @@ -1796,9 +1787,13 @@ void Renderer::renderUnitList(std::vector &vctEntity) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] vctEntity.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,vctEntity.size()); } -void Renderer::renderUnit(RenderEntity &entity) { +void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor) { Unit *unit = entity.unit; if(unit != NULL) { + if(meshCallbackTeamColor != NULL) { + meshCallbackTeamColor->setTeamTexture(entity.teamTexture); + } + glMatrixMode(GL_MODELVIEW); glPushMatrix(); diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 603b6b667..7842b73cb 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -28,6 +28,8 @@ #include "camera.h" #include #include "base_thread.h" +#include "model_renderer.h" +#include "model.h" namespace Glest{ namespace Game{ @@ -50,9 +52,24 @@ using Shared::Graphics::Model; using Shared::Graphics::ParticleSystem; using Shared::Graphics::Pixmap2D; using Shared::Graphics::Camera; +using Shared::Graphics::MeshCallback; +using Shared::Graphics::Mesh; using namespace Shared::PlatformCommon; +// ===================================================== +// class MeshCallbackTeamColor +// ===================================================== + +class MeshCallbackTeamColor: public MeshCallback{ +private: + const Texture *teamTexture; + +public: + void setTeamTexture(const Texture *teamTexture) {this->teamTexture= teamTexture;} + virtual void execute(const Mesh *mesh); +}; + //non shared classes class Config; class Game; @@ -102,6 +119,7 @@ protected: this->o = obj.o; this->mapPos = obj.mapPos; this->unit = obj.unit; + this->teamTexture = obj.teamTexture;; } public: @@ -110,13 +128,15 @@ public: this->type = retObject; this->o = NULL; this->unit = NULL; + this->teamTexture = NULL; setState(resNone); } - RenderEntity(RenderEntityType type,Object *o, Vec2i mapPos, Unit *unit) { + RenderEntity(RenderEntityType type,Object *o, Vec2i mapPos, Unit *unit,const Texture2D *teamTexture=NULL) { this->type = type; this->o = o; this->mapPos = mapPos; this->unit = unit; + this->teamTexture = teamTexture; setState(resNone); } RenderEntity(const RenderEntity &obj) { @@ -131,6 +151,7 @@ public: Object *o; Vec2i mapPos; Unit *unit; + const Texture2D *teamTexture; RenderEntityState getState() { RenderEntityState result; @@ -359,8 +380,8 @@ public: void renderWater(); void renderUnits(); void prepareUnitForRender(RenderEntity &entity); - void renderUnitList(std::vector &vctEntity); - void renderUnit(RenderEntity &entity); + void renderUnitList(std::vector &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor); + void renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor); void renderSelectionEffects(); void renderWaterEffects(); diff --git a/source/shared_lib/include/graphics/model_renderer.h b/source/shared_lib/include/graphics/model_renderer.h new file mode 100644 index 000000000..a9c3d4561 --- /dev/null +++ b/source/shared_lib/include/graphics/model_renderer.h @@ -0,0 +1,58 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + + +#ifndef _SHARED_GRAPHICS_MODELRENDERER_H_ +#define _SHARED_GRAPHICS_MODELRENDERER_H_ + +#include "model.h" + +namespace Shared{ namespace Graphics{ + +class Texture; + +// ===================================================== +// class MeshCallback +// +/// This gets called before rendering mesh +// ===================================================== + +class MeshCallback{ +public: + virtual ~MeshCallback(){}; + virtual void execute(const Mesh *mesh)= 0; +}; + +// ===================================================== +// class ModelRenderer +// ===================================================== + +class ModelRenderer{ +protected: + bool renderNormals; + bool renderTextures; + bool renderColors; + MeshCallback *meshCallback; + +public: + ModelRenderer() {meshCallback= NULL;} + + virtual ~ModelRenderer(){}; + + virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback= NULL)=0; + virtual void end()=0; + virtual void render(const Model *model)=0; + virtual void renderNormalsOnly(const Model *model)=0; +}; + +}}//end namespace + +#endif