mirror of
https://github.com/glest/glest-source.git
synced 2025-08-18 14:11:15 +02:00
- added support for showing projectile particles in the g3d viewer
This commit is contained in:
68
source/shared_lib/include/graphics/graphics_interface.h
Normal file
68
source/shared_lib/include/graphics/graphics_interface.h
Normal file
@@ -0,0 +1,68 @@
|
||||
// ==============================================================
|
||||
// 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_GRAPHICSINTERFACE_H_
|
||||
#define _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class GraphicsFactory;
|
||||
class Context;
|
||||
class Texture2D;
|
||||
class Model;
|
||||
|
||||
enum ResourceScope{
|
||||
rsGlobal,
|
||||
rsMenu,
|
||||
rsGame,
|
||||
|
||||
rsCount
|
||||
};
|
||||
|
||||
class RendererInterface {
|
||||
public:
|
||||
virtual Texture2D *newTexture2D(ResourceScope rs) = 0;
|
||||
virtual Model *newModel(ResourceScope rs) = 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsInterface
|
||||
//
|
||||
/// Interface for the graphic engine
|
||||
// =====================================================
|
||||
|
||||
class GraphicsInterface{
|
||||
private:
|
||||
GraphicsFactory *graphicsFactory;
|
||||
Context *currentContext;
|
||||
|
||||
private:
|
||||
friend class TextureManager;
|
||||
friend class FontManager;
|
||||
|
||||
private:
|
||||
GraphicsInterface();
|
||||
GraphicsInterface(GraphicsInterface &);
|
||||
void operator=(GraphicsInterface &);
|
||||
|
||||
public:
|
||||
static GraphicsInterface &getInstance();
|
||||
|
||||
void setFactory(GraphicsFactory *graphicsFactory);
|
||||
void setCurrentContext(Context *context);
|
||||
|
||||
Context *getCurrentContext() const {return currentContext;}
|
||||
GraphicsFactory *getFactory() const {return graphicsFactory;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
53
source/shared_lib/include/graphics/model_manager.h
Normal file
53
source/shared_lib/include/graphics/model_manager.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// ==============================================================
|
||||
// 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_MODELMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_MODELMANAGER_H_
|
||||
|
||||
#include "model.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class TextureManager;
|
||||
|
||||
// =====================================================
|
||||
// class ModelManager
|
||||
// =====================================================
|
||||
|
||||
class ModelManager{
|
||||
protected:
|
||||
typedef vector<Model*> ModelContainer;
|
||||
|
||||
protected:
|
||||
ModelContainer models;
|
||||
TextureManager *textureManager;
|
||||
|
||||
public:
|
||||
ModelManager();
|
||||
virtual ~ModelManager();
|
||||
|
||||
Model *newModel();
|
||||
|
||||
void init();
|
||||
void end();
|
||||
void endModel(Model *model,bool mustExistInList=false);
|
||||
void endLastModel(bool mustExistInList=false);
|
||||
|
||||
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -44,7 +44,8 @@ public:
|
||||
void setFilter(Texture::Filter textureFilter);
|
||||
void setMaxAnisotropy(int maxAnisotropy);
|
||||
void initTexture(Texture *texture);
|
||||
void endTexture(Texture **texture);
|
||||
void endTexture(Texture *texture,bool mustExistInList=false);
|
||||
void endLastTexture(bool mustExistInList=false);
|
||||
void reinitTextures();
|
||||
|
||||
Texture *getTexture(const string &path);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
|
||||
// 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
|
||||
@@ -181,7 +181,7 @@ void Texture1DGl::end(){
|
||||
void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
||||
assertGl();
|
||||
|
||||
if(!inited){
|
||||
if(!inited) {
|
||||
|
||||
//params
|
||||
GLint wrap= toWrapModeGl(wrapMode);
|
||||
@@ -219,7 +219,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
||||
if(error!=0){
|
||||
//throw runtime_error("Error building texture 2D mipmaps");
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d",error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH());
|
||||
sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d",error,(pixmap.getPath() != "" ? pixmap.getPath().c_str() : this->path.c_str()),pixmap.getW(),pixmap.getH());
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
}
|
||||
|
98
source/shared_lib/sources/graphics/model_manager.cpp
Normal file
98
source/shared_lib/sources/graphics/model_manager.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
// ==============================================================
|
||||
// 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
|
||||
// ==============================================================
|
||||
|
||||
#include "model_manager.h"
|
||||
|
||||
#include "graphics_interface.h"
|
||||
#include "graphics_factory.h"
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class ModelManager
|
||||
// =====================================================
|
||||
|
||||
ModelManager::ModelManager(){
|
||||
textureManager= NULL;
|
||||
}
|
||||
|
||||
ModelManager::~ModelManager(){
|
||||
end();
|
||||
}
|
||||
|
||||
Model *ModelManager::newModel(){
|
||||
Model *model= GraphicsInterface::getInstance().getFactory()->newModel();
|
||||
model->setTextureManager(textureManager);
|
||||
models.push_back(model);
|
||||
return model;
|
||||
}
|
||||
|
||||
void ModelManager::init(){
|
||||
for(size_t i=0; i<models.size(); ++i){
|
||||
if(models[i] != NULL) {
|
||||
models[i]->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModelManager::end(){
|
||||
for(size_t i=0; i<models.size(); ++i){
|
||||
if(models[i] != NULL) {
|
||||
models[i]->end();
|
||||
delete models[i];
|
||||
}
|
||||
}
|
||||
models.clear();
|
||||
}
|
||||
|
||||
void ModelManager::endModel(Model *model,bool mustExistInList) {
|
||||
if(model != NULL) {
|
||||
bool found = false;
|
||||
for(int idx = 0; idx < models.size(); idx++) {
|
||||
Model *curModel = models[idx];
|
||||
if(curModel == model) {
|
||||
found = true;
|
||||
models.erase(models.begin() + idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(found == false && mustExistInList == true) {
|
||||
throw std::runtime_error("found == false in endModel");
|
||||
}
|
||||
|
||||
model->end();
|
||||
delete model;
|
||||
}
|
||||
}
|
||||
|
||||
void ModelManager::endLastModel(bool mustExistInList) {
|
||||
bool found = false;
|
||||
if(models.size() > 0) {
|
||||
found = true;
|
||||
int index = models.size()-1;
|
||||
Model *curModel = models[index];
|
||||
models.erase(models.begin() + index);
|
||||
|
||||
curModel->end();
|
||||
delete curModel;
|
||||
}
|
||||
if(found == false && mustExistInList == true) {
|
||||
throw std::runtime_error("found == false in endLastModel");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}//end namespace
|
@@ -357,8 +357,6 @@ Pixmap1D::~Pixmap1D(){
|
||||
}
|
||||
|
||||
void Pixmap1D::load(const string &path){
|
||||
this->path = path;
|
||||
|
||||
string extension= path.substr(path.find_last_of('.')+1);
|
||||
if(extension=="bmp"){
|
||||
loadBmp(path);
|
||||
@@ -369,6 +367,7 @@ void Pixmap1D::load(const string &path){
|
||||
else{
|
||||
throw runtime_error("Unknown pixmap extension: "+extension);
|
||||
}
|
||||
this->path = path;
|
||||
}
|
||||
|
||||
void Pixmap1D::loadBmp(const string &path){
|
||||
@@ -477,8 +476,8 @@ Pixmap2D* Pixmap2D::loadPath(const string& path) {
|
||||
}
|
||||
|
||||
void Pixmap2D::load(const string &path){
|
||||
this->path = path;
|
||||
FileReader<Pixmap2D>::readPath(path,this);
|
||||
this->path = path;
|
||||
}
|
||||
|
||||
|
||||
@@ -781,8 +780,6 @@ Pixmap3D::~Pixmap3D(){
|
||||
}
|
||||
|
||||
void Pixmap3D::loadSlice(const string &path, int slice){
|
||||
this->path = path;
|
||||
|
||||
string extension= path.substr(path.find_last_of('.')+1);
|
||||
if(extension=="bmp"){
|
||||
loadSliceBmp(path, slice);
|
||||
@@ -793,6 +790,7 @@ void Pixmap3D::loadSlice(const string &path, int slice){
|
||||
else{
|
||||
throw runtime_error("Unknown pixmap extension: "+extension);
|
||||
}
|
||||
this->path = path;
|
||||
}
|
||||
|
||||
void Pixmap3D::loadSliceBmp(const string &path, int slice){
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
|
||||
// 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
|
||||
@@ -46,6 +46,7 @@ void Texture1D::load(const string &path){
|
||||
pixmap.init(defaultComponents);
|
||||
}
|
||||
pixmap.load(path);
|
||||
this->path= path;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
@@ -60,6 +61,7 @@ void Texture2D::load(const string &path){
|
||||
pixmap.init(defaultComponents);
|
||||
}
|
||||
pixmap.load(path);
|
||||
this->path= path;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
@@ -74,6 +76,7 @@ void Texture3D::loadSlice(const string &path, int slice){
|
||||
pixmap.init(defaultComponents);
|
||||
}
|
||||
pixmap.loadSlice(path, slice);
|
||||
this->path= path;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
@@ -88,6 +91,7 @@ void TextureCube::loadFace(const string &path, int face){
|
||||
pixmap.init(defaultComponents);
|
||||
}
|
||||
pixmap.loadFace(path, face);
|
||||
this->path= path;
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
@@ -40,11 +40,38 @@ void TextureManager::initTexture(Texture *texture) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextureManager::endTexture(Texture **texture) {
|
||||
if(texture != NULL && *texture != NULL) {
|
||||
(*texture)->end();
|
||||
delete (*texture);
|
||||
*texture = NULL;
|
||||
void TextureManager::endTexture(Texture *texture,bool mustExistInList) {
|
||||
if(texture != NULL) {
|
||||
bool found = false;
|
||||
for(int idx = 0; idx < textures.size(); idx++) {
|
||||
Texture *curTexture = textures[idx];
|
||||
if(curTexture == texture) {
|
||||
found = true;
|
||||
textures.erase(textures.begin() + idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found == false && mustExistInList == true) {
|
||||
throw std::runtime_error("found == false in endTexture");
|
||||
}
|
||||
texture->end();
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
void TextureManager::endLastTexture(bool mustExistInList) {
|
||||
bool found = false;
|
||||
if(textures.size() > 0) {
|
||||
found = true;
|
||||
int index = textures.size()-1;
|
||||
Texture *curTexture = textures[index];
|
||||
textures.erase(textures.begin() + index);
|
||||
|
||||
curTexture->end();
|
||||
delete curTexture;
|
||||
}
|
||||
if(found == false && mustExistInList == true) {
|
||||
throw std::runtime_error("found == false in endLastTexture");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +90,10 @@ void TextureManager::init(bool forceInit) {
|
||||
|
||||
void TextureManager::end(){
|
||||
for(int i=0; i<textures.size(); ++i){
|
||||
textures[i]->end();
|
||||
delete textures[i];
|
||||
if(textures[i] != NULL) {
|
||||
textures[i]->end();
|
||||
delete textures[i];
|
||||
}
|
||||
}
|
||||
textures.clear();
|
||||
}
|
||||
|
Reference in New Issue
Block a user