2013-11-05 10:45:26 +00:00
|
|
|
#ifndef OPENGLRENDERER_H
|
|
|
|
#define OPENGLRENDERER_H
|
|
|
|
|
|
|
|
#include "opengl_global.h"
|
|
|
|
|
2013-11-14 20:46:47 +00:00
|
|
|
#include "SoftwareRenderer.h"
|
2013-11-05 10:45:26 +00:00
|
|
|
|
2015-12-11 00:12:55 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2015-09-06 23:15:59 +00:00
|
|
|
class QMatrix4x4;
|
|
|
|
|
2013-11-05 10:45:26 +00:00
|
|
|
namespace paysages {
|
|
|
|
namespace opengl {
|
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
/**
|
|
|
|
* Scenery renderer in an OpenGL context.
|
2013-11-05 10:45:26 +00:00
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class OPENGLSHARED_EXPORT OpenGLRenderer : public SoftwareRenderer {
|
|
|
|
public:
|
|
|
|
OpenGLRenderer(Scenery *scenery);
|
2013-11-14 20:46:47 +00:00
|
|
|
virtual ~OpenGLRenderer();
|
2013-11-05 10:45:26 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline OpenGLSkybox *getSkybox() const {
|
|
|
|
return skybox;
|
|
|
|
}
|
|
|
|
inline OpenGLWater *getWater() const {
|
|
|
|
return water;
|
|
|
|
}
|
|
|
|
inline OpenGLTerrain *getTerrain() const {
|
|
|
|
return terrain;
|
|
|
|
}
|
2015-11-25 22:15:58 +00:00
|
|
|
inline OpenGLVegetation *getVegetation() const {
|
|
|
|
return vegetation;
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
inline bool isDisplayed() const {
|
|
|
|
return displayed;
|
|
|
|
}
|
2015-12-10 22:41:42 +00:00
|
|
|
inline bool isStopping() const {
|
|
|
|
return stopping;
|
|
|
|
}
|
|
|
|
inline bool isStopped() const {
|
|
|
|
return stopped;
|
|
|
|
}
|
2014-08-28 13:09:47 +00:00
|
|
|
|
2015-10-18 15:35:42 +00:00
|
|
|
virtual void prepare() override;
|
|
|
|
|
2015-12-03 22:04:50 +00:00
|
|
|
/**
|
|
|
|
* Check for errors in OpenGL context.
|
|
|
|
*
|
|
|
|
* Will write the error on standard error output, with the *domain* specified.
|
|
|
|
*/
|
2015-12-10 23:36:50 +00:00
|
|
|
void checkForErrors(const string &domain);
|
2015-12-03 22:04:50 +00:00
|
|
|
|
2015-12-10 22:41:42 +00:00
|
|
|
/**
|
|
|
|
* Release any allocated resource in the opengl context.
|
|
|
|
*
|
|
|
|
* Must be called in the opengl rendering thread, and before the destructor is called.
|
|
|
|
*/
|
|
|
|
void destroy();
|
2015-12-03 22:04:50 +00:00
|
|
|
|
2013-11-05 10:45:26 +00:00
|
|
|
void initialize();
|
2015-12-10 22:41:42 +00:00
|
|
|
void prepareOpenGLState(bool clear = true);
|
2013-11-05 10:45:26 +00:00
|
|
|
void resize(int width, int height);
|
2015-12-10 22:41:42 +00:00
|
|
|
void paint(bool clear = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ask for the rendering to stop gracefully.
|
|
|
|
*
|
|
|
|
* Returns true if the rendering is stopped and resources freed.
|
|
|
|
*
|
|
|
|
* This should be called in an idle loop, while it returns false.
|
|
|
|
*/
|
|
|
|
bool stop();
|
2013-12-15 14:06:43 +00:00
|
|
|
|
2015-08-19 18:06:47 +00:00
|
|
|
/**
|
|
|
|
* Reset the whole state (when the scenery has been massively updated).
|
|
|
|
*/
|
|
|
|
void reset();
|
|
|
|
|
2015-08-18 17:12:54 +00:00
|
|
|
/**
|
|
|
|
* Pause the rendering process.
|
|
|
|
*
|
|
|
|
* This will prevent paintings and stop background tasks, until resume() is called.
|
|
|
|
*/
|
|
|
|
void pause();
|
|
|
|
/**
|
|
|
|
* Resume the rendering process, put on hold by pause().
|
|
|
|
*/
|
|
|
|
void resume();
|
|
|
|
|
2015-09-06 23:15:59 +00:00
|
|
|
/**
|
|
|
|
* Set the current mouse location, for use by getMouseProjection().
|
|
|
|
*/
|
|
|
|
void setMouseLocation(int x, int y);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the coordinates of the mouse, projected in world space.
|
|
|
|
*/
|
|
|
|
const Vector3 &getMouseProjection();
|
|
|
|
|
2014-09-18 15:38:37 +00:00
|
|
|
/**
|
|
|
|
* Change the camera location.
|
|
|
|
*/
|
|
|
|
void setCamera(CameraDefinition *camera);
|
2015-11-09 21:30:46 +00:00
|
|
|
void cameraChangeEvent(CameraDefinition *camera);
|
2013-12-21 22:48:54 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline OpenGLFunctions *getOpenGlFunctions() const {
|
|
|
|
return functions;
|
|
|
|
}
|
|
|
|
inline OpenGLSharedState *getSharedState() const {
|
|
|
|
return shared_state;
|
|
|
|
}
|
2013-12-21 22:48:54 +00:00
|
|
|
|
2013-12-15 14:18:11 +00:00
|
|
|
virtual double getPrecision(const Vector3 &location) override;
|
2015-11-08 22:32:52 +00:00
|
|
|
virtual Color applyMediumTraversal(const Vector3 &location, const Color &color) override;
|
2013-12-21 22:48:54 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-09-06 23:15:59 +00:00
|
|
|
/**
|
|
|
|
* Update the mouse_projected member.
|
|
|
|
*/
|
|
|
|
void updateMouseProjection();
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2013-12-23 09:26:29 +00:00
|
|
|
bool ready;
|
2015-08-18 17:12:54 +00:00
|
|
|
bool paused;
|
2015-09-14 17:25:54 +00:00
|
|
|
bool displayed;
|
2015-12-10 22:41:42 +00:00
|
|
|
bool stopping;
|
|
|
|
bool stopped;
|
2014-08-27 16:19:48 +00:00
|
|
|
int vp_width;
|
|
|
|
int vp_height;
|
2013-12-23 09:26:29 +00:00
|
|
|
|
2015-09-06 23:15:59 +00:00
|
|
|
bool mouse_tracking;
|
|
|
|
int mouse_x;
|
|
|
|
int mouse_y;
|
|
|
|
Vector3 *mouse_projected;
|
|
|
|
|
|
|
|
QMatrix4x4 *view_matrix;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
OpenGLFunctions *functions;
|
|
|
|
OpenGLSharedState *shared_state;
|
2013-12-21 22:48:54 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
OpenGLSkybox *skybox;
|
|
|
|
OpenGLWater *water;
|
|
|
|
OpenGLTerrain *terrain;
|
2015-11-25 22:15:58 +00:00
|
|
|
OpenGLVegetation *vegetation;
|
2015-12-11 00:12:55 +00:00
|
|
|
|
|
|
|
vector<OpenGLPart *> parts;
|
2013-11-05 10:45:26 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OPENGLRENDERER_H
|