added RenderQueue
This commit is contained in:
parent
8f17a3a819
commit
7a3d5f6eb5
@ -7,116 +7,138 @@
|
|||||||
namespace BlueCore
|
namespace BlueCore
|
||||||
{
|
{
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
Camera::Camera()
|
Camera::Camera()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
Camera::~Camera()
|
Camera::~Camera()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void Camera::setFoV(Scalar fov)
|
void Camera::setFoV(Scalar fov)
|
||||||
{
|
{
|
||||||
_FoV = fov;
|
_FoV = fov;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void Camera::setAspectRatio(Scalar aspect)
|
void Camera::setAspectRatio(Scalar aspect)
|
||||||
{
|
{
|
||||||
_AspectRatio = aspect;
|
_AspectRatio = aspect;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void Camera::setNearPlane(Scalar near)
|
void Camera::setNearPlane(Scalar near)
|
||||||
{
|
{
|
||||||
_NearPlane = near;
|
_NearPlane = near;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void Camera::setFarPlane(Scalar far)
|
void Camera::setFarPlane(Scalar far)
|
||||||
{
|
{
|
||||||
_FarPlane = far;
|
_FarPlane = far;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void Camera::setPosition(const Vector3& position)
|
void Camera::setPosition(const Vector3& position)
|
||||||
{
|
{
|
||||||
_Position = position;
|
_Position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector3& Camera::getPosition()
|
const Vector3& Camera::getPosition()
|
||||||
{
|
{
|
||||||
return _Position;
|
return _Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void Camera::setRotation(const Quaternion& rotation)
|
void Camera::setRotation(const Quaternion& rotation)
|
||||||
{
|
{
|
||||||
_Rotation = rotation;
|
_Rotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
const Quaternion& Camera::getRotation()
|
||||||
|
{
|
||||||
|
return _Rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
void Camera::setupProjectionMatrix()
|
void Camera::setupProjectionMatrix()
|
||||||
{
|
{
|
||||||
Scalar fW, fH;
|
Scalar fW, fH;
|
||||||
|
|
||||||
fH = tan ( (_FoV / 2) / 180* Pi ) * _NearPlane;
|
fH = tan ( (_FoV / 2) / 180* Pi ) * _NearPlane;
|
||||||
fW = fH * _AspectRatio;
|
fW = fH * _AspectRatio;
|
||||||
|
|
||||||
// setup projectiom matrix
|
// setup projectiom matrix
|
||||||
glMatrixMode (GL_PROJECTION );
|
glMatrixMode (GL_PROJECTION );
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glFrustum ( -fW, fW, -fH, fH, _NearPlane, _FarPlane );
|
glFrustum ( -fW, fW, -fH, fH, _NearPlane, _FarPlane );
|
||||||
|
|
||||||
// save variables for frustum culling
|
// save variables for frustum culling
|
||||||
/*
|
/*
|
||||||
_near = nearZ;
|
_near = nearZ;
|
||||||
_far = farZ;
|
_far = farZ;
|
||||||
_hNear = tan ( ( fov / 2 ) / 180 * Pi ) * nearZ;
|
_hNear = tan ( ( fov / 2 ) / 180 * Pi ) * nearZ;
|
||||||
_wNear = _hNear * aspect;
|
_wNear = _hNear * aspect;
|
||||||
_hFar = tan ( ( fov / 2 ) / 180 * Pi ) * farZ;
|
_hFar = tan ( ( fov / 2 ) / 180 * Pi ) * farZ;
|
||||||
_wFar = _hFar * aspect;
|
_wFar = _hFar * aspect;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void Camera::setupViewMatrix()
|
void Camera::setupViewMatrix()
|
||||||
{
|
{
|
||||||
// set the view matrix
|
// set the view matrix
|
||||||
glMatrixMode (GL_MODELVIEW );
|
glMatrixMode (GL_MODELVIEW );
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
Matrix4x4 m(_Rotation, _Rotation.applyInversed(_Position * -1.0) );
|
Matrix4x4 m(_Rotation, _Rotation.applyInversed(_Position * -1.0) );
|
||||||
glMultMatrixd ( ( GLdouble * ) &m.m );
|
glMultMatrixd ( ( GLdouble * ) &m.m );
|
||||||
/*
|
/*
|
||||||
// calculate frustum planes
|
// calculate frustum planes
|
||||||
Vector3 up = q.apply ( Vector3 ( 0.0, 1.0, 0.0 ) );
|
Vector3 up = q.apply ( Vector3 ( 0.0, 1.0, 0.0 ) );
|
||||||
Vector3 right = q.apply ( Vector3 ( 1.0, 0.0, 0.0 ) );
|
Vector3 right = q.apply ( Vector3 ( 1.0, 0.0, 0.0 ) );
|
||||||
Vector3 d = q.apply ( Vector3 ( 0.0, 0.0, -1.0 ) );
|
Vector3 d = q.apply ( Vector3 ( 0.0, 0.0, -1.0 ) );
|
||||||
|
|
||||||
Vector3 fc = p + d * _far;
|
Vector3 fc = p + d * _far;
|
||||||
|
|
||||||
Vector3 ftl = fc + ( up * _hFar ) - ( right * _wFar );
|
Vector3 ftl = fc + ( up * _hFar ) - ( right * _wFar );
|
||||||
Vector3 ftr = fc + ( up * _hFar ) + ( right * _wFar );
|
Vector3 ftr = fc + ( up * _hFar ) + ( right * _wFar );
|
||||||
Vector3 fbl = fc - ( up * _hFar ) - ( right * _wFar );
|
Vector3 fbl = fc - ( up * _hFar ) - ( right * _wFar );
|
||||||
Vector3 fbr = fc - ( up * _hFar ) + ( right * _wFar );
|
Vector3 fbr = fc - ( up * _hFar ) + ( right * _wFar );
|
||||||
|
|
||||||
Vector3 nc = p + d * _near;
|
Vector3 nc = p + d * _near;
|
||||||
|
|
||||||
Vector3 ntl = nc + ( up * _hNear ) - ( right * _wNear );
|
Vector3 ntl = nc + ( up * _hNear ) - ( right * _wNear );
|
||||||
Vector3 ntr = nc + ( up * _hNear ) + ( right * _wNear );
|
Vector3 ntr = nc + ( up * _hNear ) + ( right * _wNear );
|
||||||
Vector3 nbl = nc - ( up * _hNear ) - ( right * _wNear );
|
Vector3 nbl = nc - ( up * _hNear ) - ( right * _wNear );
|
||||||
Vector3 nbr = nc - ( up * _hNear ) + ( right * _wNear );
|
Vector3 nbr = nc - ( up * _hNear ) + ( right * _wNear );
|
||||||
|
|
||||||
_frustumPlanes[RightPlane] = Plane ( nbr, fbr, ntr );
|
_frustumPlanes[RightPlane] = Plane ( nbr, fbr, ntr );
|
||||||
_frustumPlanes[LeftPlane] = Plane ( ntl, fbl, nbl );
|
_frustumPlanes[LeftPlane] = Plane ( ntl, fbl, nbl );
|
||||||
_frustumPlanes[BottomPlane] = Plane ( nbl, fbr, nbr );
|
_frustumPlanes[BottomPlane] = Plane ( nbl, fbr, nbr );
|
||||||
_frustumPlanes[TopPlane] = Plane ( ntr, ftl, ntl );
|
_frustumPlanes[TopPlane] = Plane ( ntr, ftl, ntl );
|
||||||
_frustumPlanes[FarPlane] = Plane ( ftl, ftr, fbl );
|
_frustumPlanes[FarPlane] = Plane ( ftl, ftr, fbl );
|
||||||
_frustumPlanes[NearPlane] = Plane ( ntl, nbl, ntr );
|
_frustumPlanes[NearPlane] = Plane ( ntl, nbl, ntr );
|
||||||
*/
|
*/
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Scalar Camera::getNearPlane() const
|
||||||
|
{
|
||||||
|
return _NearPlane;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scalar Camera::getFarPlane() const
|
||||||
|
{
|
||||||
|
return _FarPlane;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scalar Camera::getFov() const
|
||||||
|
{
|
||||||
|
return _FoV;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace BlueCore
|
} // namespace BlueCore
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
#include "Math/Plane.h"
|
#include "Math/Plane.h"
|
||||||
//#include "geometry/frustum.h"
|
//#include "geometry/frustum.h"
|
||||||
|
|
||||||
namespace BlueCore {
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
|
||||||
class Camera : public Referenced
|
class Camera : public Referenced
|
||||||
{
|
{
|
||||||
@ -23,28 +24,30 @@ private:
|
|||||||
|
|
||||||
Vector3 _Position;
|
Vector3 _Position;
|
||||||
Quaternion _Rotation;
|
Quaternion _Rotation;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Camera();
|
Camera();
|
||||||
~Camera();
|
~Camera();
|
||||||
|
|
||||||
void lookAt( const Vector3 &point );
|
void lookAt(const Vector3 &point);
|
||||||
void lookAt( const Vector3 &point, const Vector3 &up );
|
void lookAt(const Vector3 &point, const Vector3 &up);
|
||||||
void lookStraight();
|
void lookStraight();
|
||||||
|
|
||||||
void setFoV( Scalar fov );
|
void setFoV(Scalar fov);
|
||||||
void setAspectRatio( Scalar aspect );
|
void setAspectRatio(Scalar aspect);
|
||||||
void setNearPlane( Scalar near );
|
void setNearPlane(Scalar near);
|
||||||
void setFarPlane( Scalar far );
|
void setFarPlane(Scalar far);
|
||||||
|
|
||||||
void setPosition (const Vector3& position);
|
void setPosition(const Vector3& position);
|
||||||
const Vector3& getPosition ();
|
const Vector3& getPosition();
|
||||||
|
|
||||||
void setRotation (const Quaternion& rotation);
|
void setRotation(const Quaternion& rotation);
|
||||||
|
const Quaternion& getRotation();
|
||||||
|
|
||||||
void setupViewMatrix ();
|
Scalar getNearPlane() const;
|
||||||
void setupProjectionMatrix ();
|
Scalar getFarPlane() const;
|
||||||
|
Scalar getFov() const;
|
||||||
|
|
||||||
//const Frustum &getFrustum() const;
|
//const Frustum &getFrustum() const;
|
||||||
};
|
};
|
||||||
|
@ -78,7 +78,7 @@ Font *FontManager::loadFont(const std::string &filename, int size, bool hinting)
|
|||||||
|
|
||||||
if (result != _fonts.end() && result->second.valid())
|
if (result != _fonts.end() && result->second.valid())
|
||||||
{
|
{
|
||||||
return result->second.get();
|
return result->second.pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Font *font;
|
Font *font;
|
||||||
@ -99,7 +99,7 @@ Font *FontManager::loadFont(const std::string &filename, int size, bool hinting)
|
|||||||
|
|
||||||
if (ftfont->Error() == 0)
|
if (ftfont->Error() == 0)
|
||||||
{
|
{
|
||||||
font = new Font( ftfont, buffer, _Device.get() );
|
font = new Font( ftfont, buffer, _Device );
|
||||||
clog << ">>> Font '"<< filename << "' ("<< size << ") loaded"
|
clog << ">>> Font '"<< filename << "' ("<< size << ") loaded"
|
||||||
<< endline;
|
<< endline;
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ Font *FontManager::loadFont(const std::string &filename, int size, bool hinting)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
Font *FontManager::getDefaultFont()
|
Font *FontManager::getDefaultFont()
|
||||||
{
|
{
|
||||||
return _DefaultFont.get();
|
return _DefaultFont.pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -208,10 +208,10 @@ Mesh *MeshManager::loadMesh(const string &filename)
|
|||||||
|
|
||||||
if (result != _Meshes.end() && result->second.valid())
|
if (result != _Meshes.end() && result->second.valid())
|
||||||
{
|
{
|
||||||
return result->second.get();
|
return result->second.pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh *mesh = new Mesh (_Device.get());
|
Mesh *mesh = new Mesh (_Device);
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
PHYSFS_sint64 mod_file = PHYSFS_getLastModTime(filename.c_str());
|
PHYSFS_sint64 mod_file = PHYSFS_getLastModTime(filename.c_str());
|
||||||
|
@ -17,7 +17,7 @@ namespace BlueCore
|
|||||||
{
|
{
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void Model::render()
|
void Model::render(RenderDevice *device) const
|
||||||
{
|
{
|
||||||
ModelMesh->render();
|
ModelMesh->render();
|
||||||
//glEnable(GL_LIGHTING);
|
//glEnable(GL_LIGHTING);
|
||||||
@ -208,7 +208,7 @@ Model *ModelManager::loadModel(const string &name)
|
|||||||
|
|
||||||
if (result != _Models.end() )
|
if (result != _Models.end() )
|
||||||
{
|
{
|
||||||
return result->second.get();
|
return result->second.pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
string filename = name + ".model.xml";
|
string filename = name + ".model.xml";
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "ShaderManager.h"
|
#include "ShaderManager.h"
|
||||||
#include "MeshManager.h"
|
#include "MeshManager.h"
|
||||||
|
#include "RenderQueue.h"
|
||||||
|
|
||||||
// forward declaration
|
// forward declaration
|
||||||
class TiXmlElement;
|
class TiXmlElement;
|
||||||
@ -19,7 +20,7 @@ class TiXmlElement;
|
|||||||
namespace BlueCore
|
namespace BlueCore
|
||||||
{
|
{
|
||||||
|
|
||||||
class Model : public Referenced, public Named
|
class Model : public Named, public RenderItem
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -46,7 +47,7 @@ public:
|
|||||||
RenderPassDefinition LitPass;
|
RenderPassDefinition LitPass;
|
||||||
RenderPassDefinition DefaultPass;
|
RenderPassDefinition DefaultPass;
|
||||||
|
|
||||||
void render();
|
void render(RenderDevice *) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ModelManager : public Referenced
|
class ModelManager : public Referenced
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "RenderDevice.h"
|
#include "RenderDevice.h"
|
||||||
|
|
||||||
#include "Utilities/Log.h"
|
#include "Utilities/Log.h"
|
||||||
|
#include "Math/Matrix.h"
|
||||||
|
|
||||||
#include "GL/gl.h"
|
#include "GL/gl.h"
|
||||||
#include "GL/glu.h"
|
#include "GL/glu.h"
|
||||||
@ -8,7 +9,6 @@
|
|||||||
namespace BlueCore
|
namespace BlueCore
|
||||||
{
|
{
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void RenderDevice::WindowResizeSlot(int width, int height)
|
void RenderDevice::WindowResizeSlot(int width, int height)
|
||||||
{
|
{
|
||||||
glViewport( 0, 0, width, height);
|
glViewport( 0, 0, width, height);
|
||||||
@ -16,7 +16,6 @@ void RenderDevice::WindowResizeSlot(int width, int height)
|
|||||||
_ViewportHeight = height;
|
_ViewportHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
RenderDevice::RenderDevice(RenderWindow* renderWindow) :
|
RenderDevice::RenderDevice(RenderWindow* renderWindow) :
|
||||||
_RenderWindow(renderWindow)
|
_RenderWindow(renderWindow)
|
||||||
{
|
{
|
||||||
@ -36,31 +35,26 @@ RenderDevice::RenderDevice(RenderWindow* renderWindow) :
|
|||||||
clog << ">>> RenderDevice constructed..."<< endlog;
|
clog << ">>> RenderDevice constructed..."<< endlog;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
RenderDevice::~RenderDevice()
|
RenderDevice::~RenderDevice()
|
||||||
{
|
{
|
||||||
clog << ">>> RenderDevice destructed..."<< endlog;
|
clog << ">>> RenderDevice destructed..."<< endlog;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void RenderDevice::WindowCloseSlot()
|
void RenderDevice::WindowCloseSlot()
|
||||||
{
|
{
|
||||||
DeviceShutdownSignal();
|
DeviceShutdownSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int RenderDevice::getViewportWidth()
|
int RenderDevice::getViewportWidth()
|
||||||
{
|
{
|
||||||
return _ViewportWidth;
|
return _ViewportWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int RenderDevice::getViewportHeight()
|
int RenderDevice::getViewportHeight()
|
||||||
{
|
{
|
||||||
return _ViewportHeight;
|
return _ViewportHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void RenderDevice::begin2D()
|
void RenderDevice::begin2D()
|
||||||
{
|
{
|
||||||
// prepare state
|
// prepare state
|
||||||
@ -81,7 +75,6 @@ void RenderDevice::begin2D()
|
|||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void RenderDevice::end2D()
|
void RenderDevice::end2D()
|
||||||
{
|
{
|
||||||
// restore projection matrix
|
// restore projection matrix
|
||||||
@ -97,13 +90,16 @@ void RenderDevice::end2D()
|
|||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void RenderDevice::clear()
|
void RenderDevice::clear()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
void RenderDevice::swap()
|
||||||
|
{
|
||||||
|
glfwSwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
void RenderDevice::setAmbientLight(float r, float g, float b)
|
void RenderDevice::setAmbientLight(float r, float g, float b)
|
||||||
{
|
{
|
||||||
GLfloat lightAmbient[] =
|
GLfloat lightAmbient[] =
|
||||||
@ -111,219 +107,80 @@ void RenderDevice::setAmbientLight(float r, float g, float b)
|
|||||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lightAmbient);
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lightAmbient);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
void RenderDevice::begin3D(Camera *camera)
|
||||||
/*
|
{
|
||||||
void RenderDevice::renderShadowVolume(Mesh *mesh,
|
_Camera = camera;
|
||||||
const Vector3Float &direction, const Vector3Float &extrude)
|
setupProjectionMatrix();
|
||||||
{
|
setupViewMatrix();
|
||||||
// Calculate visibility
|
}
|
||||||
unsigned int i, frontface_count = 0;
|
|
||||||
for (i=0; i < mesh->shadowfaces.count(); i++)
|
|
||||||
{
|
|
||||||
if (mesh->shadowfaces[i].plane.distance(extrude) < 0)
|
|
||||||
{
|
|
||||||
shadow_faces[i].backFace = false;
|
|
||||||
frontface_count++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
shadow_faces[i].backFace = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int max_edges = (frontface_count) * 3;
|
void RenderDevice::setupProjectionMatrix()
|
||||||
if (_extrudeVertexBuffer.count() < (max_edges * 4))
|
{
|
||||||
{
|
if (_Camera.valid())
|
||||||
clog << ">>> increase shadow buffers to "<< max_edges << " Edges"<< endline;
|
{
|
||||||
_extrudeVertexBuffer.create( (max_edges + 100) * 4);
|
Scalar fH = tan( (_Camera->getFov() / 2) / 180 * Pi)
|
||||||
}
|
* _Camera->getNearPlane();
|
||||||
|
Scalar fW = fH * _ViewportWidth / _ViewportHeight;
|
||||||
|
|
||||||
if (_extrudeIndexBuffer.count() < (max_edges * 6))
|
// setup projectiom matrix
|
||||||
_extrudeIndexBuffer.create( (max_edges + 100) * 6);
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
glFrustum( -fW, fW, -fH, fH, _Camera->getNearPlane(),
|
||||||
|
_Camera->getFarPlane());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fill the buffer
|
void RenderDevice::setupViewMatrix()
|
||||||
unsigned int j, k;
|
{
|
||||||
extrude_quad_count = 0;
|
// set the view matrix
|
||||||
Vertex *face_vertices[3];
|
glMatrixMode(GL_MODELVIEW);
|
||||||
for (i=0; i<shadow_faces.count(); i++)
|
glLoadIdentity();
|
||||||
{
|
Matrix4x4 m(_Camera->getRotation(), _Camera->getRotation().applyInversed(_Camera->getPosition() * -1.0) );
|
||||||
if (shadow_faces[i].backFace == false)
|
glMultMatrixd( ( GLdouble * ) &m.m );
|
||||||
{
|
/*
|
||||||
for (j=0; j<3; j++)
|
// calculate frustum planes
|
||||||
{
|
Vector3 up = q.apply ( Vector3 ( 0.0, 1.0, 0.0 ) );
|
||||||
k = shadow_faces[i].neighbours[j];
|
Vector3 right = q.apply ( Vector3 ( 1.0, 0.0, 0.0 ) );
|
||||||
if ( (k == 0) || (shadow_faces[k-1].backFace == true))
|
Vector3 d = q.apply ( Vector3 ( 0.0, 0.0, -1.0 ) );
|
||||||
{
|
|
||||||
unsigned int src_index_offset = i * 3;
|
|
||||||
face_vertices[0]
|
|
||||||
= &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset ] ];
|
|
||||||
face_vertices[1]
|
|
||||||
= &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset + 1] ];
|
|
||||||
face_vertices[2]
|
|
||||||
= &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset + 2] ];
|
|
||||||
|
|
||||||
#ifdef DEBUG_SILHOUETTE
|
Vector3 fc = p + d * _far;
|
||||||
glBegin( GL_LINES );
|
|
||||||
glVertex3f( face_vertices[j]->point.x, face_vertices[j]->point.y, face_vertices[j]->point.z );
|
|
||||||
glVertex3f( face_vertices[(j+1)%3]->point.x, face_vertices[(j+1)%3]->point.y, face_vertices[(j+1)%3]->point.z );
|
|
||||||
glEnd();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned int vertex_offset = extrude_quad_count*4;
|
Vector3 ftl = fc + ( up * _hFar ) - ( right * _wFar );
|
||||||
_extrudeVertexBuffer[vertex_offset] = face_vertices[j]->point;
|
Vector3 ftr = fc + ( up * _hFar ) + ( right * _wFar );
|
||||||
_extrudeVertexBuffer[vertex_offset+1] = face_vertices[(j+1)%3]->point;
|
Vector3 fbl = fc - ( up * _hFar ) - ( right * _wFar );
|
||||||
_extrudeVertexBuffer[vertex_offset+2] = face_vertices[(j+1)%3]->point + extrude_vector;
|
Vector3 fbr = fc - ( up * _hFar ) + ( right * _wFar );
|
||||||
_extrudeVertexBuffer[vertex_offset+3] = face_vertices[j]->point
|
|
||||||
+ extrude_vector;
|
|
||||||
|
|
||||||
unsigned int index_offset = extrude_quad_count*6;
|
Vector3 nc = p + d * _near;
|
||||||
_extrudeIndexBuffer[index_offset] = vertex_offset;
|
|
||||||
_extrudeIndexBuffer[index_offset+1] = vertex_offset + 3;
|
|
||||||
_extrudeIndexBuffer[index_offset+2] = vertex_offset + 1;
|
|
||||||
_extrudeIndexBuffer[index_offset+3] = vertex_offset + 1;
|
|
||||||
_extrudeIndexBuffer[index_offset+4] = vertex_offset + 3;
|
|
||||||
_extrudeIndexBuffer[index_offset+5] = vertex_offset + 2;
|
|
||||||
|
|
||||||
extrude_quad_count++;
|
Vector3 ntl = nc + ( up * _hNear ) - ( right * _wNear );
|
||||||
}
|
Vector3 ntr = nc + ( up * _hNear ) + ( right * _wNear );
|
||||||
}
|
Vector3 nbl = nc - ( up * _hNear ) - ( right * _wNear );
|
||||||
}
|
Vector3 nbr = nc - ( up * _hNear ) + ( right * _wNear );
|
||||||
|
|
||||||
}
|
_frustumPlanes[RightPlane] = Plane ( nbr, fbr, ntr );
|
||||||
|
_frustumPlanes[LeftPlane] = Plane ( ntl, fbl, nbl );
|
||||||
|
_frustumPlanes[BottomPlane] = Plane ( nbl, fbr, nbr );
|
||||||
|
_frustumPlanes[TopPlane] = Plane ( ntr, ftl, ntl );
|
||||||
|
_frustumPlanes[FarPlane] = Plane ( ftl, ftr, fbl );
|
||||||
|
_frustumPlanes[NearPlane] = Plane ( ntl, nbl, ntr );
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
if (_capIndexBuffer.count() < mesh->index_buffer.count() )
|
void RenderDevice::setTransformation (const Vector3& position, const Quaternion& orientation)
|
||||||
_capIndexBuffer.create(mesh->index_buffer.count() );
|
{
|
||||||
|
glMatrixMode ( GL_MODELVIEW );
|
||||||
|
glPushMatrix();
|
||||||
|
Matrix4x4 m ( orientation, position );
|
||||||
|
glMultMatrixd ( ( GLdouble * ) &m.m );
|
||||||
|
}
|
||||||
|
|
||||||
bf = 0;
|
#if 0
|
||||||
ff = 0;
|
void RenderDevice::setu
|
||||||
|
// set the view matrix
|
||||||
for (i=0; i<shadow_faces.count(); i++)
|
glMatrixMode (GL_MODELVIEW );
|
||||||
{
|
glLoadIdentity();
|
||||||
unsigned int dst_offset, src_offset = i*3;
|
Matrix4x4 m(_Rotation, _Rotation.applyInversed(_Position * -1.0) );
|
||||||
|
glMultMatrixd ( ( GLdouble * ) &m.m );
|
||||||
if (shadow_faces[i].backFace == false)
|
|
||||||
{
|
|
||||||
dst_offset = ff*3;
|
|
||||||
ff++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dst_offset = _capIndexBuffer.count() - (bf + 1)*3;
|
|
||||||
bf++;
|
|
||||||
}
|
|
||||||
|
|
||||||
_capIndexBuffer[dst_offset] = mesh->index_buffer[src_offset];
|
|
||||||
_capIndexBuffer[dst_offset+1] = mesh->index_buffer[src_offset+1];
|
|
||||||
_capIndexBuffer[dst_offset+2] = mesh->index_buffer[src_offset+2];
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastOrientation = _AbsoluteRotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_extrudeVertexBuffer.count() > 0)
|
|
||||||
{
|
|
||||||
// draw the volume
|
|
||||||
glPushAttrib( GL_ALL_ATTRIB_BITS);
|
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
|
|
||||||
glEnable( GL_DEPTH_TEST);
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
|
|
||||||
#if defined(DEBUG_SILHOUETTE) || defined(DEBUG_CAPS) || defined(DEBUG_VOLUME)
|
|
||||||
glColorMask( 1, 1, 1, 1 );
|
|
||||||
glDepthFunc(GL_LEQUAL);
|
|
||||||
#else
|
|
||||||
glColorMask(0, 0, 0, 0);
|
|
||||||
glDepthFunc(GL_LESS);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
glEnable(GL_STENCIL_TEST);
|
|
||||||
glStencilFunc(GL_ALWAYS, 0, ~0);
|
|
||||||
glStencilMask( ~0);
|
|
||||||
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
|
|
||||||
glMatrixMode ( GL_MODELVIEW);
|
|
||||||
glPushMatrix();
|
|
||||||
Matrix4x4 m(_AbsoluteRotation, _AbsoluteTranslation);
|
|
||||||
glMultMatrixd ( ( GLdouble * ) &m.m );
|
|
||||||
|
|
||||||
glActiveTextureARB ( GL_TEXTURE2_ARB);
|
|
||||||
glDisable ( GL_TEXTURE_2D);
|
|
||||||
glActiveTextureARB ( GL_TEXTURE1_ARB);
|
|
||||||
glDisable ( GL_TEXTURE_2D);
|
|
||||||
glActiveTextureARB ( GL_TEXTURE0_ARB);
|
|
||||||
glDisable ( GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
ShaderManager::getSingleton()->useShaderProgram( 0);
|
|
||||||
|
|
||||||
#ifndef DEBUG_SILHOUETTE
|
|
||||||
|
|
||||||
glEnableClientState( GL_VERTEX_ARRAY);
|
|
||||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState( GL_NORMAL_ARRAY);
|
|
||||||
glDisableClientState( GL_ARRAY_BUFFER_ARB);
|
|
||||||
glDisableClientState( GL_ELEMENT_ARRAY_BUFFER_ARB);
|
|
||||||
|
|
||||||
for (int p=0; p<2; p++)
|
|
||||||
{
|
|
||||||
if (p==0)
|
|
||||||
{
|
|
||||||
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
|
|
||||||
glCullFace(GL_FRONT);
|
|
||||||
//glColorMask(0, 1, 0, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
|
|
||||||
glCullFace(GL_BACK);
|
|
||||||
//glColorMask(1, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GLEW_ARB_vertex_buffer_object )
|
|
||||||
{
|
|
||||||
glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0);
|
|
||||||
glBindBufferARB ( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
|
||||||
}
|
|
||||||
// #if !defined(DEBUG_CAPS) || defined(DEBUG_VOLUME)
|
|
||||||
glVertexPointer ( 3, GL_FLOAT, 0, _extrudeVertexBuffer.data() );
|
|
||||||
glDrawElements (
|
|
||||||
GL_TRIANGLES,
|
|
||||||
extrude_quad_count * 6,
|
|
||||||
GL_UNSIGNED_SHORT,
|
|
||||||
_extrudeIndexBuffer.data());
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// #if !defined(DEBUG_VOLUME) || defined(DEBUG_CAPS)
|
|
||||||
// draw caps
|
|
||||||
mesh->vertex_buffer.bind();
|
|
||||||
//glVertexPointer ( 3, GL_FLOAT, sizeof(Vertex), mesh->vertex_buffer.data() );
|
|
||||||
glDrawElements (
|
|
||||||
GL_TRIANGLES,
|
|
||||||
ff*3,
|
|
||||||
GL_UNSIGNED_SHORT,
|
|
||||||
_capIndexBuffer.data());
|
|
||||||
//&_capIndexBuffer[_capIndexBuffer.count() - bf*3]);
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(extrude_vector.x, extrude_vector.y, extrude_vector.z);
|
|
||||||
glDrawElements (
|
|
||||||
GL_TRIANGLES,
|
|
||||||
bf*3,
|
|
||||||
GL_UNSIGNED_SHORT,
|
|
||||||
&_capIndexBuffer[_capIndexBuffer.count() - bf*3]);
|
|
||||||
//_capIndexBuffer.data() );
|
|
||||||
glPopMatrix();
|
|
||||||
// #endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
glPopAttrib();
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} // namespace BlueCore
|
} // namespace BlueCore
|
||||||
|
#endif
|
||||||
|
}
|
@ -2,7 +2,8 @@
|
|||||||
#define BLUECORE_RENDERDEVICE_H
|
#define BLUECORE_RENDERDEVICE_H
|
||||||
|
|
||||||
#include "RenderWindow.h"
|
#include "RenderWindow.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
#include "Material.h"
|
||||||
#include "Utilities/Buffer.h"
|
#include "Utilities/Buffer.h"
|
||||||
#include "Utilities/Referenced.h"
|
#include "Utilities/Referenced.h"
|
||||||
#include "Utilities/sigslot.h"
|
#include "Utilities/sigslot.h"
|
||||||
@ -12,45 +13,42 @@ namespace BlueCore
|
|||||||
|
|
||||||
class RenderDevice : public Referenced, public sigslot::has_slots<>
|
class RenderDevice : public Referenced, public sigslot::has_slots<>
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
|
int _ViewportWidth, _ViewportHeight;
|
||||||
|
|
||||||
class RenderItem
|
void WindowResizeSlot(int width, int height);
|
||||||
{
|
void WindowCloseSlot();
|
||||||
|
|
||||||
public:
|
ref_ptr<RenderWindow> _RenderWindow;
|
||||||
//virtual void render ( RenderPass pass ) = 0;
|
ref_ptr<Camera> _Camera;
|
||||||
virtual ~RenderItem()
|
|
||||||
{};
|
public:
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
int _ViewportWidth, _ViewportHeight;
|
|
||||||
|
|
||||||
void WindowResizeSlot(int width, int height);
|
RenderDevice(RenderWindow* renderWindow);
|
||||||
void WindowCloseSlot();
|
~RenderDevice();
|
||||||
|
|
||||||
ref_ptr<RenderWindow> _RenderWindow;
|
int getViewportWidth();
|
||||||
|
int getViewportHeight();
|
||||||
|
|
||||||
public:
|
void begin2D();
|
||||||
|
void end2D();
|
||||||
|
|
||||||
RenderDevice(RenderWindow* renderWindow);
|
void clear();
|
||||||
~RenderDevice();
|
void swap();
|
||||||
|
|
||||||
int getViewportWidth();
|
void setAmbientLight(float r, float g, float b);
|
||||||
int getViewportHeight();
|
void setMaterial(Material *);
|
||||||
|
|
||||||
void begin2D();
|
void setTexture(unsigned int unit, unsigned int texture);
|
||||||
void end2D();
|
void begin3D(Camera *);
|
||||||
|
void setTransformation (const Vector3&, const Quaternion&);
|
||||||
|
void setupProjectionMatrix();
|
||||||
|
void setupViewMatrix();
|
||||||
|
|
||||||
void clear();
|
sigslot::signal0<> DeviceShutdownSignal;
|
||||||
|
|
||||||
void setAmbientLight(float r, float g, float b);
|
|
||||||
|
//Buffer<ShadowFace> &_ShadowFaces;
|
||||||
void setTexture(unsigned int unit, unsigned int texture);
|
|
||||||
|
|
||||||
sigslot::signal0<> DeviceShutdownSignal;
|
|
||||||
|
|
||||||
//Buffer<ShadowFace> &_ShadowFaces;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespaced BlueCore
|
} // namespaced BlueCore
|
||||||
|
51
engine/RenderQueue.cpp
Normal file
51
engine/RenderQueue.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "RenderQueue.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
|
||||||
|
void RenderQueue::addOpaqueItem(RenderItem *item, const Vector3& position,
|
||||||
|
const Quaternion& orientation)
|
||||||
|
{
|
||||||
|
_OpaqueItems.push_back(QueueItem(item, position, orientation));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderQueue::addTransparentItem(RenderItem *item, const Vector3& position,
|
||||||
|
const Quaternion& orientation)
|
||||||
|
{
|
||||||
|
_TransparentItems.push_back(QueueItem(item, position, orientation));
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::list<RenderQueue::QueueItem>& RenderQueue::getOpaqueItems()
|
||||||
|
{
|
||||||
|
return _OpaqueItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::list<RenderQueue::QueueItem>& RenderQueue::getTransparentItems()
|
||||||
|
{
|
||||||
|
return _TransparentItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderQueue::clear()
|
||||||
|
{
|
||||||
|
_OpaqueItems.clear();
|
||||||
|
_TransparentItems.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderQueue::render(RenderDevice *device) const
|
||||||
|
{
|
||||||
|
std::list<QueueItem>::const_iterator i;
|
||||||
|
|
||||||
|
for (i = _OpaqueItems.begin(); i != _OpaqueItems.end(); i++)
|
||||||
|
{
|
||||||
|
device->setTransformation((*i).position, (*i).orientation);
|
||||||
|
(*i).item->render(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = _TransparentItems.begin(); i != _TransparentItems.end(); i++)
|
||||||
|
{
|
||||||
|
device->setTransformation((*i).position, (*i).orientation);
|
||||||
|
(*i).item->render(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
engine/RenderQueue.h
Normal file
52
engine/RenderQueue.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#ifndef BLUECORE_RENDER_QUEUE_H
|
||||||
|
#define BLUECORE_RENDER_QUEUE_H
|
||||||
|
|
||||||
|
#include "RenderDevice.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
class RenderItem : public Referenced
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void render(RenderDevice *) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RenderQueue : public Referenced
|
||||||
|
{
|
||||||
|
struct QueueItem
|
||||||
|
{
|
||||||
|
QueueItem(RenderItem *renderitem, const Vector3& vector,
|
||||||
|
const Quaternion& quat) :
|
||||||
|
item(renderitem), position(vector), orientation(quat)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ref_ptr<RenderItem> item;
|
||||||
|
Vector3 position;
|
||||||
|
Quaternion orientation;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::list<QueueItem> _OpaqueItems;
|
||||||
|
std::list<QueueItem> _TransparentItems;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void addOpaqueItem(RenderItem *item, const Vector3& position,
|
||||||
|
const Quaternion& orientation);
|
||||||
|
|
||||||
|
void addTransparentItem(RenderItem *item, const Vector3& position,
|
||||||
|
const Quaternion& orientation);
|
||||||
|
|
||||||
|
const std::list<QueueItem>& getOpaqueItems();
|
||||||
|
|
||||||
|
const std::list<QueueItem>& getTransparentItems();
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
void render(RenderDevice *device) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace BluewCore
|
||||||
|
|
||||||
|
#endif // BLUECORE_RENDER_QUEUE_H
|
@ -114,12 +114,6 @@ bool RenderWindow::create(int width, int height, int pixelbits, int depthbits,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void RenderWindow::swap()
|
|
||||||
{
|
|
||||||
glfwSwapBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void RenderWindow::destroy()
|
void RenderWindow::destroy()
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// library includes
|
// library includes
|
||||||
|
#include "GL/glew.h"
|
||||||
#include "GL/glfw.h"
|
#include "GL/glfw.h"
|
||||||
|
|
||||||
// project includes
|
// project includes
|
||||||
@ -63,8 +64,6 @@ class RenderWindow : public Referenced
|
|||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
||||||
bool isOpen();
|
bool isOpen();
|
||||||
|
|
||||||
void swap();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ static SQInteger _image_constructor(HSQUIRRELVM vm)
|
|||||||
sq_getfloat(vm, 6, &by );
|
sq_getfloat(vm, 6, &by );
|
||||||
|
|
||||||
Texture *texture = gTextureManager->loadTexture(texturename, 0, 0);
|
Texture *texture = gTextureManager->loadTexture(texturename, 0, 0);
|
||||||
image = new TextureImage( gRenderDevice.get(), texture, ax, ay, bx, by );
|
image = new TextureImage( gRenderDevice, texture, ax, ay, bx, by );
|
||||||
image->addReference();
|
image->addReference();
|
||||||
|
|
||||||
sq_setinstanceup(vm, 1, (void *)image );
|
sq_setinstanceup(vm, 1, (void *)image );
|
||||||
|
@ -30,7 +30,7 @@ void Kernel::setTaskPriority(KernelTask* task, int priority)
|
|||||||
std::list<KernelTaskContainer>::iterator i;
|
std::list<KernelTaskContainer>::iterator i;
|
||||||
for (i = _Tasks.begin(); i != _Tasks.end(); i++)
|
for (i = _Tasks.begin(); i != _Tasks.end(); i++)
|
||||||
{
|
{
|
||||||
if ((*i)._Task.get() == task)
|
if ((*i)._Task == task)
|
||||||
{
|
{
|
||||||
(*i)._Priority = priority;
|
(*i)._Priority = priority;
|
||||||
_Changed = true;
|
_Changed = true;
|
||||||
|
@ -137,6 +137,14 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator == (T* ref)
|
||||||
|
{
|
||||||
|
if (_Referenced == ref)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool valid() const
|
bool valid() const
|
||||||
{
|
{
|
||||||
return (_Referenced != 0);
|
return (_Referenced != 0);
|
||||||
@ -147,7 +155,7 @@ public:
|
|||||||
return _Referenced;
|
return _Referenced;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* get() const
|
T* pointer() const
|
||||||
{
|
{
|
||||||
return _Referenced;
|
return _Referenced;
|
||||||
}
|
}
|
||||||
@ -215,11 +223,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
T* get() const
|
T* pointer() const
|
||||||
{
|
{
|
||||||
return _Referenced;
|
return _Referenced;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator T*() const
|
||||||
|
{
|
||||||
|
return _Referenced;
|
||||||
|
}
|
||||||
|
|
||||||
void onDestruction(Referenced *referenced)
|
void onDestruction(Referenced *referenced)
|
||||||
{
|
{
|
||||||
|
@ -87,6 +87,7 @@ int main(int argc, char **argv)
|
|||||||
ref_ptr<RigidBodySimulation> simulation = new RigidBodySimulation(scriptsystem);
|
ref_ptr<RigidBodySimulation> simulation = new RigidBodySimulation(scriptsystem);
|
||||||
ref_ptr<ModelManager> modelmanager = new ModelManager (texturemanager, shadermanager, meshmanager);
|
ref_ptr<ModelManager> modelmanager = new ModelManager (texturemanager, shadermanager, meshmanager);
|
||||||
ref_ptr<Camera> camera = new Camera();
|
ref_ptr<Camera> camera = new Camera();
|
||||||
|
ref_ptr<RenderQueue> queue = new RenderQueue();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ShaderProgram prog =
|
ShaderProgram prog =
|
||||||
@ -130,15 +131,16 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
while (window->isOpen())
|
while (window->isOpen())
|
||||||
{
|
{
|
||||||
device->clear();
|
|
||||||
double time = glfwGetTime();
|
double time = glfwGetTime();
|
||||||
_DeltaTime = time - _LastTime;
|
_DeltaTime = time - _LastTime;
|
||||||
_LastTime = time;
|
_LastTime = time;
|
||||||
|
|
||||||
// device->setViewMatrix();
|
device->clear();
|
||||||
// device->setProjectionMatrix();
|
device->begin3D(camera);
|
||||||
camera->setupProjectionMatrix();
|
|
||||||
camera->setupViewMatrix();
|
queue->clear();
|
||||||
|
queue->addOpaqueItem(model, Vector3(10.0, 0.0, 0.0), Quaternion(Vector3(0.0,1.0,0.0), fmod(time, 3)));
|
||||||
|
queue->render(device);
|
||||||
|
|
||||||
// device->useShader (program);
|
// device->useShader (program);
|
||||||
// device->setTexture (stage, name, texture)
|
// device->setTexture (stage, name, texture)
|
||||||
@ -148,7 +150,8 @@ int main(int argc, char **argv)
|
|||||||
//glBindTexture (GL_TEXTURE_2D, texture->getId() );
|
//glBindTexture (GL_TEXTURE_2D, texture->getId() );
|
||||||
|
|
||||||
// device->
|
// device->
|
||||||
model->render();
|
//device->
|
||||||
|
//model->render();
|
||||||
|
|
||||||
simulation->saveStates();
|
simulation->saveStates();
|
||||||
simulation->updateSteps(_DeltaTime);
|
simulation->updateSteps(_DeltaTime);
|
||||||
@ -156,7 +159,7 @@ int main(int argc, char **argv)
|
|||||||
;
|
;
|
||||||
scriptsystem->callFunction("OnFrame", _DeltaTime);
|
scriptsystem->callFunction("OnFrame", _DeltaTime);
|
||||||
|
|
||||||
window->swap();
|
device->swap();
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptsystem->callFunction("Shutdown");
|
scriptsystem->callFunction("Shutdown");
|
||||||
|
241
engine/todo.txt
241
engine/todo.txt
@ -10,4 +10,243 @@ Scripting
|
|||||||
|
|
||||||
* make ShaderProgram a class
|
* make ShaderProgram a class
|
||||||
* create RenderSet AND/OR RenderQueue
|
* create RenderSet AND/OR RenderQueue
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/*
|
||||||
|
void RenderDevice::renderShadowVolume(Mesh *mesh,
|
||||||
|
const Vector3Float &direction, const Vector3Float &extrude)
|
||||||
|
{
|
||||||
|
// Calculate visibility
|
||||||
|
unsigned int i, frontface_count = 0;
|
||||||
|
for (i=0; i < mesh->shadowfaces.count(); i++)
|
||||||
|
{
|
||||||
|
if (mesh->shadowfaces[i].plane.distance(extrude) < 0)
|
||||||
|
{
|
||||||
|
shadow_faces[i].backFace = false;
|
||||||
|
frontface_count++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shadow_faces[i].backFace = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int max_edges = (frontface_count) * 3;
|
||||||
|
if (_extrudeVertexBuffer.count() < (max_edges * 4))
|
||||||
|
{
|
||||||
|
clog << ">>> increase shadow buffers to "<< max_edges << " Edges"<< endline;
|
||||||
|
_extrudeVertexBuffer.create( (max_edges + 100) * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_extrudeIndexBuffer.count() < (max_edges * 6))
|
||||||
|
_extrudeIndexBuffer.create( (max_edges + 100) * 6);
|
||||||
|
|
||||||
|
// fill the buffer
|
||||||
|
unsigned int j, k;
|
||||||
|
extrude_quad_count = 0;
|
||||||
|
Vertex *face_vertices[3];
|
||||||
|
for (i=0; i<shadow_faces.count(); i++)
|
||||||
|
{
|
||||||
|
if (shadow_faces[i].backFace == false)
|
||||||
|
{
|
||||||
|
for (j=0; j<3; j++)
|
||||||
|
{
|
||||||
|
k = shadow_faces[i].neighbours[j];
|
||||||
|
if ( (k == 0) || (shadow_faces[k-1].backFace == true))
|
||||||
|
{
|
||||||
|
unsigned int src_index_offset = i * 3;
|
||||||
|
face_vertices[0]
|
||||||
|
= &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset ] ];
|
||||||
|
face_vertices[1]
|
||||||
|
= &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset + 1] ];
|
||||||
|
face_vertices[2]
|
||||||
|
= &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset + 2] ];
|
||||||
|
|
||||||
|
#ifdef DEBUG_SILHOUETTE
|
||||||
|
glBegin( GL_LINES );
|
||||||
|
glVertex3f( face_vertices[j]->point.x, face_vertices[j]->point.y, face_vertices[j]->point.z );
|
||||||
|
glVertex3f( face_vertices[(j+1)%3]->point.x, face_vertices[(j+1)%3]->point.y, face_vertices[(j+1)%3]->point.z );
|
||||||
|
glEnd();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned int vertex_offset = extrude_quad_count*4;
|
||||||
|
_extrudeVertexBuffer[vertex_offset] = face_vertices[j]->point;
|
||||||
|
_extrudeVertexBuffer[vertex_offset+1] = face_vertices[(j+1)%3]->point;
|
||||||
|
_extrudeVertexBuffer[vertex_offset+2] = face_vertices[(j+1)%3]->point + extrude_vector;
|
||||||
|
_extrudeVertexBuffer[vertex_offset+3] = face_vertices[j]->point
|
||||||
|
+ extrude_vector;
|
||||||
|
|
||||||
|
unsigned int index_offset = extrude_quad_count*6;
|
||||||
|
_extrudeIndexBuffer[index_offset] = vertex_offset;
|
||||||
|
_extrudeIndexBuffer[index_offset+1] = vertex_offset + 3;
|
||||||
|
_extrudeIndexBuffer[index_offset+2] = vertex_offset + 1;
|
||||||
|
_extrudeIndexBuffer[index_offset+3] = vertex_offset + 1;
|
||||||
|
_extrudeIndexBuffer[index_offset+4] = vertex_offset + 3;
|
||||||
|
_extrudeIndexBuffer[index_offset+5] = vertex_offset + 2;
|
||||||
|
|
||||||
|
extrude_quad_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_capIndexBuffer.count() < mesh->index_buffer.count() )
|
||||||
|
_capIndexBuffer.create(mesh->index_buffer.count() );
|
||||||
|
|
||||||
|
bf = 0;
|
||||||
|
ff = 0;
|
||||||
|
|
||||||
|
for (i=0; i<shadow_faces.count(); i++)
|
||||||
|
{
|
||||||
|
unsigned int dst_offset, src_offset = i*3;
|
||||||
|
|
||||||
|
if (shadow_faces[i].backFace == false)
|
||||||
|
{
|
||||||
|
dst_offset = ff*3;
|
||||||
|
ff++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dst_offset = _capIndexBuffer.count() - (bf + 1)*3;
|
||||||
|
bf++;
|
||||||
|
}
|
||||||
|
|
||||||
|
_capIndexBuffer[dst_offset] = mesh->index_buffer[src_offset];
|
||||||
|
_capIndexBuffer[dst_offset+1] = mesh->index_buffer[src_offset+1];
|
||||||
|
_capIndexBuffer[dst_offset+2] = mesh->index_buffer[src_offset+2];
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastOrientation = _AbsoluteRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_extrudeVertexBuffer.count() > 0)
|
||||||
|
{
|
||||||
|
// draw the volume
|
||||||
|
glPushAttrib( GL_ALL_ATTRIB_BITS);
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
glEnable( GL_DEPTH_TEST);
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
|
#if defined(DEBUG_SILHOUETTE) || defined(DEBUG_CAPS) || defined(DEBUG_VOLUME)
|
||||||
|
glColorMask( 1, 1, 1, 1 );
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
#else
|
||||||
|
glColorMask(0, 0, 0, 0);
|
||||||
|
glDepthFunc(GL_LESS);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
glEnable(GL_STENCIL_TEST);
|
||||||
|
glStencilFunc(GL_ALWAYS, 0, ~0);
|
||||||
|
glStencilMask( ~0);
|
||||||
|
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
glMatrixMode ( GL_MODELVIEW);
|
||||||
|
glPushMatrix();
|
||||||
|
Matrix4x4 m(_AbsoluteRotation, _AbsoluteTranslation);
|
||||||
|
glMultMatrixd ( ( GLdouble * ) &m.m );
|
||||||
|
|
||||||
|
glActiveTextureARB ( GL_TEXTURE2_ARB);
|
||||||
|
glDisable ( GL_TEXTURE_2D);
|
||||||
|
glActiveTextureARB ( GL_TEXTURE1_ARB);
|
||||||
|
glDisable ( GL_TEXTURE_2D);
|
||||||
|
glActiveTextureARB ( GL_TEXTURE0_ARB);
|
||||||
|
glDisable ( GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
ShaderManager::getSingleton()->useShaderProgram( 0);
|
||||||
|
|
||||||
|
#ifndef DEBUG_SILHOUETTE
|
||||||
|
|
||||||
|
glEnableClientState( GL_VERTEX_ARRAY);
|
||||||
|
glDisableClientState( GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glDisableClientState( GL_NORMAL_ARRAY);
|
||||||
|
glDisableClientState( GL_ARRAY_BUFFER_ARB);
|
||||||
|
glDisableClientState( GL_ELEMENT_ARRAY_BUFFER_ARB);
|
||||||
|
|
||||||
|
for (int p=0; p<2; p++)
|
||||||
|
{
|
||||||
|
if (p==0)
|
||||||
|
{
|
||||||
|
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
|
||||||
|
glCullFace(GL_FRONT);
|
||||||
|
//glColorMask(0, 1, 0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
//glColorMask(1, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GLEW_ARB_vertex_buffer_object )
|
||||||
|
{
|
||||||
|
glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0);
|
||||||
|
glBindBufferARB ( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
||||||
|
}
|
||||||
|
// #if !defined(DEBUG_CAPS) || defined(DEBUG_VOLUME)
|
||||||
|
glVertexPointer ( 3, GL_FLOAT, 0, _extrudeVertexBuffer.data() );
|
||||||
|
glDrawElements (
|
||||||
|
GL_TRIANGLES,
|
||||||
|
extrude_quad_count * 6,
|
||||||
|
GL_UNSIGNED_SHORT,
|
||||||
|
_extrudeIndexBuffer.data());
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #if !defined(DEBUG_VOLUME) || defined(DEBUG_CAPS)
|
||||||
|
// draw caps
|
||||||
|
mesh->vertex_buffer.bind();
|
||||||
|
//glVertexPointer ( 3, GL_FLOAT, sizeof(Vertex), mesh->vertex_buffer.data() );
|
||||||
|
glDrawElements (
|
||||||
|
GL_TRIANGLES,
|
||||||
|
ff*3,
|
||||||
|
GL_UNSIGNED_SHORT,
|
||||||
|
_capIndexBuffer.data());
|
||||||
|
//&_capIndexBuffer[_capIndexBuffer.count() - bf*3]);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(extrude_vector.x, extrude_vector.y, extrude_vector.z);
|
||||||
|
glDrawElements (
|
||||||
|
GL_TRIANGLES,
|
||||||
|
bf*3,
|
||||||
|
GL_UNSIGNED_SHORT,
|
||||||
|
&_capIndexBuffer[_capIndexBuffer.count() - bf*3]);
|
||||||
|
//_capIndexBuffer.data() );
|
||||||
|
glPopMatrix();
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
glPopAttrib();
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Scalar fW, fH;
|
||||||
|
|
||||||
|
fH = tan ( (_FoV / 2) / 180* Pi ) * _NearPlane;
|
||||||
|
fW = fH * _AspectRatio;
|
||||||
|
|
||||||
|
// setup projectiom matrix
|
||||||
|
glMatrixMode (GL_PROJECTION );
|
||||||
|
glLoadIdentity();
|
||||||
|
glFrustum ( -fW, fW, -fH, fH, _NearPlane, _FarPlane );
|
||||||
|
|
||||||
|
// save variables for frustum culling
|
||||||
|
/*
|
||||||
|
_near = nearZ;
|
||||||
|
_far = farZ;
|
||||||
|
_hNear = tan ( ( fov / 2 ) / 180 * Pi ) * nearZ;
|
||||||
|
_wNear = _hNear * aspect;
|
||||||
|
_hFar = tan ( ( fov / 2 ) / 180 * Pi ) * farZ;
|
||||||
|
_wFar = _hFar * aspect;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user