ScummVM API documentation
low_level_graphics_tgl.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef HPL_LOW_LEVEL_GRAPHICS_TGL_H
23#define HPL_LOW_LEVEL_GRAPHICS_TGL_H
24
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"
31
32#ifdef USE_TINYGL
33
34namespace hpl {
35
36TGLenum TextureTargetToTGL(eTextureTarget target);
37
38TGLenum GetTGLTextureTargetEnum(eTextureTarget type);
39
40//-------------------------------------------------
41
42class LowLevelGraphicsTGL : public iLowLevelGraphics {
43public:
44 LowLevelGraphicsTGL();
45 ~LowLevelGraphicsTGL();
46
47 bool Init(int alWidth, int alHeight, int alBpp, int abFullscreen, int alMultisampling,
48 const tString &asWindowCaption);
49
50 int GetCaps(eGraphicCaps aType) const;
51
52 void ShowCursor(bool abX);
53
54 void SetMultisamplingActive(bool abX);
55
56 void SetGammaCorrection(float afX);
57 float GetGammaCorrection();
58
59 int GetMultisampling() { return mlMultisampling; }
60
61 void SetClipPlane(int alIdx, const cPlanef &aPlane);
62 cPlanef GetClipPlane(int alIdx, const cPlanef &aPlane);
63 void SetClipPlaneActive(int alIdx, bool abX);
64
65 cVector2f GetScreenSize();
66 cVector2f GetVirtualSize();
67 void SetVirtualSize(cVector2f avSize);
68
69 Bitmap2D *CreateBitmap2D(const cVector2l &avSize);
70 FontData *CreateFontData(const tString &asName);
71
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);
77
78 Graphics::PixelFormat *GetPixelFormat();
79
80 iGpuProgram *CreateGpuProgram(const tString &vertex, const tString &fragment);
81
82 void SaveScreenToBMP(const tString &asFile);
83
85
86 void PushMatrix(eMatrix aMtxType);
87 void PopMatrix(eMatrix aMtxType);
88 void SetIdentityMatrix(eMatrix aMtxType);
89
90 void SetMatrix(eMatrix aMtxType, const cMatrixf &a_mtxA);
91
92 void TranslateMatrix(eMatrix aMtxType, const cVector3f &avPos);
93 void RotateMatrix(eMatrix aMtxType, const cVector3f &avRot);
94 void ScaleMatrix(eMatrix aMtxType, const cVector3f &avScale);
95
96 void SetOrthoProjection(const cVector2f &avSize, float afMin, float afMax);
97
99
100 // OCCLUSION
101 iOcclusionQuery *CreateOcclusionQuery();
102 void DestroyOcclusionQuery(iOcclusionQuery *apQuery);
103
104 // CLEARING THE FRAMEBUFFER
105 void ClearScreen();
106
107 void SetClearColor(const cColor &aCol);
108 void SetClearDepth(float afDepth);
109 void SetClearStencil(int alVal);
110
111 void SetClearColorActive(bool abX);
112 void SetClearDepthActive(bool abX);
113 void SetClearStencilActive(bool abX);
114
115 void SetColorWriteActive(bool abR, bool abG, bool abB, bool abA);
116 void SetDepthWriteActive(bool abX);
117
118 void SetCullActive(bool abX);
119 void SetCullMode(eCullMode aMode);
120
121 // DEPTH
122 void SetDepthTestActive(bool abX);
123 void SetDepthTestFunc(eDepthTestFunc aFunc);
124
125 // ALPHA
126 void SetAlphaTestActive(bool abX);
127 void SetAlphaTestFunc(eAlphaTestFunc aFunc, float afRef);
128
129 // STENCIL
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);
138
139 // SCISSOR
140 void SetScissorActive(bool abX);
141 void SetScissorRect(const cRect2l &aRect);
142
143 // BLENDING
144 void SetBlendActive(bool abX);
145 void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor);
146 void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
147 eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha);
148
149 // TEXTURE
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);
154
155 void SetColor(const cColor &aColor);
156
157 // POLYGONS
158 iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
159 eVertexBufferUsageType aUsageType,
160 int alReserveVtxSize = 0, int alReserveIdxSize = 0);
161
162 void DrawRect(const cVector2f &avPos, const cVector2f &avSize, float afZ);
163
164 void DrawTri(const tVertexVec &avVtx);
165 void DrawTri(const cVertex *avVtx);
166
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);
172
173 void AddVertexToBatch(const cVertex &apVtx);
174 void AddVertexToBatch(const cVertex *apVtx, const cVector3f *avTransform);
175 void AddVertexToBatch(const cVertex *apVtx, const cMatrixf *aMtx);
176
177 void AddVertexToBatch_Size2D(const cVertex *apVtx, const cVector3f *avTransform,
178 const cColor *apCol, const float &mfW, const float &mfH);
179
180 void AddVertexToBatch_Raw(const cVector3f &avPos, const cColor &aColor,
181 const cVector3f &avTex);
182
183 void AddTexCoordToBatch(unsigned int alUnit, const cVector3f *apCoord);
184 void SetBatchTextureUnitActive(unsigned int alUnit, bool abActive);
185
186 void AddIndexToBatch(int alIndex);
187
188 void FlushTriBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true);
189 void FlushQuadBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true);
190 void ClearBatch();
191
192 // PRIMITIVES
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);
196
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);
200
201 void DrawFilledRect2D(const cRect2f &aRect, float afZ, cColor aCol);
202
203 // FRAMEBUFFER
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();
209
210 void FlushRendering();
211 void SwapBuffers();
212
214
215 void SetupGL();
216
217private:
218 cVector2l mvScreenSize;
219 cVector2f mvVirtualSize;
220 int mlMultisampling;
221 int mlBpp;
222
223 // Gamma
224 // uint16 mvStartGammaArray[3][256];
225 float mfGammaCorrection;
226
227 // Clipping
228 cPlanef mvClipPlanes[kMaxClipPlanes];
229
230 // SDL Variables
231 // SDL_Surface *mpScreen;
232 Graphics::PixelFormat mpPixelFormat;
233
234 // Vertex Array variables
235 // The vertex arrays used:
236 float *mpVertexArray;
237 unsigned int mlVertexCount;
238 unsigned int *mpIndexArray;
239 unsigned int mlIndexCount;
240
241 unsigned int mlBatchStride;
242
243 float *mpTexCoordArray[MAX_TEXTUREUNITS];
244 bool mbTexCoordArrayActive[MAX_TEXTUREUNITS];
245 unsigned int mlTexCoordArrayCount[MAX_TEXTUREUNITS];
246
247 unsigned int mlBatchArraySize;
248
249 // Clearing
250 bool mbClearColor;
251 bool mbClearDepth;
252 bool mbClearStencil;
253
254 // Rendertarget variables
255 iTexture *mpRenderTarget;
256
257 // Texture
258 iTexture *mpCurrentTexture[MAX_TEXTUREUNITS];
259
260 // CG Compiler Variables
261 // CGcontext mCG_Context;
262
263 // Multisample
264 void CheckMultisampleCaps();
265
266 // Batch helper
267 void SetUpBatchArrays();
268
269 // Matrix Helper
270 void SetMatrixMode(eMatrix mType);
271
272 // Vtx helper
273 void SetVtxBatchStates(tVtxBatchFlag flags);
274};
275
276} // namespace hpl
277
278#endif // USE_TINYGL
279
280#endif // HPL_LOWLEVELGRAPHICS_TGL_H
Definition: pixelformat.h:138