2016-10-05 23:28:52 +02:00
|
|
|
#ifndef _LC_CONTEXT_H_
|
|
|
|
#define _LC_CONTEXT_H_
|
|
|
|
|
|
|
|
#include "lc_array.h"
|
|
|
|
#include "lc_math.h"
|
|
|
|
#include "lc_colors.h"
|
|
|
|
#include "lc_mesh.h"
|
|
|
|
|
|
|
|
class lcScene
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcScene();
|
|
|
|
|
|
|
|
void Begin(const lcMatrix44& ViewMatrix);
|
|
|
|
void End();
|
2017-03-23 07:35:02 +01:00
|
|
|
void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State, int Flags);
|
2016-10-05 23:28:52 +02:00
|
|
|
|
|
|
|
lcMatrix44 mViewMatrix;
|
2017-03-20 06:59:55 +01:00
|
|
|
lcArray<lcRenderMesh> mRenderMeshes;
|
|
|
|
lcArray<int> mOpaqueMeshes;
|
|
|
|
lcArray<int> mTranslucentMeshes;
|
2016-10-05 23:28:52 +02:00
|
|
|
lcArray<const lcObject*> mInterfaceObjects;
|
2017-03-23 07:35:02 +01:00
|
|
|
bool mHasTexture;
|
2016-10-05 23:28:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class lcVertexBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcVertexBuffer()
|
|
|
|
: Pointer(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValid() const
|
|
|
|
{
|
|
|
|
return Pointer != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
GLuint Object;
|
|
|
|
void* Pointer;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
class lcIndexBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcIndexBuffer()
|
|
|
|
: Pointer(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValid() const
|
|
|
|
{
|
|
|
|
return Pointer != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
GLuint Object;
|
|
|
|
void* Pointer;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-02-18 20:12:35 +01:00
|
|
|
|
2017-03-01 00:20:34 +01:00
|
|
|
enum lcMaterialType
|
2016-10-05 23:28:52 +02:00
|
|
|
{
|
2017-03-12 21:51:14 +01:00
|
|
|
LC_MATERIAL_UNLIT_COLOR,
|
|
|
|
LC_MATERIAL_UNLIT_TEXTURE_MODULATE,
|
|
|
|
LC_MATERIAL_UNLIT_TEXTURE_DECAL,
|
|
|
|
LC_MATERIAL_UNLIT_VERTEX_COLOR,
|
|
|
|
LC_MATERIAL_FAKELIT_COLOR,
|
|
|
|
LC_MATERIAL_FAKELIT_TEXTURE_DECAL,
|
2017-03-01 00:20:34 +01:00
|
|
|
LC_NUM_MATERIALS
|
2016-10-05 23:28:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum lcProgramAttrib
|
|
|
|
{
|
2017-02-18 20:12:35 +01:00
|
|
|
LC_ATTRIB_POSITION,
|
|
|
|
LC_ATTRIB_NORMAL,
|
|
|
|
LC_ATTRIB_TEXCOORD,
|
2016-10-05 23:28:52 +02:00
|
|
|
LC_ATTRIB_COLOR
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lcProgram
|
|
|
|
{
|
|
|
|
GLuint Object;
|
2017-03-12 01:47:21 +01:00
|
|
|
GLint WorldViewProjectionMatrixLocation;
|
|
|
|
GLint WorldMatrixLocation;
|
|
|
|
GLint MaterialColorLocation;
|
|
|
|
GLint LightPositionLocation;
|
|
|
|
GLint EyePositionLocation;
|
2016-10-05 23:28:52 +02:00
|
|
|
};
|
|
|
|
|
2017-02-11 18:46:21 +01:00
|
|
|
enum lcTextureMode
|
|
|
|
{
|
|
|
|
LC_TEXTURE_DECAL,
|
|
|
|
LC_TEXTURE_MODULATE
|
|
|
|
};
|
|
|
|
|
2016-10-05 23:28:52 +02:00
|
|
|
class lcContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcContext();
|
|
|
|
~lcContext();
|
|
|
|
|
|
|
|
static void CreateResources();
|
|
|
|
static void DestroyResources();
|
|
|
|
|
|
|
|
void SetDefaultState();
|
|
|
|
|
|
|
|
void SetWorldMatrix(const lcMatrix44& WorldMatrix)
|
|
|
|
{
|
|
|
|
mWorldMatrix = WorldMatrix;
|
|
|
|
mWorldMatrixDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetViewMatrix(const lcMatrix44& ViewMatrix)
|
|
|
|
{
|
|
|
|
mViewMatrix = ViewMatrix;
|
|
|
|
mViewMatrixDirty = true;
|
|
|
|
mViewProjectionMatrixDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetProjectionMatrix(const lcMatrix44& ProjectionMatrix)
|
|
|
|
{
|
|
|
|
mProjectionMatrix = ProjectionMatrix;
|
|
|
|
mProjectionMatrixDirty = true;
|
|
|
|
mViewProjectionMatrixDirty = true;
|
|
|
|
}
|
|
|
|
|
2017-03-01 00:20:34 +01:00
|
|
|
void SetMaterial(lcMaterialType MaterialType);
|
2016-10-05 23:28:52 +02:00
|
|
|
void SetViewport(int x, int y, int Width, int Height);
|
|
|
|
void SetLineWidth(float LineWidth);
|
2017-02-11 18:46:21 +01:00
|
|
|
void SetTextureMode(lcTextureMode TextureMode);
|
2016-10-05 23:28:52 +02:00
|
|
|
|
|
|
|
void SetColor(const lcVector4& Color)
|
|
|
|
{
|
|
|
|
mColor = Color;
|
|
|
|
mColorDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetColor(float Red, float Green, float Blue, float Alpha);
|
|
|
|
void SetColorIndex(int ColorIndex);
|
|
|
|
void SetColorIndexTinted(int ColorIndex, lcInterfaceColor InterfaceColor);
|
|
|
|
void SetEdgeColorIndex(int ColorIndex);
|
|
|
|
void SetInterfaceColor(lcInterfaceColor InterfaceColor);
|
|
|
|
|
|
|
|
bool BeginRenderToTexture(int Width, int Height);
|
|
|
|
void EndRenderToTexture();
|
2016-12-16 18:14:19 +01:00
|
|
|
QImage GetRenderToTextureImage(int Width, int Height);
|
2016-10-05 23:28:52 +02:00
|
|
|
bool SaveRenderToTextureImage(const QString& FileName, int Width, int Height);
|
|
|
|
|
|
|
|
lcVertexBuffer CreateVertexBuffer(int Size, const void* Data);
|
|
|
|
void DestroyVertexBuffer(lcVertexBuffer& VertexBuffer);
|
|
|
|
lcIndexBuffer CreateIndexBuffer(int Size, const void* Data);
|
|
|
|
void DestroyIndexBuffer(lcIndexBuffer& IndexBuffer);
|
|
|
|
|
|
|
|
void ClearVertexBuffer();
|
|
|
|
void SetVertexBuffer(lcVertexBuffer VertexBuffer);
|
|
|
|
void SetVertexBufferPointer(const void* VertexBuffer);
|
|
|
|
|
|
|
|
void ClearIndexBuffer();
|
|
|
|
void SetIndexBuffer(lcIndexBuffer IndexBuffer);
|
|
|
|
void SetIndexBufferPointer(const void* IndexBuffer);
|
|
|
|
|
2017-02-18 20:12:35 +01:00
|
|
|
void SetVertexFormat(int BufferOffset, int PositionSize, int NormalSize, int TexCoordSize, int ColorSize);
|
2016-10-05 23:28:52 +02:00
|
|
|
void DrawPrimitives(GLenum Mode, GLint First, GLsizei Count);
|
|
|
|
void DrawIndexedPrimitives(GLenum Mode, GLsizei Count, GLenum Type, int Offset);
|
|
|
|
|
|
|
|
void UnbindMesh();
|
2017-03-17 23:53:26 +01:00
|
|
|
void DrawScene(const lcScene& Scene);
|
2016-10-05 23:28:52 +02:00
|
|
|
void DrawInterfaceObjects(const lcArray<const lcObject*>& InterfaceObjects);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void CreateShaderPrograms();
|
|
|
|
void BindMesh(lcMesh* Mesh);
|
|
|
|
void FlushState();
|
|
|
|
|
2017-03-17 23:53:26 +01:00
|
|
|
void DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section);
|
2017-03-20 06:59:55 +01:00
|
|
|
void DrawOpaqueMeshes(const lcScene& Scene);
|
|
|
|
void DrawTranslucentMeshes(const lcScene& Scene);
|
2017-03-23 07:35:02 +01:00
|
|
|
void DrawRenderMeshes(const lcArray<lcRenderMesh>& RenderMeshes, const lcArray<int>& Meshes, lcMeshPrimitiveType PrimitiveType, bool DrawTranslucent, bool DrawTextured);
|
2017-03-17 23:53:26 +01:00
|
|
|
|
2016-10-05 23:28:52 +02:00
|
|
|
GLuint mVertexBufferObject;
|
|
|
|
GLuint mIndexBufferObject;
|
|
|
|
char* mVertexBufferPointer;
|
|
|
|
char* mIndexBufferPointer;
|
|
|
|
char* mVertexBufferOffset;
|
|
|
|
|
2017-03-01 00:20:34 +01:00
|
|
|
lcMaterialType mMaterialType;
|
2017-02-18 20:12:35 +01:00
|
|
|
bool mNormalEnabled;
|
2016-10-05 23:28:52 +02:00
|
|
|
bool mTexCoordEnabled;
|
|
|
|
bool mColorEnabled;
|
|
|
|
|
|
|
|
lcTexture* mTexture;
|
|
|
|
float mLineWidth;
|
|
|
|
int mMatrixMode;
|
|
|
|
|
|
|
|
lcVector4 mColor;
|
|
|
|
lcMatrix44 mWorldMatrix;
|
|
|
|
lcMatrix44 mViewMatrix;
|
|
|
|
lcMatrix44 mProjectionMatrix;
|
|
|
|
lcMatrix44 mViewProjectionMatrix;
|
|
|
|
bool mColorDirty;
|
|
|
|
bool mWorldMatrixDirty;
|
|
|
|
bool mViewMatrixDirty;
|
|
|
|
bool mProjectionMatrixDirty;
|
|
|
|
bool mViewProjectionMatrixDirty;
|
|
|
|
|
|
|
|
GLuint mFramebufferObject;
|
|
|
|
GLuint mFramebufferTexture;
|
|
|
|
GLuint mDepthRenderbufferObject;
|
|
|
|
|
2017-03-12 21:51:14 +01:00
|
|
|
static lcProgram mPrograms[LC_NUM_MATERIALS];
|
2016-10-05 23:28:52 +02:00
|
|
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(lcContext);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _LC_CONTEXT_H_
|