2011-01-20 20:54:38 -05:00
|
|
|
// $Id$
|
2009-02-03 19:31:40 -05:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2009 Joerg Henrichs
|
|
|
|
//
|
|
|
|
// 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, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#ifndef HEADER_IRR_DRIVER_HPP
|
|
|
|
#define HEADER_IRR_DRIVER_HPP
|
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \defgroup graphics
|
|
|
|
*/
|
|
|
|
|
2009-02-10 00:30:59 -05:00
|
|
|
#include <string>
|
2009-03-23 19:50:50 -04:00
|
|
|
#include <vector>
|
2009-02-10 00:30:59 -05:00
|
|
|
|
2011-02-02 17:04:13 -05:00
|
|
|
#include "irrlicht.h"
|
|
|
|
using namespace irr;
|
|
|
|
|
|
|
|
#include "utils/aligned_array.hpp"
|
2010-09-08 20:30:58 -04:00
|
|
|
#include "utils/no_copy.hpp"
|
2009-06-25 21:19:57 -04:00
|
|
|
#include "utils/ptr_vector.hpp"
|
|
|
|
#include "utils/vec3.hpp"
|
|
|
|
|
2009-02-03 19:31:40 -05:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
class Camera;
|
|
|
|
class Kart;
|
2011-02-09 20:56:52 -05:00
|
|
|
class PerCameraNode;
|
2011-04-21 18:25:09 -04:00
|
|
|
namespace irr { namespace scene { class IAnimatedMeshSceneNode; } }
|
2009-11-23 00:20:05 -05:00
|
|
|
|
2009-05-09 16:20:16 -04:00
|
|
|
struct VideoMode
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
};
|
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
2011-04-20 09:04:21 -04:00
|
|
|
* \brief class that creates the irrLicht device and offers higher-level
|
|
|
|
* ways to manage the 3D scene
|
2010-04-23 16:36:13 -04:00
|
|
|
* \ingroup graphics
|
|
|
|
*/
|
2010-09-08 20:30:58 -04:00
|
|
|
class IrrDriver : public IEventReceiver, public NoCopy
|
2009-02-03 19:31:40 -05:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
/** The irrlicht device. */
|
2009-02-28 19:46:47 -05:00
|
|
|
IrrlichtDevice *m_device;
|
2009-03-11 01:10:56 -04:00
|
|
|
/** Irrlicht scene manager. */
|
2009-02-28 19:46:47 -05:00
|
|
|
scene::ISceneManager *m_scene_manager;
|
2009-03-11 01:10:56 -04:00
|
|
|
/** Irrlicht gui environment. */
|
|
|
|
gui::IGUIEnvironment *m_gui_env;
|
2009-07-13 08:25:38 -04:00
|
|
|
/** Irrlicht video driver. */
|
|
|
|
video::IVideoDriver *m_video_driver;
|
2009-03-11 01:10:56 -04:00
|
|
|
/** Irrlicht race font. */
|
|
|
|
irr::gui::IGUIFont *m_race_font;
|
2009-08-29 13:09:03 -04:00
|
|
|
|
2010-11-23 18:23:40 -05:00
|
|
|
/** Flag to indicate if a resolution change is pending (which will be
|
|
|
|
* acted upon in the next update). None means no change, yes means
|
|
|
|
* change to new resolution and trigger confirmation dialog.
|
|
|
|
* Cancel indicates a change of the resolution (back to the original
|
|
|
|
* one), but no confirmation dialog. */
|
|
|
|
enum {RES_CHANGE_NONE, RES_CHANGE_YES,
|
|
|
|
RES_CHANGE_CANCEL} m_resolution_changing;
|
2010-02-03 16:47:36 -05:00
|
|
|
|
2011-03-16 17:43:58 -04:00
|
|
|
void setAllMaterialFlags(scene::IMesh *mesh) const;
|
2009-05-09 16:20:16 -04:00
|
|
|
std::vector<VideoMode> m_modes;
|
2009-03-26 19:31:00 -04:00
|
|
|
|
2009-11-23 00:20:05 -05:00
|
|
|
void setupViewports();
|
|
|
|
video::E_DRIVER_TYPE getEngineDriverType(int index);
|
2010-01-30 14:53:06 -05:00
|
|
|
|
|
|
|
/** Whether the mouse cursor is currently shown */
|
|
|
|
bool m_pointer_shown;
|
|
|
|
|
2010-02-03 19:45:24 -05:00
|
|
|
/** Internal method that applies the resolution in user settings. */
|
2010-11-23 18:23:40 -05:00
|
|
|
void applyResolutionSettings();
|
2010-02-03 19:45:24 -05:00
|
|
|
|
2009-02-03 19:31:40 -05:00
|
|
|
public:
|
2009-02-10 00:30:59 -05:00
|
|
|
IrrDriver();
|
|
|
|
~IrrDriver();
|
2009-04-23 19:27:06 -04:00
|
|
|
void initDevice();
|
|
|
|
|
2009-07-13 08:25:38 -04:00
|
|
|
/** Returns a list of all video modes supports by the graphics card. */
|
2009-05-09 16:20:16 -04:00
|
|
|
const std::vector<VideoMode>& getVideoModes() const { return m_modes; }
|
2009-07-13 08:25:38 -04:00
|
|
|
/** Returns the frame size. */
|
2009-08-05 08:45:11 -04:00
|
|
|
const core::dimension2d<u32> getFrameSize() const
|
|
|
|
{ return m_video_driver->getCurrentRenderTargetSize(); }
|
2009-07-13 08:25:38 -04:00
|
|
|
/** Returns the irrlicht device. */
|
2009-02-10 00:30:59 -05:00
|
|
|
IrrlichtDevice *getDevice() const { return m_device; }
|
2009-07-13 08:25:38 -04:00
|
|
|
/** Returns the irrlicht video driver. */
|
|
|
|
video::IVideoDriver *getVideoDriver() const { return m_video_driver; }
|
|
|
|
/** Returns the irrlicht scene manager. */
|
2009-02-10 00:30:59 -05:00
|
|
|
scene::ISceneManager *getSceneManager() const { return m_scene_manager; }
|
|
|
|
scene::IAnimatedMesh *getAnimatedMesh(const std::string &name);
|
2009-02-10 06:11:39 -05:00
|
|
|
scene::IMesh *getMesh(const std::string &name);
|
2009-03-11 01:10:56 -04:00
|
|
|
/** Returns the gui environment, used to add widgets to a screen. */
|
|
|
|
gui::IGUIEnvironment *getGUI() const { return m_gui_env; }
|
2010-01-24 18:57:50 -05:00
|
|
|
//irr::gui::IGUIFont *getRaceFont() const { return m_race_font; }
|
2010-04-20 19:45:54 -04:00
|
|
|
|
2011-04-20 09:04:21 -04:00
|
|
|
video::ITexture *applyMask(video::ITexture* texture,
|
|
|
|
const std::string& mask_path);
|
2011-03-25 19:52:30 -04:00
|
|
|
|
2010-09-11 16:47:05 -04:00
|
|
|
void displayFPS();
|
2010-04-20 19:45:54 -04:00
|
|
|
/** this is not really used to process events, it's only used to shut down irrLicht's
|
|
|
|
* chatty logging until the event handler is ready to take the task
|
|
|
|
*/
|
|
|
|
bool OnEvent(const irr::SEvent &event);
|
|
|
|
|
2009-03-15 21:45:49 -04:00
|
|
|
void setAmbientLight(const video::SColor &light);
|
2011-02-16 01:07:38 -05:00
|
|
|
video::ITexture *getTexture(const std::string &filename,
|
|
|
|
bool is_premul=false,
|
|
|
|
bool is_prediv=false);
|
2009-07-16 20:22:58 -04:00
|
|
|
scene::IMesh *createQuadMesh(const video::SMaterial *material=NULL,
|
|
|
|
bool create_one_quad=false);
|
2011-04-20 09:04:21 -04:00
|
|
|
scene::IMesh *createTexturedQuadMesh(const video::SMaterial *material,
|
|
|
|
const double w, const double h);
|
2009-03-23 19:50:50 -04:00
|
|
|
scene::ISceneNode *addWaterNode(scene::IMesh *mesh, float wave_height,
|
|
|
|
float wave_speed, float wave_length);
|
2010-06-15 20:18:51 -04:00
|
|
|
scene::IMeshSceneNode*addOctTree(scene::IMesh *mesh);
|
2010-09-08 20:30:58 -04:00
|
|
|
scene::IMeshSceneNode*addMesh(scene::IMesh *mesh,
|
|
|
|
scene::ISceneNode *parent=NULL);
|
2011-04-20 09:04:21 -04:00
|
|
|
PerCameraNode *addPerCameraMesh(scene::IMesh* mesh,
|
|
|
|
scene::ICameraSceneNode* node,
|
|
|
|
scene::ISceneNode *parent = NULL);
|
|
|
|
scene::ISceneNode *addBillboard(const core::dimension2d< f32 > size,
|
|
|
|
video::ITexture *texture,
|
|
|
|
scene::ISceneNode* parent=NULL);
|
2009-12-28 14:37:59 -05:00
|
|
|
|
2009-03-16 22:52:58 -04:00
|
|
|
scene::IParticleSystemSceneNode
|
|
|
|
*addParticleNode(bool default_emitter=true);
|
2011-04-28 20:29:34 -04:00
|
|
|
scene::ISceneNode *addSkyDome(video::ITexture *texture, int hori_res,
|
2009-03-16 22:52:58 -04:00
|
|
|
int vert_res, float texture_percent,
|
|
|
|
float sphere_percent);
|
2011-04-28 20:29:34 -04:00
|
|
|
scene::ISceneNode *addSkyBox(const std::vector<video::ITexture*> &texture_names);
|
2009-03-11 01:10:56 -04:00
|
|
|
void removeNode(scene::ISceneNode *node);
|
2011-04-27 07:47:33 -04:00
|
|
|
void removeMeshFromCache(scene::IMesh *mesh);
|
2009-07-27 07:56:09 -04:00
|
|
|
void removeTexture(video::ITexture *t);
|
2009-04-05 08:53:17 -04:00
|
|
|
scene::IAnimatedMeshSceneNode
|
|
|
|
*addAnimatedMesh(scene::IAnimatedMesh *mesh);
|
2009-02-10 00:30:59 -05:00
|
|
|
scene::ICameraSceneNode
|
2009-11-23 00:20:05 -05:00
|
|
|
*addCameraSceneNode();
|
|
|
|
Camera *addCamera(unsigned int index, Kart *kart);
|
|
|
|
void removeCameraSceneNode(scene::ICameraSceneNode *camera);
|
|
|
|
void removeCamera(Camera *camera);
|
2009-02-19 20:42:34 -05:00
|
|
|
void update(float dt);
|
2009-04-23 19:27:06 -04:00
|
|
|
|
2010-02-03 19:45:24 -05:00
|
|
|
/** Call to change resolution */
|
|
|
|
void changeResolution(const int w, const int h, const bool fullscreen);
|
2010-11-23 18:23:40 -05:00
|
|
|
/** Call this to roll back to the previous resolution if a resolution switch attempt goes bad */
|
2010-02-03 19:45:24 -05:00
|
|
|
void cancelResChange();
|
|
|
|
|
2010-01-28 06:50:47 -05:00
|
|
|
void showPointer();
|
|
|
|
void hidePointer();
|
2010-01-30 14:53:06 -05:00
|
|
|
bool isPointerShown() const { return m_pointer_shown; }
|
2010-01-28 06:50:47 -05:00
|
|
|
void printRenderStats();
|
2009-08-23 11:42:58 -04:00
|
|
|
/** Returns the current real time, which might not be 0 at start of the
|
|
|
|
* application. Value in msec.
|
|
|
|
*/
|
|
|
|
unsigned int getRealTime() {return m_device->getTimer()->getRealTime(); }
|
2009-06-24 19:01:45 -04:00
|
|
|
|
2009-08-29 13:09:03 -04:00
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
void draw2dTriangle(const core::vector2df &a, const core::vector2df &b,
|
|
|
|
const core::vector2df &c,
|
|
|
|
const video::ITexture *texture = NULL,
|
2011-04-20 09:04:21 -04:00
|
|
|
const video::SColor *ca=NULL,
|
|
|
|
const video::SColor *cb=NULL,
|
2009-07-27 07:56:09 -04:00
|
|
|
const video::SColor *cc=NULL);
|
2009-08-29 13:09:03 -04:00
|
|
|
|
|
|
|
// --------------------- RTT --------------------
|
|
|
|
/**
|
2011-04-20 09:04:21 -04:00
|
|
|
* Class that provides RTT (currently, only when no other 3D rendering
|
|
|
|
* in the main scene is required)
|
|
|
|
* Provides an optional 'setupRTTScene' method to make it quick and easy
|
|
|
|
* to prepare rendering of 3D objects but you can also manually set the
|
|
|
|
* scene/camera. If you use the factory 'setupRTTScene', cleanup can be
|
|
|
|
* done through 'tearDownRTTScene' (destructor will also do this). If
|
|
|
|
* you set it up manually, you need to clean it up manually.
|
2009-08-29 13:09:03 -04:00
|
|
|
*/
|
|
|
|
class RTTProvider
|
|
|
|
{
|
|
|
|
/** A pointer to texture on which a scene is rendered. Only used
|
|
|
|
* in between beginRenderToTexture() and endRenderToTexture calls. */
|
|
|
|
video::ITexture *m_render_target_texture;
|
|
|
|
|
|
|
|
/** Main node of the RTT scene */
|
|
|
|
scene::ISceneNode *m_rtt_main_node;
|
|
|
|
|
|
|
|
scene::ICameraSceneNode *m_camera;
|
|
|
|
|
|
|
|
scene::ILightSceneNode *m_light;
|
|
|
|
|
|
|
|
/** Irrlicht video driver. */
|
|
|
|
video::IVideoDriver *m_video_driver;
|
|
|
|
|
|
|
|
public:
|
|
|
|
RTTProvider(const core::dimension2du &dimension,
|
2009-09-08 08:50:52 -04:00
|
|
|
const std::string &name);
|
2009-08-29 13:09:03 -04:00
|
|
|
|
|
|
|
~RTTProvider();
|
|
|
|
|
2009-12-30 14:41:59 -05:00
|
|
|
/**
|
2011-04-20 09:04:21 -04:00
|
|
|
* \brief Quick utility method to setup a scene from a plain list
|
|
|
|
* of models
|
2009-12-30 14:41:59 -05:00
|
|
|
*
|
2011-04-20 09:04:21 -04:00
|
|
|
* Sets up a given vector of meshes for render-to-texture. Ideal to
|
|
|
|
* embed a 3D object inside the GUI. If there are multiple meshes,
|
|
|
|
* the first mesh is considered to be the root, and all following
|
|
|
|
* meshes will have their locations relative to the location of the
|
|
|
|
* first mesh.
|
2009-12-30 14:41:59 -05:00
|
|
|
*
|
|
|
|
* \param mesh The list of meshes to add to the scene
|
|
|
|
* \param mesh_location Location of each fo these meshes
|
2011-04-20 09:04:21 -04:00
|
|
|
* \param model_frames For animated meshes, which frame to use
|
|
|
|
* (value can be -1 to set none)
|
|
|
|
* When frame is not -1, the corresponding
|
|
|
|
* IMesh must be an IAnimatedMesh.
|
2011-04-12 16:42:57 -04:00
|
|
|
* \pre The 3 vectors have the same size.
|
2009-12-30 14:41:59 -05:00
|
|
|
*/
|
2011-02-03 17:20:53 -05:00
|
|
|
void setupRTTScene(PtrVector<scene::IMesh, REF>& mesh,
|
2011-02-02 17:04:13 -05:00
|
|
|
AlignedArray<Vec3>& mesh_location,
|
|
|
|
AlignedArray<Vec3>& mesh_scale,
|
2009-12-30 14:41:59 -05:00
|
|
|
const std::vector<int>& model_frames);
|
2009-08-29 13:09:03 -04:00
|
|
|
|
2011-04-20 09:04:21 -04:00
|
|
|
/** Optional 'angle' parameter will rotate the object added
|
|
|
|
* *through setupRTTScene* */
|
2009-09-08 08:50:52 -04:00
|
|
|
video::ITexture* renderToTexture(float angle=-1,
|
|
|
|
bool is_2d_render=false);
|
2009-08-29 13:09:03 -04:00
|
|
|
|
|
|
|
void tearDownRTTScene();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-04-21 18:25:09 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
std::vector<irr::scene::IAnimatedMeshSceneNode*> debug_meshes;
|
|
|
|
#endif
|
|
|
|
|
2009-07-27 07:56:09 -04:00
|
|
|
|
2009-02-03 19:31:40 -05:00
|
|
|
}; // IrrDriver
|
|
|
|
|
|
|
|
extern IrrDriver *irr_driver;
|
|
|
|
|
|
|
|
#endif // HEADER_IRR_DRIVER_HPP
|