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" 36 TGLenum ColorFormatToTGL(eColorDataFormat format);
38 TGLenum TextureTargetToTGL(eTextureTarget target);
40 TGLenum GetTGLTextureTargetEnum(eTextureTarget type);
44 class LowLevelGraphicsTGL :
public iLowLevelGraphics {
46 LowLevelGraphicsTGL();
47 ~LowLevelGraphicsTGL();
49 bool Init(
int alWidth,
int alHeight,
int alBpp,
int abFullscreen,
int alMultisampling,
50 const tString &asWindowCaption);
52 int GetCaps(eGraphicCaps aType)
const;
54 void ShowCursor(
bool abX);
56 void SetMultisamplingActive(
bool abX);
58 void SetGammaCorrection(
float afX);
59 float GetGammaCorrection();
61 int GetMultisampling() {
return mlMultisampling; }
63 void SetClipPlane(
int alIdx,
const cPlanef &aPlane);
64 cPlanef GetClipPlane(
int alIdx,
const cPlanef &aPlane);
65 void SetClipPlaneActive(
int alIdx,
bool abX);
67 cVector2f GetScreenSize();
68 cVector2f GetVirtualSize();
69 void SetVirtualSize(cVector2f avSize);
71 Bitmap2D *CreateBitmap2D(
const cVector2l &avSize);
72 FontData *CreateFontData(
const tString &asName);
74 iTexture *CreateTexture(
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
75 iTexture *CreateTexture(
const tString &asName,
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
76 iTexture *CreateTexture(Bitmap2D *apBmp,
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
77 iTexture *CreateTexture(
const cVector2l &avSize,
int alBpp, cColor aFillCol,
78 bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
82 iGpuProgram *CreateGpuProgram(
const tString &vertex,
const tString &fragment);
84 void SaveScreenToBMP(
const tString &asFile);
88 void PushMatrix(eMatrix aMtxType);
89 void PopMatrix(eMatrix aMtxType);
90 void SetIdentityMatrix(eMatrix aMtxType);
92 void SetMatrix(eMatrix aMtxType,
const cMatrixf &a_mtxA);
94 void TranslateMatrix(eMatrix aMtxType,
const cVector3f &avPos);
95 void RotateMatrix(eMatrix aMtxType,
const cVector3f &avRot);
96 void ScaleMatrix(eMatrix aMtxType,
const cVector3f &avScale);
98 void SetOrthoProjection(
const cVector2f &avSize,
float afMin,
float afMax);
103 iOcclusionQuery *CreateOcclusionQuery();
104 void DestroyOcclusionQuery(iOcclusionQuery *apQuery);
109 void SetClearColor(
const cColor &aCol);
110 void SetClearDepth(
float afDepth);
111 void SetClearStencil(
int alVal);
113 void SetClearColorActive(
bool abX);
114 void SetClearDepthActive(
bool abX);
115 void SetClearStencilActive(
bool abX);
117 void SetColorWriteActive(
bool abR,
bool abG,
bool abB,
bool abA);
118 void SetDepthWriteActive(
bool abX);
120 void SetCullActive(
bool abX);
121 void SetCullMode(eCullMode aMode);
124 void SetDepthTestActive(
bool abX);
125 void SetDepthTestFunc(eDepthTestFunc aFunc);
128 void SetAlphaTestActive(
bool abX);
129 void SetAlphaTestFunc(eAlphaTestFunc aFunc,
float afRef);
132 void SetStencilActive(
bool abX);
133 void SetStencil(eStencilFunc aFunc,
int alRef,
unsigned int aMask,
134 eStencilOp aFailOp, eStencilOp aZFailOp, eStencilOp aZPassOp);
135 void SetStencilTwoSide(eStencilFunc aFrontFunc, eStencilFunc aBackFunc,
136 int alRef,
unsigned int aMask,
137 eStencilOp aFrontFailOp, eStencilOp aFrontZFailOp, eStencilOp aFrontZPassOp,
138 eStencilOp aBackFailOp, eStencilOp aBackZFailOp, eStencilOp aBackZPassOp);
139 void SetStencilTwoSide(
bool abX);
142 void SetScissorActive(
bool abX);
143 void SetScissorRect(
const cRect2l &aRect);
146 void SetBlendActive(
bool abX);
147 void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor);
148 void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
149 eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha);
152 void SetTexture(
unsigned int alUnit, iTexture *apTex);
153 void SetActiveTextureUnit(
unsigned int alUnit);
154 void SetTextureEnv(eTextureParam aParam,
int alVal);
155 void SetTextureConstantColor(
const cColor &color);
157 void SetColor(
const cColor &aColor);
160 iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
161 eVertexBufferUsageType aUsageType,
162 int alReserveVtxSize = 0,
int alReserveIdxSize = 0);
164 void DrawRect(
const cVector2f &avPos,
const cVector2f &avSize,
float afZ);
166 void DrawTri(
const tVertexVec &avVtx);
167 void DrawTri(
const cVertex *avVtx);
169 void DrawQuad(
const tVertexVec &avVtx);
170 void DrawQuad(
const tVertexVec &avVtx,
const cColor aCol);
171 void DrawQuad(
const tVertexVec &avVtx,
const float afZ);
172 void DrawQuad(
const tVertexVec &avVtx,
const float afZ,
const cColor &aCol);
173 void DrawQuadMultiTex(
const tVertexVec &avVtx,
const tVector3fVec &avExtraUvs);
175 void AddVertexToBatch(
const cVertex &apVtx);
176 void AddVertexToBatch(
const cVertex *apVtx,
const cVector3f *avTransform);
177 void AddVertexToBatch(
const cVertex *apVtx,
const cMatrixf *aMtx);
179 void AddVertexToBatch_Size2D(
const cVertex *apVtx,
const cVector3f *avTransform,
180 const cColor *apCol,
const float &mfW,
const float &mfH);
182 void AddVertexToBatch_Raw(
const cVector3f &avPos,
const cColor &aColor,
183 const cVector3f &avTex);
185 void AddTexCoordToBatch(
unsigned int alUnit,
const cVector3f *apCoord);
186 void SetBatchTextureUnitActive(
unsigned int alUnit,
bool abActive);
188 void AddIndexToBatch(
int alIndex);
190 void FlushTriBatch(tVtxBatchFlag aTypeFlags,
bool abAutoClear =
true);
191 void FlushQuadBatch(tVtxBatchFlag aTypeFlags,
bool abAutoClear =
true);
195 void DrawLine(
const cVector3f &avBegin,
const cVector3f &avEnd, cColor aCol);
196 void DrawBoxMaxMin(
const cVector3f &avMax,
const cVector3f &avMin, cColor aCol);
197 void DrawSphere(
const cVector3f &avPos,
float afRadius, cColor aCol);
199 void DrawLine2D(
const cVector2f &avBegin,
const cVector2f &avEnd,
float afZ, cColor aCol);
200 void DrawLineRect2D(
const cRect2f &aRect,
float afZ, cColor aCol);
201 void DrawLineCircle2D(
const cVector2f &avCenter,
float afRadius,
float afZ, cColor aCol);
203 void DrawFilledRect2D(
const cRect2f &aRect,
float afZ, cColor aCol);
206 void CopyContextToTexure(iTexture *apTex,
const cVector2l &avPos,
207 const cVector2l &avSize,
const cVector2l &avTexOffset = 0);
208 void SetRenderTarget(iTexture *pTex);
209 bool RenderTargetHasZBuffer();
210 void FlushRenderTarget();
212 void FlushRendering();
220 cVector2l mvScreenSize;
221 cVector2f mvVirtualSize;
227 float mfGammaCorrection;
230 cPlanef mvClipPlanes[kMaxClipPlanes];
238 float *mpVertexArray;
239 unsigned int mlVertexCount;
240 unsigned int *mpIndexArray;
241 unsigned int mlIndexCount;
243 unsigned int mlBatchStride;
245 float *mpTexCoordArray[MAX_TEXTUREUNITS];
246 bool mbTexCoordArrayActive[MAX_TEXTUREUNITS];
247 unsigned int mlTexCoordArrayCount[MAX_TEXTUREUNITS];
249 unsigned int mlBatchArraySize;
257 iTexture *mpRenderTarget;
260 iTexture *mpCurrentTexture[MAX_TEXTUREUNITS];
266 void CheckMultisampleCaps();
269 void SetUpBatchArrays();
272 void SetMatrixMode(eMatrix mType);
275 void SetVtxBatchStates(tVtxBatchFlag flags);
282 #endif // HPL_LOWLEVELGRAPHICS_TGL_H