From 9bd4ec03b272e7925b11c3efc2bd8460894ea589 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 1 Jul 2012 01:37:30 +0200 Subject: CDevice interface and stub of implementation - added CDevice abstract interface - began implementation of CGLDevice - added stub for Texture struct - created CGLDeviceConfig - changed particule -> particle & other minor changes --- CMakeLists.txt | 2 + src/app/app.cpp | 44 +++++---- src/app/app.h | 3 - src/graphics/common/device.cpp | 29 +++++- src/graphics/common/device.h | 134 ++++++++++++++++++++++++++- src/graphics/common/engine.cpp | 13 +++ src/graphics/common/engine.h | 76 +++++++++------- src/graphics/common/particle.h | 104 ++++++++++----------- src/graphics/common/text.h | 4 +- src/graphics/common/texture.h | 28 ++++++ src/graphics/common/water.h | 4 +- src/graphics/opengl/gldevice.cpp | 192 ++++++++++++++++++++++++++++++++++++++- src/graphics/opengl/gldevice.h | 94 ++++++++++++++++++- 13 files changed, 608 insertions(+), 119 deletions(-) create mode 100644 src/graphics/common/texture.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d0fc02e..3a50bcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ find_package(OpenGL REQUIRED) find_package(SDL REQUIRED) find_package(SDL_image REQUIRED) +# TODO: check for SDL version. Should be >= 1.2.10 + # Build with debugging symbols set(CMAKE_BUILD_TYPE debug) diff --git a/src/app/app.cpp b/src/app/app.cpp index 2be58ff..2e1948f 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -21,6 +21,7 @@ #include "app/system.h" #include "common/iman.h" +#include "graphics/opengl/gldevice.h" #include @@ -54,6 +55,8 @@ struct ApplicationPrivate int joystickIndex; //! Id of joystick timer SDL_TimerID joystickTimer; + //! Current configuration of OpenGL display device + Gfx::GLDeviceConfig deviceConfig; ApplicationPrivate() { @@ -137,18 +140,18 @@ Error CApplication::ParseArguments(int argc, char *argv[]) bool CApplication::Create() { // Temporarily -- only in windowed mode - m_deviceConfig.fullScreen = false; + m_private->deviceConfig.fullScreen = false; // Create the 3D engine. m_engine = new Gfx::CEngine(m_iMan, this); - /* TODO + // Initialize the app's custom scene stuff if (! m_engine->OneTimeSceneInit()) { SystemDialog(SDT_ERROR, "COLOBOT - Error", m_engine->RetError()); return false; - }*/ + } /* // Create the sound instance. m_sound = new CSound(m_iMan); @@ -178,7 +181,7 @@ bool CApplication::Create() Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; - if (m_deviceConfig.resizeable) + if (m_private->deviceConfig.resizeable) videoFlags |= SDL_RESIZABLE; // Use hardware surface if available @@ -191,16 +194,25 @@ bool CApplication::Create() if (videoInfo->blit_hw) videoFlags |= SDL_HWACCEL; - if (m_deviceConfig.fullScreen) + if (m_private->deviceConfig.fullScreen) videoFlags |= SDL_FULLSCREEN; - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + // Set OpenGL attributes + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, m_private->deviceConfig.redSize); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, m_private->deviceConfig.greenSize); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, m_private->deviceConfig.blueSize); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, m_private->deviceConfig.alphaSize); + + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_private->deviceConfig.depthSize); + + if (m_private->deviceConfig.doubleBuf) + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + /* If hardware acceleration specifically requested, this will force the hw accel + and fail with error if not available */ + if (m_private->deviceConfig.hardwareAccel) + SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0) { @@ -209,8 +221,8 @@ bool CApplication::Create() return false; } - m_private->surface = SDL_SetVideoMode(m_deviceConfig.width, m_deviceConfig.height, - m_deviceConfig.bpp, videoFlags); + m_private->surface = SDL_SetVideoMode(m_private->deviceConfig.width, m_private->deviceConfig.height, + m_private->deviceConfig.bpp, videoFlags); if (m_private->surface == NULL) { @@ -426,8 +438,8 @@ y: 0=down, 1=up */ Math::Point CApplication::WindowToInterfaceCoords(int x, int y) { - return Math::Point((float)x / (float)m_deviceConfig.width, - 1.0f - (float)y / (float)m_deviceConfig.height); + return Math::Point((float)x / (float)m_private->deviceConfig.width, + 1.0f - (float)y / (float)m_private->deviceConfig.height); } @@ -546,7 +558,7 @@ bool CApplication::Render() if (! result) return false; - if (m_deviceConfig.doubleBuf) + if (m_private->deviceConfig.doubleBuf) SDL_GL_SwapBuffers(); return true; diff --git a/src/app/app.h b/src/app/app.h index b2d9135..4cb6976 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -21,7 +21,6 @@ #include "common/misc.h" -#include "graphics/common/device.h" #include "graphics/common/engine.h" #include @@ -162,8 +161,6 @@ protected: ApplicationPrivate* m_private; //! Global event queue CEventQueue* m_eventQueue; - //! Current configuration of display device - Gfx::DeviceConfig m_deviceConfig; //! Graphics engine Gfx::CEngine* m_engine; //! Sound subsystem diff --git a/src/graphics/common/device.cpp b/src/graphics/common/device.cpp index 53274b3..fcd4318 100644 --- a/src/graphics/common/device.cpp +++ b/src/graphics/common/device.cpp @@ -1,14 +1,33 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +// device.cpp + + #include "graphics/common/device.h" -//! Sets the default values -Gfx::DeviceConfig::DeviceConfig() + +void Gfx::DeviceConfig::LoadDefault() { width = 800; height = 600; - bpp = 16; + bpp = 32; fullScreen = false; resizeable = false; - hardwareAccel = true; doubleBuf = true; noFrame = false; -} \ No newline at end of file +} diff --git a/src/graphics/common/device.h b/src/graphics/common/device.h index 5900570..4604e88 100644 --- a/src/graphics/common/device.h +++ b/src/graphics/common/device.h @@ -20,8 +20,22 @@ #pragma once +#include "graphics/common/color.h" +#include "graphics/common/light.h" +#include "graphics/common/material.h" +#include "graphics/common/texture.h" +#include "graphics/common/vertex.h" +#include "math/matrix.h" + + namespace Gfx { +/** + \struct DeviceConfig + \brief General config for graphics device + + These settings are common window options set by SDL. +*/ struct DeviceConfig { //! Screen width @@ -34,19 +48,131 @@ struct DeviceConfig bool fullScreen; //! Resizeable window bool resizeable; - //! Hardware acceleration - bool hardwareAccel; //! Double buffering bool doubleBuf; //! No window frame (also set with full screen) bool noFrame; - DeviceConfig(); + //! Constructor calls LoadDefault() + DeviceConfig() { LoadDefault(); } + + //! Loads the default values + void LoadDefault(); +}; + +/** + \enum TransformType + \brief Type of transformation in rendering pipeline + + Corresponds directly to DirectX's transformation types. Listed are only the used types. */ +enum TransformType +{ + TRANSFORM_WORLD, + TRANSFORM_VIEW, + TRANSFORM_PROJECTION +}; + +/** + \enum RenderState + \brief Render states that can be enabled/disabled + + Corresponds to DirectX's render states. Listed are only the used modes. + + TODO: replace with functions in CDevice */ +enum RenderState +{ + RENDER_STATE_ALPHABLENDENABLE, + RENDER_STATE_ALPHAFUNC, + RENDER_STATE_ALPHAREF, + RENDER_STATE_ALPHATESTENABLE, + RENDER_STATE_AMBIENT, + RENDER_STATE_CULLMODE, + RENDER_STATE_DESTBLEND, + RENDER_STATE_DITHERENABLE, + RENDER_STATE_FILLMODE, + RENDER_STATE_FOGCOLOR, + RENDER_STATE_FOGENABLE, + RENDER_STATE_FOGEND, + RENDER_STATE_FOGSTART, + RENDER_STATE_FOGVERTEXMODE, + RENDER_STATE_LIGHTING, + RENDER_STATE_SHADEMODE, + RENDER_STATE_SPECULARENABLE, + RENDER_STATE_SRCBLEND, + RENDER_STATE_TEXTUREFACTOR, + RENDER_STATE_WRAP, + RENDER_STATE_ZBIAS, + RENDER_STATE_ZENABLE, + RENDER_STATE_ZFUNC, + RENDER_STATE_ZWRITEENABLE +}; + +/** + \enum PrimitiveType + \brief Type of primitive to render + + Only these two types are used. */ +enum PrimitiveType +{ + PRIMITIVE_TRIANGLES, + PRIMITIVE_TRIANGLE_STRIP }; +/** + \class CDevice + \brief Abstract interface of graphics device + + It is based on DIRECT3DDEVICE class from DirectX to make it easier to port existing code. + It encapsulates the general graphics device state and provides a common interface + to graphics-specific functions which will be used throughout the program, + both in CEngine class and in UI classes. Note that it doesn't contain all functions from DirectX, + only those that were used in old code. + + */ class CDevice { - // TODO +public: + //! Initializes the device, setting the initial state + virtual void Initialize() = 0; + //! Destroys the device, releasing every acquired resource + virtual void Destroy() = 0; + + // TODO: documentation + + virtual void BeginScene() = 0; + virtual void EndScene() = 0; + + virtual void Clear() = 0; + + virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0; + virtual const Math::Matrix& GetTransform(TransformType type) = 0; + virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix) = 0; + + virtual void SetMaterial(const Gfx::Material &material) = 0; + virtual const Gfx::Material& GetMaterial() = 0; + + virtual int GetMaxLightCount() = 0; + virtual void SetLight(int index, const Gfx::Light &light) = 0; + virtual const Gfx::Light& GetLight(int index) = 0; + virtual void SetLightEnabled(int index, bool enabled) = 0; + virtual bool GetLightEnabled(int index) = 0; + + virtual int GetMaxTextureCount() = 0; + virtual const Gfx::Texture& GetTexture(int index) = 0; + virtual void SetTexture(int index, const Gfx::Texture &texture) = 0; + + // TODO: + // virtual void GetTextureStageState() = 0; + // virtual void SetTextureStageState() = 0; + + virtual void SetRenderState(Gfx::RenderState state, bool enabled) = 0; + virtual bool GetRenderState(Gfx::RenderState state) = 0; + + // TODO: + // virtual void ComputeSphereVisibility() = 0; + + virtual void DrawPrimitive(PrimitiveType, Vertex *vertices, int vertexCount) = 0; + virtual void DrawPrimitive(PrimitiveType, VertexTex2 *vertices, int vertexCount) = 0; }; }; // namespace Gfx diff --git a/src/graphics/common/engine.cpp b/src/graphics/common/engine.cpp index 3b9a89d..9906a0a 100644 --- a/src/graphics/common/engine.cpp +++ b/src/graphics/common/engine.cpp @@ -35,6 +35,17 @@ Gfx::CEngine::~CEngine() // TODO } +std::string Gfx::CEngine::RetError() +{ + return m_error; +} + +int Gfx::CEngine::OneTimeSceneInit() +{ + // TODO + return 1; +} + int Gfx::CEngine::Render() { /* Just a hello world for now */ @@ -71,3 +82,5 @@ int Gfx::CEngine::Render() return 1; } + + diff --git a/src/graphics/common/engine.h b/src/graphics/common/engine.h index 0d93ea2..df8f16b 100644 --- a/src/graphics/common/engine.h +++ b/src/graphics/common/engine.h @@ -29,10 +29,16 @@ #include "math/vector.h" +#include + + class CApplication; class CInstanceManager; class CObject; + +namespace Snd { class CSound; +}; namespace Gfx { @@ -117,46 +123,46 @@ enum ShadowType SHADOW_WORM = 1 }; -enum RenderState +enum EngineRenderState { //! Normal opaque materials - RSTATE_NORMAL = 0, + ENG_RSTATE_NORMAL = 0, //! The transparent texture (black = no) - RSTATE_TTEXTURE_BLACK = (1<<0), + ENG_RSTATE_TTEXTURE_BLACK = (1<<0), //! The transparent texture (white = no) - RSTATE_TTEXTURE_WHITE = (1<<1), + ENG_RSTATE_TTEXTURE_WHITE = (1<<1), //! The transparent diffuse color - RSTATE_TDIFFUSE = (1<<2), + ENG_RSTATE_TDIFFUSE = (1<<2), //! Texture wrap - RSTATE_WRAP = (1<<3), + ENG_RSTATE_WRAP = (1<<3), //! Texture borders with solid color - RSTATE_CLAMP = (1<<4), + ENG_RSTATE_CLAMP = (1<<4), //! Light texture (ambient max) - RSTATE_LIGHT = (1<<5), + ENG_RSTATE_LIGHT = (1<<5), //! Double black texturing - RSTATE_DUAL_BLACK = (1<<6), + ENG_RSTATE_DUAL_BLACK = (1<<6), //! Double white texturing - RSTATE_DUAL_WHITE = (1<<7), + ENG_RSTATE_DUAL_WHITE = (1<<7), //! Part 1 (no change in. MOD!) - RSTATE_PART1 = (1<<8), + ENG_RSTATE_PART1 = (1<<8), //! Part 2 - RSTATE_PART2 = (1<<9), + ENG_RSTATE_PART2 = (1<<9), //! Part 3 - RSTATE_PART3 = (1<<10), + ENG_RSTATE_PART3 = (1<<10), //! Part 4 - RSTATE_PART4 = (1<<11), + ENG_RSTATE_PART4 = (1<<11), //! Double-sided face - RSTATE_2FACE = (1<<12), + ENG_RSTATE_2FACE = (1<<12), //! Image using alpha channel - RSTATE_ALPHA = (1<<13), + ENG_RSTATE_ALPHA = (1<<13), //! Always use 2nd floor texturing - RSTATE_SECOND = (1<<14), + ENG_RSTATE_SECOND = (1<<14), //! Causes the fog - RSTATE_FOG = (1<<15), + ENG_RSTATE_FOG = (1<<15), //! The transparent color (black = no) - RSTATE_TCOLOR_BLACK = (1<<16), + ENG_RSTATE_TCOLOR_BLACK = (1<<16), //! The transparent color (white = no) - RSTATE_TCOLOR_WHITE = (1<<17) + ENG_RSTATE_TCOLOR_WHITE = (1<<17) }; @@ -289,6 +295,8 @@ public: CEngine(CInstanceManager *iMan, CApplication *app); ~CEngine(); + std::string RetError(); + void SetDevice(Gfx::CDevice *device); Gfx::CDevice* RetDevice(); @@ -439,7 +447,7 @@ public: void RetBackground(char *name, Gfx::Color &up, Gfx::Color &down, Gfx::Color &cloudUp, Gfx::Color &cloudDown, bool &full, bool &quarter); void SetFrontsizeName(char *name); void SetOverFront(bool front); - void SetOverColor(const Gfx::Color &color=Gfx::Color(), int mode=RSTATE_TCOLOR_BLACK); + void SetOverColor(const Gfx::Color &color=Gfx::Color(), int mode=ENG_RSTATE_TCOLOR_BLACK); void SetParticuleDensity(float value); float RetParticuleDensity(); @@ -584,18 +592,20 @@ protected: void DrawSprite(Math::Point pos, Math::Point dim, int icon); protected: - CInstanceManager* m_iMan; - CApplication* m_app; - Gfx::CDevice* m_device; - Gfx::CText* m_text; - Gfx::CLight* m_light; - Gfx::CParticle* m_particule; - Gfx::CWater* m_water; - Gfx::CCloud* m_cloud; - Gfx::CLightning* m_blitz; - Gfx::CPlanet* m_planet; - Gfx::CTerrain* m_terrain; - CSound* m_sound; + CInstanceManager* m_iMan; + CApplication* m_app; + Gfx::CDevice* m_device; + Gfx::CText* m_text; + Gfx::CLight* m_light; + Gfx::CParticle* m_particle; + Gfx::CWater* m_water; + Gfx::CCloud* m_cloud; + Gfx::CLightning* m_lightning; + Gfx::CPlanet* m_planet; + Gfx::CTerrain* m_terrain; + Snd::CSound* m_sound; + + std::string m_error; int m_blackSrcBlend[2]; int m_blackDestBlend[2]; diff --git a/src/graphics/common/particle.h b/src/graphics/common/particle.h index dd9f4e3..62d001d 100644 --- a/src/graphics/common/particle.h +++ b/src/graphics/common/particle.h @@ -50,7 +50,7 @@ const short SH_MAX = 3; // type == 4 -> text (white background) -enum ParticuleType +enum ParticleType { PARTIEXPLOT = 1, // technology explosion PARTIEXPLOO = 2, // organic explosion @@ -193,20 +193,20 @@ enum ParticuleType PARTITRACE19 = 159, // trace }; -enum ParticulePhase +enum ParticlePhase { PARPHSTART = 0, PARPHEND = 1, }; -struct Particule +struct Particle { char bUsed; // TRUE -> particle used char bRay; // TRUE -> ray with goal unsigned short uniqueStamp; // unique mark short sheet; // sheet (0..n) - ParticuleType type; // type PARTI* - ParticulePhase phase; // phase PARPH* + ParticleType type; // type PARTI* + ParticlePhase phase; // phase PARPH* float mass; // mass of the particle (in rebounding) float weight; // weight of the particle (for noise) float duration; // length of life @@ -233,7 +233,7 @@ struct Particule struct Track { char bUsed; // TRUE -> drag used - char bDrawParticule; + char bDrawParticle; float step; // duration of not float last; // increase last not memorized float intensity; // intensity at starting (0..1) @@ -246,7 +246,7 @@ struct Track struct WheelTrace { - ParticuleType type; // type PARTI* + ParticleType type; // type PARTI* Math::Vector pos[4]; // rectangle positions float startTime; // beginning of life }; @@ -261,16 +261,16 @@ public: void SetGLDevice(CDevice device); - void FlushParticule(); - void FlushParticule(int sheet); - int CreateParticule(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticuleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreateFrag(Math::Vector pos, Math::Vector speed, Triangle *triangle, ParticuleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreatePart(Math::Vector pos, Math::Vector speed, ParticuleType type, float duration=1.0f, float mass=0.0f, float weight=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreateRay(Math::Vector pos, Math::Vector goal, ParticuleType type, Math::Point dim, float duration=1.0f, int sheet=0); - int CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticuleType type, float duration=1.0f, float mass=0.0f, float length=10.0f, float width=1.0f); - void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, const Math::Vector &p4, ParticuleType type); - void DeleteParticule(ParticuleType type); - void DeleteParticule(int channel); + void FlushParticle(); + void FlushParticle(int sheet); + int CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); + int CreateFrag(Math::Vector pos, Math::Vector speed, Triangle *triangle, ParticleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); + int CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type, float duration=1.0f, float mass=0.0f, float weight=0.0f, float windSensitivity=1.0f, int sheet=0); + int CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, Math::Point dim, float duration=1.0f, int sheet=0); + int CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type, float duration=1.0f, float mass=0.0f, float length=10.0f, float width=1.0f); + void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, const Math::Vector &p4, ParticleType type); + void DeleteParticle(ParticleType type); + void DeleteParticle(int channel); void SetObjectLink(int channel, CObject *object); void SetObjectFather(int channel, CObject *object); void SetPosition(int channel, Math::Vector pos); @@ -279,57 +279,57 @@ public: void SetAngle(int channel, float angle); void SetIntensity(int channel, float intensity); void SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity); - void SetPhase(int channel, ParticulePhase phase, float duration); + void SetPhase(int channel, ParticlePhase phase, float duration); bool GetPosition(int channel, Math::Vector &pos); Gfx::Color RetFogColor(Math::Vector pos); void SetFrameUpdate(int sheet, bool bUpdate); - void FrameParticule(float rTime); - void DrawParticule(int sheet); + void FrameParticle(float rTime); + void DrawParticle(int sheet); bool WriteWheelTrace(char *filename, int width, int height, Math::Vector dl, Math::Vector ur); protected: void DeleteRank(int rank); bool CheckChannel(int &channel); - void DrawParticuleTriangle(int i); - void DrawParticuleNorm(int i); - void DrawParticuleFlat(int i); - void DrawParticuleFog(int i); - void DrawParticuleRay(int i); - void DrawParticuleSphere(int i); - void DrawParticuleCylinder(int i); - void DrawParticuleWheel(int i); - CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, ParticuleType type, CObject *father); - CObject* SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticuleType type, CObject *father); + void DrawParticleTriangle(int i); + void DrawParticleNorm(int i); + void DrawParticleFlat(int i); + void DrawParticleFog(int i); + void DrawParticleRay(int i); + void DrawParticleSphere(int i); + void DrawParticleCylinder(int i); + void DrawParticleWheel(int i); + CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, ParticleType type, CObject *father); + CObject* SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticleType type, CObject *father); void Play(Snd::Sound sound, Math::Vector pos, float amplitude); bool TrackMove(int i, Math::Vector pos, float progress); - void TrackDraw(int i, ParticuleType type); + void TrackDraw(int i, ParticleType type); protected: - CInstanceManager* m_iMan; - CEngine* m_engine; - CDevice* m_pDevice; - CRobotMain* m_main; - CTerrain* m_terrain; - CWater* m_water; - CSound* m_sound; + CInstanceManager* m_iMan; + CEngine* m_engine; + CDevice* m_pDevice; + CRobotMain* m_main; + CTerrain* m_terrain; + CWater* m_water; + Snd::CSound* m_sound; - Particule m_particule[MAXPARTICULE*MAXPARTITYPE]; - Gfx::Triangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0 - Track m_track[MAXTRACK]; - int m_wheelTraceTotal; - int m_wheelTraceIndex; - WheelTrace m_wheelTrace[MAXWHEELTRACE]; - int m_totalInterface[MAXPARTITYPE][SH_MAX]; - bool m_bFrameUpdate[SH_MAX]; - int m_fogTotal; - int m_fog[MAXPARTIFOG]; - int m_uniqueStamp; - int m_exploGunCounter; - float m_lastTimeGunDel; - float m_absTime; + Gfx::Particle m_particule[MAXPARTICULE*MAXPARTITYPE]; + Gfx::Triangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0 + Track m_track[MAXTRACK]; + int m_wheelTraceTotal; + int m_wheelTraceIndex; + WheelTrace m_wheelTrace[MAXWHEELTRACE]; + int m_totalInterface[MAXPARTITYPE][SH_MAX]; + bool m_bFrameUpdate[SH_MAX]; + int m_fogTotal; + int m_fog[MAXPARTIFOG]; + int m_uniqueStamp; + int m_exploGunCounter; + float m_lastTimeGunDel; + float m_absTime; }; diff --git a/src/graphics/common/text.h b/src/graphics/common/text.h index 00b73f2..f96dc61 100644 --- a/src/graphics/common/text.h +++ b/src/graphics/common/text.h @@ -73,7 +73,7 @@ public: CText(CInstanceManager *iMan, Gfx::CEngine* engine); ~CText(); - void SetGLDevice(Gfx::CDevice device); + void SetDevice(Gfx::CDevice *device); void DrawText(char *string, char *format, int len, Math::Point pos, float width, int justif, float size, float stretch, int eol); void DrawText(char *string, char *format, Math::Point pos, float width, int justif, float size, float stretch, int eol); @@ -106,7 +106,7 @@ protected: protected: CInstanceManager* m_iMan; Gfx::CEngine* m_engine; - Gfx::CDevice m_pDevice; + Gfx::CDevice* m_device; }; diff --git a/src/graphics/common/texture.h b/src/graphics/common/texture.h new file mode 100644 index 0000000..ab894db --- /dev/null +++ b/src/graphics/common/texture.h @@ -0,0 +1,28 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +// texture.h + +#pragma once + +namespace Gfx { + +struct Texture +{ + // TODO +}; + +}; // namespace Gfx diff --git a/src/graphics/common/water.h b/src/graphics/common/water.h index 5999eac..f5224a4 100644 --- a/src/graphics/common/water.h +++ b/src/graphics/common/water.h @@ -48,7 +48,7 @@ const short MAXWATVAPOR = 10; struct WaterVapor { bool bUsed; - ParticuleType type; + ParticleType type; Math::Vector pos; float delay; float time; @@ -96,7 +96,7 @@ protected: bool CreateLine(int x, int y, int len); void VaporFlush(); - bool VaporCreate(ParticuleType type, Math::Vector pos, float delay); + bool VaporCreate(ParticleType type, Math::Vector pos, float delay); void VaporFrame(int i, float rTime); protected: diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 7938e62..9ef376f 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -18,4 +18,194 @@ #include "graphics/opengl/gldevice.h" -// TODO +#include +#include + + +void Gfx::GLDeviceConfig::LoadDefault() +{ + Gfx::DeviceConfig::LoadDefault(); + + hardwareAccel = true; + + redSize = 8; + blueSize = 8; + greenSize = 8; + alphaSize = 8; + depthSize = 24; +} + +Gfx::CGLDevice::CGLDevice() +{ + m_renderState = 0; +} + + +Gfx::CGLDevice::~CGLDevice() +{ +} + +void Gfx::CGLDevice::Initialize() +{ + // TODO +} + +void Gfx::CGLDevice::Destroy() +{ + // TODO +} + +void Gfx::CGLDevice::BeginScene() +{ + // TODO +} + +void Gfx::CGLDevice::EndScene() +{ + // TODO +} + +void Gfx::CGLDevice::Clear() +{ + // TODO +} + +void Gfx::CGLDevice::SetTransform(Gfx::TransformType type, const Math::Matrix &matrix) +{ + switch (type) + { + case Gfx::TRANSFORM_WORLD: + m_worldMat = matrix; + // TODO + break; + case Gfx::TRANSFORM_VIEW: + m_viewMat = matrix; + // TODO + break; + case Gfx::TRANSFORM_PROJECTION: + m_projectionMat = matrix; + // TODO + break; + default: + assert(false); + } +} + +const Math::Matrix& Gfx::CGLDevice::GetTransform(Gfx::TransformType type) +{ + switch (type) + { + case Gfx::TRANSFORM_WORLD: + return m_worldMat; + case Gfx::TRANSFORM_VIEW: + return m_viewMat; + case Gfx::TRANSFORM_PROJECTION: + return m_projectionMat; + default: + assert(false); + } + + return m_worldMat; // to avoid warning +} + +void Gfx::CGLDevice::MultiplyTransform(Gfx::TransformType type, const Math::Matrix &matrix) +{ + // TODO +} + +void Gfx::CGLDevice::SetMaterial(const Gfx::Material &material) +{ + m_material = material; + + // TODO +} + +const Gfx::Material& Gfx::CGLDevice::GetMaterial() +{ + return m_material; +} + +int Gfx::CGLDevice::GetMaxLightCount() +{ + return m_lights.size(); +} + +void Gfx::CGLDevice::SetLight(int index, const Gfx::Light &light) +{ + assert(index >= 0); + assert(index < (int)m_lights.size()); + + m_lights[index] = light; + + // TODO +} + +const Gfx::Light& Gfx::CGLDevice::GetLight(int index) +{ + assert(index >= 0); + assert(index < (int)m_lights.size()); + + return m_lights[index]; +} + +void Gfx::CGLDevice::SetLightEnabled(int index, bool enabled) +{ + assert(index >= 0); + assert(index < (int)m_lightsEnabled.size()); + + m_lightsEnabled[index] = enabled; + + // TODO +} + +bool Gfx::CGLDevice::GetLightEnabled(int index) +{ + assert(index >= 0); + assert(index < (int)m_lights.size()); + + return m_lightsEnabled[index]; +} + +int Gfx::CGLDevice::GetMaxTextureCount() +{ + return m_textures.size(); +} + +const Gfx::Texture& Gfx::CGLDevice::GetTexture(int index) +{ + assert(index >= 0); + assert(index < (int)m_textures.size()); + + return m_textures[index]; +} + +void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture) +{ + assert(index >= 0); + assert(index < (int)m_textures.size()); + + m_textures[index] = texture; + + // TODO +} + +void Gfx::CGLDevice::SetRenderState(Gfx::RenderState state, bool enabled) +{ + // TODO +} + +bool Gfx::CGLDevice::GetRenderState(Gfx::RenderState state) +{ + // TODO + return false; +} + +void Gfx::CGLDevice::DrawPrimitive(Gfx::PrimitiveType, Vertex *vertices, int vertexCount) +{ + // TODO +} + +void Gfx::CGLDevice::DrawPrimitive(Gfx::PrimitiveType, VertexTex2 *vertices, int vertexCount) +{ + // TODO +} diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index a2fb4a0..0b4702a 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -21,11 +21,103 @@ #include "graphics/common/device.h" + +#include + + namespace Gfx { +/** + \struct GLDeviceConfig + \brief Additional config with OpenGL-specific settings */ +struct GLDeviceConfig : public DeviceConfig +{ + //! Size of red channel in bits + int redSize; + //! Size of green channel in bits + int greenSize; + //! Size of blue channel in bits + int blueSize; + //! Size of alpha channel in bits + int alphaSize; + //! Color depth in bits + int depthSize; + + //! Force hardware acceleration (video mode set will fail on lack of hw accel) + bool hardwareAccel; + + //! Constructor calls LoadDefaults() + GLDeviceConfig() { LoadDefault(); } + + //! Loads the default values + void LoadDefault(); +}; + +/** + \class CGLDevice + \brief Implementation of CDevice interface in OpenGL + + Provides the concrete implementation of 3D device in OpenGL. + + This class should be initialized (by calling Initialize() ) only after + setting the video mode by CApplication, once the OpenGL context is defined. + Because of that, CGLDeviceConfig is outside the CDevice class and must be set + in CApplication. +*/ class CGLDevice : public Gfx::CDevice { - // TODO +public: + CGLDevice(); + virtual ~CGLDevice(); + + virtual void Initialize(); + virtual void Destroy(); + + virtual void BeginScene(); + virtual void EndScene(); + + virtual void Clear(); + + virtual void SetTransform(Gfx::TransformType type, const Math::Matrix &matrix); + virtual const Math::Matrix& GetTransform(Gfx::TransformType type); + virtual void MultiplyTransform(Gfx::TransformType type, const Math::Matrix &matrix); + + virtual void SetMaterial(const Gfx::Material &material); + virtual const Gfx::Material& GetMaterial(); + + virtual int GetMaxLightCount(); + virtual void SetLight(int index, const Gfx::Light &light); + virtual const Gfx::Light& GetLight(int index); + virtual void SetLightEnabled(int index, bool enabled); + virtual bool GetLightEnabled(int index); + + virtual int GetMaxTextureCount(); + virtual const Gfx::Texture& GetTexture(int index); + virtual void SetTexture(int index, const Gfx::Texture &texture); + + virtual void SetRenderState(Gfx::RenderState state, bool enabled); + virtual bool GetRenderState(Gfx::RenderState state); + + virtual void DrawPrimitive(Gfx::PrimitiveType, Vertex *vertices, int vertexCount); + virtual void DrawPrimitive(Gfx::PrimitiveType, VertexTex2 *vertices, int vertexCount); + +private: + //! Current world matrix + Math::Matrix m_worldMat; + //! Current view matrix + Math::Matrix m_viewMat; + //! Current projection matrix + Math::Matrix m_projectionMat; + //! The current material + Gfx::Material m_material; + //! Current lights + std::vector m_lights; + //! Current lights enable status + std::vector m_lightsEnabled; + //! Current textures + std::vector m_textures; + //! Current render state + unsigned long m_renderState; }; }; // namespace Gfx -- cgit v1.2.3-1-g7c22