summaryrefslogtreecommitdiffstats
path: root/src/graphics
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-29 15:09:53 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-29 15:09:53 +0200
commit7c5a3514dd6e907866bddcbb09b4d9cbd958dd8e (patch)
tree00aaece75d43bd35a3997bf4eacdfd103d29d5c7 /src/graphics
parent72c0188ec37c3783133baf6960d72cb3c9d12a6c (diff)
downloadcolobot-7c5a3514dd6e907866bddcbb09b4d9cbd958dd8e.tar.gz
colobot-7c5a3514dd6e907866bddcbb09b4d9cbd958dd8e.tar.bz2
colobot-7c5a3514dd6e907866bddcbb09b4d9cbd958dd8e.zip
Video mode changing
- added video mode querying & changing - added joystick querying & changing - cleaned up CApplication interface
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/core/device.h10
-rw-r--r--src/graphics/core/texture.h10
-rw-r--r--src/graphics/engine/engine.cpp20
-rw-r--r--src/graphics/engine/engine.h21
-rw-r--r--src/graphics/opengl/gldevice.cpp44
-rw-r--r--src/graphics/opengl/gldevice.h6
6 files changed, 82 insertions, 29 deletions
diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h
index ae612b7..1f6cacf 100644
--- a/src/graphics/core/device.h
+++ b/src/graphics/core/device.h
@@ -25,6 +25,7 @@
#include "graphics/core/material.h"
#include "graphics/core/texture.h"
#include "graphics/core/vertex.h"
+#include "math/intsize.h"
#include "math/matrix.h"
#include <string>
@@ -43,10 +44,8 @@ namespace Gfx {
*/
struct DeviceConfig
{
- //! Screen width
- int width;
- //! Screen height
- int height;
+ //! Screen size
+ Math::IntSize size;
//! Bits per pixel
int bpp;
//! Full screen
@@ -64,8 +63,7 @@ struct DeviceConfig
//! Loads the default values
inline void LoadDefault()
{
- width = 800;
- height = 600;
+ size = Math::IntSize(800, 600);
bpp = 32;
fullScreen = false;
resizeable = false;
diff --git a/src/graphics/core/texture.h b/src/graphics/core/texture.h
index 787c2bf..8d6b082 100644
--- a/src/graphics/core/texture.h
+++ b/src/graphics/core/texture.h
@@ -18,6 +18,9 @@
#pragma once
+#include "math/intsize.h"
+
+
namespace Gfx {
/**
@@ -190,10 +193,8 @@ struct Texture
bool valid;
//! ID of the texture in graphics engine
unsigned int id;
- //! Width of texture
- int width;
- //! Height of texture
- int height;
+ //! Size of texture
+ Math::IntSize size;
//! Whether the texture has alpha channel
bool alpha;
@@ -201,7 +202,6 @@ struct Texture
{
valid = false;
id = 0;
- width = height = 0;
alpha = false;
}
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 0914f9e..e544ee3 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -62,9 +62,6 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_sound = NULL;
m_terrain = NULL;
- m_dim.x = 640;
- m_dim.y = 480;
- m_lastDim = m_dim;
m_focus = 0.75f;
m_baseTime = 0;
m_lastTime = 0;
@@ -272,6 +269,12 @@ bool Gfx::CEngine::AfterDeviceSetInit()
return true;
}
+void Gfx::CEngine::ResetAfterDeviceChanged()
+{
+ // TODO
+}
+
+
Gfx::Texture Gfx::CEngine::CreateTexture(const std::string &texName, const Gfx::TextureCreateParams &params)
{
CImage img;
@@ -727,3 +730,14 @@ void Gfx::CEngine::AddStatisticTriangle(int count)
{
m_statisticTriangle += count;
}
+
+void Gfx::CEngine::SetShowStat(bool show)
+{
+ m_showStats = show;
+}
+
+bool Gfx::CEngine::GetShowStat()
+{
+ return m_showStats;
+}
+
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index 1348cdd..25c5e5d 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -26,6 +26,7 @@
#include "graphics/core/texture.h"
#include "graphics/core/vertex.h"
#include "math/intpoint.h"
+#include "math/intsize.h"
#include "math/matrix.h"
#include "math/point.h"
#include "math/vector.h"
@@ -513,21 +514,33 @@ public:
CEngine(CInstanceManager *iMan, CApplication *app);
~CEngine();
+ //! Returns whether the device was initialized
bool GetWasInit();
+ //! Returns the last error encountered
std::string GetError();
+ //! Performs the first initialization, before a device was set
bool Create();
+ //! Frees all resources before exit
void Destroy();
+ //! Sets the device to be used
void SetDevice(Gfx::CDevice *device);
+ //! Returns the current device
Gfx::CDevice* GetDevice();
+ //! Performs initialization after a device was created and set
bool AfterDeviceSetInit();
+ //! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
+ void ResetAfterDeviceChanged();
+
void SetTerrain(Gfx::CTerrain* terrain);
+ //! Processes incoming event
bool ProcessEvent(const Event &event);
+ //! Renders a single frame
bool Render();
@@ -859,6 +872,9 @@ protected:
bool m_wasInit;
std::string m_error;
+ //! Whether to show stats (FPS, etc)
+ bool m_showStats;
+
int m_blackSrcBlend[2];
int m_blackDestBlend[2];
int m_whiteSrcBlend[2];
@@ -887,8 +903,9 @@ protected:
bool m_render;
bool m_movieLock;
- Math::IntPoint m_dim;
- Math::IntPoint m_lastDim;
+ //! Current size of window
+ Math::IntSize m_size;
+ Math::IntSize m_lastSize;
std::vector<Gfx::EngineObjLevel1> m_objectTree;
std::vector<Gfx::EngineObject> m_objects;
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index bfe7fd7..1fd6a18 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -61,8 +61,9 @@ void Gfx::GLDeviceConfig::LoadDefault()
-Gfx::CGLDevice::CGLDevice()
+Gfx::CGLDevice::CGLDevice(const Gfx::GLDeviceConfig &config)
{
+ m_config = config;
m_wasInit = false;
m_lighting = false;
m_texturing = false;
@@ -86,18 +87,24 @@ std::string Gfx::CGLDevice::GetError()
bool Gfx::CGLDevice::Create()
{
#if defined(USE_GLEW)
- if (glewInit() != GLEW_OK)
- {
- m_error = "GLEW initialization failed";
- return false;
- }
+ static bool glewInited = false;
- if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) || (! GLEW_EXT_secondary_color) )
+ if (!glewInited)
{
- m_error = "GLEW reports required extensions not supported";
- return false;
- }
+ glewInited = true;
+
+ if (glewInit() != GLEW_OK)
+ {
+ m_error = "GLEW initialization failed";
+ return false;
+ }
+ if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) || (! GLEW_EXT_secondary_color) )
+ {
+ m_error = "GLEW reports required extensions not supported";
+ return false;
+ }
+ }
#endif
/* NOTE: when not using GLEW, extension testing is not performed, as it is assumed that
@@ -123,6 +130,8 @@ bool Gfx::CGLDevice::Create()
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
+ glViewport(0, 0, m_config.size.w, m_config.size.h);
+
m_lights = std::vector<Gfx::Light>(GL_MAX_LIGHTS, Gfx::Light());
m_lightsEnabled = std::vector<bool> (GL_MAX_LIGHTS, false);
@@ -153,6 +162,17 @@ void Gfx::CGLDevice::Destroy()
m_wasInit = false;
}
+void Gfx::CGLDevice::ConfigChanged(const Gfx::GLDeviceConfig& newConfig)
+{
+ m_config = newConfig;
+
+ // Reset state
+ m_lighting = false;
+ m_texturing = false;
+ Destroy();
+ Create();
+}
+
void Gfx::CGLDevice::BeginScene()
{
Clear();
@@ -375,8 +395,8 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCrea
}
result.valid = true;
- result.width = data->surface->w;
- result.height = data->surface->h;
+ result.size.w = data->surface->w;
+ result.size.h = data->surface->h;
// Use & enable 1st texture stage
glActiveTexture(GL_TEXTURE0);
diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h
index 313ea02..1864000 100644
--- a/src/graphics/opengl/gldevice.h
+++ b/src/graphics/opengl/gldevice.h
@@ -70,7 +70,7 @@ struct GLDevicePrivate;
class CGLDevice : public Gfx::CDevice
{
public:
- CGLDevice();
+ CGLDevice(const Gfx::GLDeviceConfig &config);
virtual ~CGLDevice();
virtual bool GetWasInit();
@@ -79,6 +79,8 @@ public:
virtual bool Create();
virtual void Destroy();
+ void ConfigChanged(const Gfx::GLDeviceConfig &newConfig);
+
virtual void BeginScene();
virtual void EndScene();
@@ -159,6 +161,8 @@ private:
void UpdateLightPosition(int index);
private:
+ //! Current config
+ Gfx::GLDeviceConfig m_config;
//! Was initialized?
bool m_wasInit;
//! Last encountered error