Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/camera.cc18
-rw-r--r--src/render/render.cc57
-rw-r--r--src/render/render.h8
-rw-r--r--src/render/textures.cc67
-rw-r--r--src/render/textures.h11
5 files changed, 116 insertions, 45 deletions
diff --git a/src/render/camera.cc b/src/render/camera.cc
index e708b71..53d27f7 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -138,19 +138,22 @@ void Camera::view_next()
case Free:
// switch camera to Track mode
set_mode(Track);
- core::application()->notify_message(std::string("view: track"));
+ con_print << "view: track" << std::endl;
+ //core::application()->notify_message(core::Message::Info, std::string("view: track"));
break;
case Track:
// switch camera to Cockpit mode
set_mode(Cockpit);
- core::application()->notify_message(std::string("view: cockpit"));
+ con_print << "view: cockpit" << std::endl;
+ //core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
break;
case Cockpit:
// switch camera to Free mode
set_mode(Free);
- core::application()->notify_message(std::string("view: free"));
+ con_print << "view: free" << std::endl;
+ //core::application()->notify_message(core::Message::Info, std::string("view: free"));
break;
default:
@@ -170,19 +173,22 @@ void Camera::view_previous()
case Cockpit:
// switch camera to Track mode
set_mode(Track);
- core::application()->notify_message(std::string("view: track"));
+ con_print << "view: track" << std::endl;
+ //core::application()->notify_message(std::string("view: track"));
break;
case Free:
// switch camera to Cockpit mode
set_mode(Cockpit);
- core::application()->notify_message(std::string("view: cockpit"));
+ con_print << "view: cockpit" << std::endl;
+ //core::application()->notify_message(std::string("view: cockpit"));
break;
case Track:
// switch camera to Free mode
set_mode(Free);
- core::application()->notify_message(std::string("view: free"));
+ con_print << "view: free" << std::endl;
+ //core::application()->notify_message(std::string("view: free"));
break;
default:
diff --git a/src/render/render.cc b/src/render/render.cc
index e91be23..8fce251 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -22,8 +22,6 @@
namespace render {
-GLuint textures[32];
-
core::Cvar *r_arraysize = 0;
core::Cvar *r_bbox = 0;
core::Cvar *r_grid = 0;
@@ -32,31 +30,11 @@ core::Cvar *r_sky = 0;
core::Cvar *r_wireframe = 0;
using model::VertexArray;
-
VertexArray *vertexarray = 0;
-bool texture(const char *filename, size_t id)
+void func_list_textures(std::string const &args)
{
- Image *image = TGA::load(filename);
- if (!image)
- return false;
-
- glGenTextures(1, &textures[id]);
- glBindTexture(GL_TEXTURE_2D, textures[id]);
-
- int texture_type;
- if (image->channels() == 4)
- texture_type = GL_RGBA;
- else
- texture_type = GL_RGB;
-
- gluBuild2DMipmaps(GL_TEXTURE_2D, image->channels(),
- image->width(), image->height(), texture_type, GL_UNSIGNED_BYTE, image->data());
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
-
- return true;
+ Textures::list();
}
void init()
@@ -101,12 +79,13 @@ void init()
Text::init();
Dust::init();
+
+ core::Func *func = core::Func::add("list_textures", func_list_textures);
+ func->set_info("list loaded textures");
}
-void shutdown()
+void clear()
{
- con_print << "^BShutting down renderer..." << std::endl;
-
// clear zone sky textures
for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
core::Zone *zone = (*it).second;
@@ -132,6 +111,30 @@ void shutdown()
// clear vertex array
delete vertexarray;
vertexarray = 0;
+}
+
+void unload()
+{
+ clear();
+
+ Textures::shutdown();
+ Textures::init();
+ size_t mb = (size_t) r_arraysize->value();
+ if (mb < 4 * sizeof(float))
+ mb = 4 * sizeof(float);
+ if (mb > 256)
+ mb = 256;
+ (*r_arraysize) = (float) mb;
+ vertexarray = new VertexArray(mb);
+
+}
+void shutdown()
+{
+ con_print << "^BShutting down renderer..." << std::endl;
+
+ core::Func::remove("list_textures");
+
+ clear();
Text::shutdown();
diff --git a/src/render/render.h b/src/render/render.h
index 2a8952e..5d8d12f 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -12,8 +12,13 @@
#include "render/camera.h"
#include "render/draw.h"
+#include "render/dust.h"
#include "render/gl.h"
+#include "render/jpgfile.h"
+#include "render/pngfile.h"
+#include "render/image.h"
#include "render/text.h"
+#include "render/textures.h"
#include "render/tga.h"
namespace render {
@@ -24,6 +29,9 @@ namespace render {
/// shutdown the render subsystem
void shutdown();
+ /// unload render data
+ void unload();
+
extern core::Cvar *r_arraysize;
extern core::Cvar *r_bbox;
extern core::Cvar *r_grid;
diff --git a/src/render/textures.cc b/src/render/textures.cc
index a041c32..b6b7f05 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -19,14 +19,18 @@ namespace render
{
std::map<std::string, size_t> Textures::registry;
-size_t Textures::index = 0;
GLuint Textures::textures[MAXTEXTURES];
void Textures::init()
{
- clear();
con_print << "^BLoading textures..." << std::endl;
+ if (registry.size()) {
+ clear();
+ } else {
+ memset(textures,0, sizeof(textures));
+ }
+
// "no texture" bitmap
load("textures/common/notex");
@@ -51,14 +55,54 @@ void Textures::shutdown()
clear();
}
+void Textures::list()
+{
+ for (iterator it = registry.begin(); it != registry.end(); it++) {
+ con_print << " " << (*it).first << " " << (*it).second << std::endl;
+ }
+ con_print << registry.size() << " loaded textures" << std::endl;
+}
+
void Textures::clear()
{
- if (index)
- glDeleteTextures(index, textures);
+ for (size_t i=0; i < MAXTEXTURES; i++) {
+ if (textures[i]) {
+ glDeleteTextures(1, &textures[i]);
+ }
+ }
registry.clear();
memset(textures,0, sizeof(textures));
- index = 0;
+}
+
+void Textures::unload(std::string name)
+{
+ iterator it = registry.find(name);
+ if (it != registry.end()) {
+ con_debug << " unloading " << (*it).first << std::endl;
+ size_t id = (*it).second;
+ if (textures[id]) {
+ glDeleteTextures(1, &textures[id]);
+ }
+ registry.erase(it);
+
+ }
+}
+
+void Textures::unload(size_t id)
+{
+ // find in map
+ for (iterator it = registry.begin(); it != registry.end(); it++) {
+ if ((*it).second == id) {
+ con_debug << " unloading " << (*it).first << std::endl;
+ size_t id = (*it).second;
+ if (textures[id]) {
+ glDeleteTextures(1, &textures[id]);
+ }
+ registry.erase(it);
+ break;
+ }
+ }
}
size_t Textures::load(std::string name, bool filter)
@@ -68,7 +112,12 @@ size_t Textures::load(std::string name, bool filter)
if (it != registry.end())
return (*it).second;
- if (index == MAXTEXTURES) {
+ // find first available texture
+ size_t id = 0;
+ while ((id < MAXTEXTURES) && (textures[id])) {
+ id++;
+ }
+ if (id == MAXTEXTURES) {
con_error << "Texture limit " << MAXTEXTURES << " exceeded!" << std::endl;
registry[name] = 0;
return 0;
@@ -105,8 +154,6 @@ size_t Textures::load(std::string name, bool filter)
return 0;
}
- size_t id = index;
-
glGenTextures(1, &textures[id]);
glBindTexture(GL_TEXTURE_2D, textures[id]);
@@ -123,7 +170,6 @@ size_t Textures::load(std::string name, bool filter)
// add to the registry
registry[name] = id;
- index++;
// delete image data
delete image;
@@ -157,7 +203,7 @@ size_t Textures::bind(std::string name, bool filter)
size_t Textures::bind(size_t texture, bool filter)
{
size_t id = texture;
- if (texture >= index)
+ if (!textures[id])
id = 0;
glBindTexture(GL_TEXTURE_2D, textures[id]);
@@ -175,4 +221,5 @@ void Textures::set_filter(bool filter)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
}
+
}
diff --git a/src/render/textures.h b/src/render/textures.h
index 43e312d..aa47bfa 100644
--- a/src/render/textures.h
+++ b/src/render/textures.h
@@ -43,15 +43,22 @@ public:
/// find the texture index for a given name
static size_t find(std::string name);
+ /// unload a texture
+ static void unload(size_t id);
+
+ /// unload a texture
+ static void unload(std::string name);
+
+ /// list loaded textures
+ static void list();
+
private:
static void clear();
-
static void set_filter(bool filter);
typedef std::map<std::string, size_t>::iterator iterator;
static std::map<std::string, size_t> registry;
- static size_t index;
static GLuint textures[MAXTEXTURES];
};