22#ifndef HPL_LOW_LEVEL_GRAPHICS_TGL_H
23#define HPL_LOW_LEVEL_GRAPHICS_TGL_H
25#include "common/ptr.h"
26#include "graphics/pixelformat.h"
27#include "graphics/surface.h"
28#include "graphics/tinygl/tinygl.h"
29#include "hpl1/engine/graphics/LowLevelGraphics.h"
30#include "hpl1/engine/math/MathTypes.h"
36TGLenum TextureTargetToTGL(eTextureTarget target);
38TGLenum GetTGLTextureTargetEnum(eTextureTarget type);
42class LowLevelGraphicsTGL :
public iLowLevelGraphics {
44 LowLevelGraphicsTGL();
45 ~LowLevelGraphicsTGL();
47 bool Init(
int alWidth,
int alHeight,
int alBpp,
int abFullscreen,
int alMultisampling,
48 const tString &asWindowCaption);
50 int GetCaps(eGraphicCaps aType)
const;
52 void ShowCursor(
bool abX);
54 void SetMultisamplingActive(
bool abX);
56 void SetGammaCorrection(
float afX);
57 float GetGammaCorrection();
59 int GetMultisampling() {
return mlMultisampling; }
61 void SetClipPlane(
int alIdx,
const cPlanef &aPlane);
62 cPlanef GetClipPlane(
int alIdx,
const cPlanef &aPlane);
63 void SetClipPlaneActive(
int alIdx,
bool abX);
65 cVector2f GetScreenSize();
66 cVector2f GetVirtualSize();
67 void SetVirtualSize(cVector2f avSize);
69 Bitmap2D *CreateBitmap2D(
const cVector2l &avSize);
70 FontData *CreateFontData(
const tString &asName);
72 iTexture *CreateTexture(
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
73 iTexture *CreateTexture(
const tString &asName,
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
74 iTexture *CreateTexture(Bitmap2D *apBmp,
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
75 iTexture *CreateTexture(
const cVector2l &avSize,
int alBpp, cColor aFillCol,
76 bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
80 iGpuProgram *CreateGpuProgram(
const tString &vertex,
const tString &fragment);
82 void SaveScreenToBMP(
const tString &asFile);
86 void PushMatrix(eMatrix aMtxType);
87 void PopMatrix(eMatrix aMtxType);
88 void SetIdentityMatrix(eMatrix aMtxType);
90 void SetMatrix(eMatrix aMtxType,
const cMatrixf &a_mtxA);
92 void TranslateMatrix(eMatrix aMtxType,
const cVector3f &avPos);
93 void RotateMatrix(eMatrix aMtxType,
const cVector3f &avRot);
94 void ScaleMatrix(eMatrix aMtxType,
const cVector3f &avScale);
96 void SetOrthoProjection(
const cVector2f &avSize,
float afMin,
float afMax);
101 iOcclusionQuery *CreateOcclusionQuery();
102 void DestroyOcclusionQuery(iOcclusionQuery *apQuery);
107 void SetClearColor(
const cColor &aCol);
108 void SetClearDepth(
float afDepth);
109 void SetClearStencil(
int alVal);
111 void SetClearColorActive(
bool abX);
112 void SetClearDepthActive(
bool abX);
113 void SetClearStencilActive(
bool abX);
115 void SetColorWriteActive(
bool abR,
bool abG,
bool abB,
bool abA);
116 void SetDepthWriteActive(
bool abX);
118 void SetCullActive(
bool abX);
119 void SetCullMode(eCullMode aMode);
122 void SetDepthTestActive(
bool abX);
123 void SetDepthTestFunc(eDepthTestFunc aFunc);
126 void SetAlphaTestActive(
bool abX);
127 void SetAlphaTestFunc(eAlphaTestFunc aFunc,
float afRef);
130 void SetStencilActive(
bool abX);
131 void SetStencil(eStencilFunc aFunc,
int alRef,
unsigned int aMask,
132 eStencilOp aFailOp, eStencilOp aZFailOp, eStencilOp aZPassOp);
133 void SetStencilTwoSide(eStencilFunc aFrontFunc, eStencilFunc aBackFunc,
134 int alRef,
unsigned int aMask,
135 eStencilOp aFrontFailOp, eStencilOp aFrontZFailOp, eStencilOp aFrontZPassOp,
136 eStencilOp aBackFailOp, eStencilOp aBackZFailOp, eStencilOp aBackZPassOp);
137 void SetStencilTwoSide(
bool abX);
140 void SetScissorActive(
bool abX);
141 void SetScissorRect(
const cRect2l &aRect);
144 void SetBlendActive(
bool abX);
145 void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor);
146 void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
147 eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha);
150 void SetTexture(
unsigned int alUnit, iTexture *apTex);
151 void SetActiveTextureUnit(
unsigned int alUnit);
152 void SetTextureEnv(eTextureParam aParam,
int alVal);
153 void SetTextureConstantColor(
const cColor &color);
155 void SetColor(
const cColor &aColor);
158 iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
159 eVertexBufferUsageType aUsageType,
160 int alReserveVtxSize = 0,
int alReserveIdxSize = 0);
162 void DrawRect(
const cVector2f &avPos,
const cVector2f &avSize,
float afZ);
164 void DrawTri(
const tVertexVec &avVtx);
165 void DrawTri(
const cVertex *avVtx);
167 void DrawQuad(
const tVertexVec &avVtx);
168 void DrawQuad(
const tVertexVec &avVtx,
const cColor aCol);
169 void DrawQuad(
const tVertexVec &avVtx,
const float afZ);
170 void DrawQuad(
const tVertexVec &avVtx,
const float afZ,
const cColor &aCol);
171 void DrawQuadMultiTex(
const tVertexVec &avVtx,
const tVector3fVec &avExtraUvs);
173 void AddVertexToBatch(
const cVertex &apVtx);
174 void AddVertexToBatch(
const cVertex *apVtx,
const cVector3f *avTransform);
175 void AddVertexToBatch(
const cVertex *apVtx,
const cMatrixf *aMtx);
177 void AddVertexToBatch_Size2D(
const cVertex *apVtx,
const cVector3f *avTransform,
178 const cColor *apCol,
const float &mfW,
const float &mfH);
180 void AddVertexToBatch_Raw(
const cVector3f &avPos,
const cColor &aColor,
181 const cVector3f &avTex);
183 void AddTexCoordToBatch(
unsigned int alUnit,
const cVector3f *apCoord);
184 void SetBatchTextureUnitActive(
unsigned int alUnit,
bool abActive);
186 void AddIndexToBatch(
int alIndex);
188 void FlushTriBatch(tVtxBatchFlag aTypeFlags,
bool abAutoClear =
true);
189 void FlushQuadBatch(tVtxBatchFlag aTypeFlags,
bool abAutoClear =
true);
193 void DrawLine(
const cVector3f &avBegin,
const cVector3f &avEnd, cColor aCol);
194 void DrawBoxMaxMin(
const cVector3f &avMax,
const cVector3f &avMin, cColor aCol);
195 void DrawSphere(
const cVector3f &avPos,
float afRadius, cColor aCol);
197 void DrawLine2D(
const cVector2f &avBegin,
const cVector2f &avEnd,
float afZ, cColor aCol);
198 void DrawLineRect2D(
const cRect2f &aRect,
float afZ, cColor aCol);
199 void DrawLineCircle2D(
const cVector2f &avCenter,
float afRadius,
float afZ, cColor aCol);
201 void DrawFilledRect2D(
const cRect2f &aRect,
float afZ, cColor aCol);
204 void CopyContextToTexure(iTexture *apTex,
const cVector2l &avPos,
205 const cVector2l &avSize,
const cVector2l &avTexOffset = 0);
206 void SetRenderTarget(iTexture *pTex);
207 bool RenderTargetHasZBuffer();
208 void FlushRenderTarget();
210 void FlushRendering();
218 cVector2l mvScreenSize;
219 cVector2f mvVirtualSize;
225 float mfGammaCorrection;
228 cPlanef mvClipPlanes[kMaxClipPlanes];
236 float *mpVertexArray;
237 unsigned int mlVertexCount;
238 unsigned int *mpIndexArray;
239 unsigned int mlIndexCount;
241 unsigned int mlBatchStride;
243 float *mpTexCoordArray[MAX_TEXTUREUNITS];
244 bool mbTexCoordArrayActive[MAX_TEXTUREUNITS];
245 unsigned int mlTexCoordArrayCount[MAX_TEXTUREUNITS];
247 unsigned int mlBatchArraySize;
255 iTexture *mpRenderTarget;
258 iTexture *mpCurrentTexture[MAX_TEXTUREUNITS];
264 void CheckMultisampleCaps();
267 void SetUpBatchArrays();
270 void SetMatrixMode(eMatrix mType);
273 void SetVtxBatchStates(tVtxBatchFlag flags);