leocad/common/lc_context.h

213 lines
4.5 KiB
C
Raw Normal View History

2014-04-14 05:20:16 +02:00
#ifndef _LC_CONTEXT_H_
#define _LC_CONTEXT_H_
2014-04-20 03:50:41 +02:00
#include "lc_array.h"
#include "lc_math.h"
2015-05-04 02:51:41 +02:00
#include "lc_colors.h"
2014-04-20 03:50:41 +02:00
2015-02-08 19:54:51 +01:00
class lcScene
2014-11-24 00:48:56 +01:00
{
2015-02-08 19:54:51 +01:00
public:
lcScene();
void Begin(const lcMatrix44& ViewMatrix);
void End();
lcMatrix44 mViewMatrix;
lcArray<lcRenderMesh> mOpaqueMeshes;
lcArray<lcRenderMesh> mTranslucentMeshes;
lcArray<lcObject*> mInterfaceObjects;
2014-11-24 00:48:56 +01: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;
};
};
2015-05-17 01:04:35 +02:00
enum lcProgramType
{
LC_PROGRAM_SIMPLE,
LC_PROGRAM_TEXTURE,
LC_PROGRAM_VERTEX_COLOR,
LC_NUM_PROGRAMS
};
enum lcProgramAttrib
{
LC_ATTRIB_POSITION,
LC_ATTRIB_TEXCOORD,
LC_ATTRIB_COLOR
};
struct lcProgram
{
GLuint Object;
GLint MatrixLocation;
GLint ColorLocation;
};
2014-04-14 05:20:16 +02:00
class lcContext
{
public:
lcContext();
~lcContext();
int GetViewportWidth() const
{
return mViewportWidth;
}
int GetViewportHeight() const
{
return mViewportHeight;
}
2015-05-17 01:04:35 +02:00
static void CreateResources();
static void DestroyResources();
2014-04-16 02:29:54 +02:00
void SetDefaultState();
2015-05-17 01:04:35 +02:00
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;
}
void SetProgram(lcProgramType ProgramType);
void SetViewport(int x, int y, int Width, int Height);
2014-04-14 05:20:16 +02:00
void SetLineWidth(float LineWidth);
2015-05-17 01:04:35 +02:00
void SetColor(const lcVector4& Color)
{
mColor = Color;
mColorDirty = true;
}
2015-05-04 02:51:41 +02:00
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);
2014-10-12 01:26:23 +02:00
bool BeginRenderToTexture(int Width, int Height);
void EndRenderToTexture();
bool SaveRenderToTextureImage(const QString& FileName, int Width, int Height);
2014-10-12 01:26:23 +02:00
lcVertexBuffer CreateVertexBuffer(int Size, const void* Data);
void DestroyVertexBuffer(lcVertexBuffer& VertexBuffer);
lcIndexBuffer CreateIndexBuffer(int Size, const void* Data);
void DestroyIndexBuffer(lcIndexBuffer& IndexBuffer);
2015-04-14 06:14:10 +02:00
void ClearVertexBuffer();
void SetVertexBuffer(lcVertexBuffer VertexBuffer);
2015-04-14 06:14:10 +02:00
void SetVertexBufferPointer(const void* VertexBuffer);
void ClearIndexBuffer();
void SetIndexBuffer(lcIndexBuffer IndexBuffer);
void SetIndexBufferPointer(const void* IndexBuffer);
2015-04-14 06:14:10 +02:00
void SetVertexFormat(int BufferOffset, int PositionSize, int TexCoordSize, int ColorSize);
void DrawPrimitives(GLenum Mode, GLint First, GLsizei Count);
void DrawIndexedPrimitives(GLenum Mode, GLsizei Count, GLenum Type, int Offset);
2015-04-14 06:14:10 +02:00
2014-04-14 05:20:16 +02:00
void UnbindMesh();
void DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section);
2015-05-17 01:04:35 +02:00
void DrawOpaqueMeshes(const lcArray<lcRenderMesh>& OpaqueMeshes);
void DrawTranslucentMeshes(const lcArray<lcRenderMesh>& TranslucentMeshes);
void DrawInterfaceObjects(const lcArray<lcObject*>& InterfaceObjects);
2014-04-14 05:20:16 +02:00
protected:
2015-05-17 01:04:35 +02:00
static void CreateShaderPrograms();
void BindMesh(lcMesh* Mesh);
2015-05-17 01:04:35 +02:00
void FlushState();
2014-04-14 05:20:16 +02:00
GLuint mVertexBufferObject;
GLuint mIndexBufferObject;
char* mVertexBufferPointer;
char* mIndexBufferPointer;
char* mVertexBufferOffset;
2015-05-17 01:04:35 +02:00
lcProgramType mProgramType;
2015-04-14 06:14:10 +02:00
bool mTexCoordEnabled;
bool mColorEnabled;
2014-04-14 05:20:16 +02:00
lcTexture* mTexture;
float mLineWidth;
int mMatrixMode;
2014-10-12 01:26:23 +02:00
int mViewportX;
int mViewportY;
int mViewportWidth;
int mViewportHeight;
2015-05-17 01:04:35 +02:00
lcVector4 mColor;
lcMatrix44 mWorldMatrix;
lcMatrix44 mViewMatrix;
lcMatrix44 mProjectionMatrix;
lcMatrix44 mViewProjectionMatrix;
bool mColorDirty;
bool mWorldMatrixDirty;
bool mViewMatrixDirty;
bool mProjectionMatrixDirty;
bool mViewProjectionMatrixDirty;
2014-10-12 01:26:23 +02:00
GLuint mFramebufferObject;
GLuint mFramebufferTexture;
GLuint mDepthRenderbufferObject;
2015-05-17 01:04:35 +02:00
static lcProgram mPrograms[LC_NUM_PROGRAMS];
Q_DECLARE_TR_FUNCTIONS(lcContext);
2014-04-14 05:20:16 +02:00
};
#endif // _LC_CONTEXT_H_