ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
34 namespace hpl {
35 
36 TGLenum ColorFormatToTGL(eColorDataFormat format);
37 
38 TGLenum TextureTargetToTGL(eTextureTarget target);
39 
40 TGLenum GetTGLTextureTargetEnum(eTextureTarget type);
41 
42 //-------------------------------------------------
43 
44 class LowLevelGraphicsTGL : public iLowLevelGraphics {
45 public:
46  LowLevelGraphicsTGL();
47  ~LowLevelGraphicsTGL();
48 
49  bool Init(int alWidth, int alHeight, int alBpp, int abFullscreen, int alMultisampling,
50  const tString &asWindowCaption);
51 
52  int GetCaps(eGraphicCaps aType) const;
53 
54  void ShowCursor(bool abX);
55 
56  void SetMultisamplingActive(bool abX);
57 
58  void SetGammaCorrection(float afX);
59  float GetGammaCorrection();
60 
61  int GetMultisampling() { return mlMultisampling; }
62 
63  void SetClipPlane(int alIdx, const cPlanef &aPlane);
64  cPlanef GetClipPlane(int alIdx, const cPlanef &aPlane);
65  void SetClipPlaneActive(int alIdx, bool abX);
66 
67  cVector2f GetScreenSize();
68  cVector2f GetVirtualSize();
69  void SetVirtualSize(cVector2f avSize);
70 
71  Bitmap2D *CreateBitmap2D(const cVector2l &avSize);
72  FontData *CreateFontData(const tString &asName);
73 
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);
79 
80  Graphics::PixelFormat *GetPixelFormat();
81 
82  iGpuProgram *CreateGpuProgram(const tString &vertex, const tString &fragment);
83 
84  void SaveScreenToBMP(const tString &asFile);
85 
87 
88  void PushMatrix(eMatrix aMtxType);
89  void PopMatrix(eMatrix aMtxType);
90  void SetIdentityMatrix(eMatrix aMtxType);
91 
92  void SetMatrix(eMatrix aMtxType, const cMatrixf &a_mtxA);
93 
94  void TranslateMatrix(eMatrix aMtxType, const cVector3f &avPos);
95  void RotateMatrix(eMatrix aMtxType, const cVector3f &avRot);
96  void ScaleMatrix(eMatrix aMtxType, const cVector3f &avScale);
97 
98  void SetOrthoProjection(const cVector2f &avSize, float afMin, float afMax);
99 
101 
102  // OCCLUSION
103  iOcclusionQuery *CreateOcclusionQuery();
104  void DestroyOcclusionQuery(iOcclusionQuery *apQuery);
105 
106  // CLEARING THE FRAMEBUFFER
107  void ClearScreen();
108 
109  void SetClearColor(const cColor &aCol);
110  void SetClearDepth(float afDepth);
111  void SetClearStencil(int alVal);
112 
113  void SetClearColorActive(bool abX);
114  void SetClearDepthActive(bool abX);
115  void SetClearStencilActive(bool abX);
116 
117  void SetColorWriteActive(bool abR, bool abG, bool abB, bool abA);
118  void SetDepthWriteActive(bool abX);
119 
120  void SetCullActive(bool abX);
121  void SetCullMode(eCullMode aMode);
122 
123  // DEPTH
124  void SetDepthTestActive(bool abX);
125  void SetDepthTestFunc(eDepthTestFunc aFunc);
126 
127  // ALPHA
128  void SetAlphaTestActive(bool abX);
129  void SetAlphaTestFunc(eAlphaTestFunc aFunc, float afRef);
130 
131  // STENCIL
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);
140 
141  // SCISSOR
142  void SetScissorActive(bool abX);
143  void SetScissorRect(const cRect2l &aRect);
144 
145  // BLENDING
146  void SetBlendActive(bool abX);
147  void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor);
148  void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
149  eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha);
150 
151  // TEXTURE
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);
156 
157  void SetColor(const cColor &aColor);
158 
159  // POLYGONS
160  iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
161  eVertexBufferUsageType aUsageType,
162  int alReserveVtxSize = 0, int alReserveIdxSize = 0);
163 
164  void DrawRect(const cVector2f &avPos, const cVector2f &avSize, float afZ);
165 
166  void DrawTri(const tVertexVec &avVtx);
167  void DrawTri(const cVertex *avVtx);
168 
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);
174 
175  void AddVertexToBatch(const cVertex &apVtx);
176  void AddVertexToBatch(const cVertex *apVtx, const cVector3f *avTransform);
177  void AddVertexToBatch(const cVertex *apVtx, const cMatrixf *aMtx);
178 
179  void AddVertexToBatch_Size2D(const cVertex *apVtx, const cVector3f *avTransform,
180  const cColor *apCol, const float &mfW, const float &mfH);
181 
182  void AddVertexToBatch_Raw(const cVector3f &avPos, const cColor &aColor,
183  const cVector3f &avTex);
184 
185  void AddTexCoordToBatch(unsigned int alUnit, const cVector3f *apCoord);
186  void SetBatchTextureUnitActive(unsigned int alUnit, bool abActive);
187 
188  void AddIndexToBatch(int alIndex);
189 
190  void FlushTriBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true);
191  void FlushQuadBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true);
192  void ClearBatch();
193 
194  // PRIMITIVES
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);
198 
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);
202 
203  void DrawFilledRect2D(const cRect2f &aRect, float afZ, cColor aCol);
204 
205  // FRAMEBUFFER
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();
211 
212  void FlushRendering();
213  void SwapBuffers();
214 
216 
217  void SetupGL();
218 
219 private:
220  cVector2l mvScreenSize;
221  cVector2f mvVirtualSize;
222  int mlMultisampling;
223  int mlBpp;
224 
225  // Gamma
226  // uint16 mvStartGammaArray[3][256];
227  float mfGammaCorrection;
228 
229  // Clipping
230  cPlanef mvClipPlanes[kMaxClipPlanes];
231 
232  // SDL Variables
233  // SDL_Surface *mpScreen;
234  Graphics::PixelFormat mpPixelFormat;
235 
236  // Vertex Array variables
237  // The vertex arrays used:
238  float *mpVertexArray;
239  unsigned int mlVertexCount;
240  unsigned int *mpIndexArray;
241  unsigned int mlIndexCount;
242 
243  unsigned int mlBatchStride;
244 
245  float *mpTexCoordArray[MAX_TEXTUREUNITS];
246  bool mbTexCoordArrayActive[MAX_TEXTUREUNITS];
247  unsigned int mlTexCoordArrayCount[MAX_TEXTUREUNITS];
248 
249  unsigned int mlBatchArraySize;
250 
251  // Clearing
252  bool mbClearColor;
253  bool mbClearDepth;
254  bool mbClearStencil;
255 
256  // Rendertarget variables
257  iTexture *mpRenderTarget;
258 
259  // Texture
260  iTexture *mpCurrentTexture[MAX_TEXTUREUNITS];
261 
262  // CG Compiler Variables
263  // CGcontext mCG_Context;
264 
265  // Multisample
266  void CheckMultisampleCaps();
267 
268  // Batch helper
269  void SetUpBatchArrays();
270 
271  // Matrix Helper
272  void SetMatrixMode(eMatrix mType);
273 
274  // Vtx helper
275  void SetVtxBatchStates(tVtxBatchFlag flags);
276 };
277 
278 } // namespace hpl
279 
280 #endif // USE_TINYGL
281 
282 #endif // HPL_LOWLEVELGRAPHICS_TGL_H
Definition: AI.h:36
Definition: pixelformat.h:138