ScummVM API documentation
render.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 WATCHMAKER_RENDER_H
23 #define WATCHMAKER_RENDER_H
24 
25 #include "common/array.h"
26 #include "watchmaker/types.h"
27 #include "watchmaker/windows_hacks.h"
28 #include "watchmaker/3d/texture.h"
29 #include "watchmaker/3d/material.h"
30 
31 namespace Watchmaker {
32 
33 // Material properties
34 #define T3D_MATERIAL_CLIPMAP (1<<0) // clipmap
35 #define T3D_MATERIAL_OPACITY (1<<1) // opacity (0-24)
36 #define T3D_MATERIAL_ADDITIVE (1<<2) // additive (25-49)
37 #define T3D_MATERIAL_GLASS (1<<3) // glass (50-74)
38 #define T3D_MATERIAL_BOTTLE (1<<4) // bottle (75-100)
39 #define T3D_MATERIAL_ENVIROMENT (1<<5) // enviroment
40 #define T3D_MATERIAL_SKY (1<<6) // sky
41 #define T3D_MATERIAL_NOLIGHTMAP (1<<7) // no lightmap
42 #define T3D_MATERIAL_MOVIE (1<<8) // with movie
43 #define T3D_MATERIAL_FLARE (1<<9) // flare
44 #define T3D_MATERIAL_FLARE_SUN (1<<10) // flare sun
45 #define T3D_MATERIAL_FLARESOFT (1<<11) // flare soft
46 #define T3D_MATERIAL_SMOKE (1<<12) // smoke
47 #define T3D_MATERIAL_MOVIEPAUSED (1<<13) // if movie is paused
48 
49 // Backbuffer & Z-Buffer
50 #define rCLEARZBUFFER (1<<0) // clear zbuffer
51 #define rCLEARBACKBUFFER (1<<1) // clear back buffer
52 #define rCLEARSCREENBUFFER (1<<2) // clear screen buffer
53 
54 // rendering modes
55 #define rSOLIDMODE 1 // render in solid mode
56 #define rWIREFRAMEMODE 2 // render in wireframe
57 
58 // vertex buffer lock options
59 #define rVBLOCK_READONLY 1 // lock VB for reading
60 #define rVBLOCK_WRITEONLY 2 // lock VB for writing
61 #define rVBLOCK_NOSYSLOCK 4 // lock VB without hanging the system
62 
63 // VertexBuffers
64 #define MAX_LINES 50000 // max lines in VB
65 #define MAX_SHADOWS_PER_LIGHT 30 // max shadows per light
66 
67 #define MAX_BATCH_BLOCKS 512 // max normal batch blocks
68 #define MAX_BATCH_BLOCKS_SPECIAL 128 // max special batch blocks
69 #define MAX_BATCH_BLOCKS_LIGHTMAPS 512 // max lightmaps batch blocks
70 #define MAX_BATCH_BLOCKS_SKY 4 // max sky batch blocks
71 
72 #define FLEXIBLEVERTEXFLAGS (D3DFVF_XYZ | D3DFVF_DIFFUSE |D3DFVF_TEX2 ) // VB struct elements
73 //#define FLEXIBLEVERTEXFLAGSDEST (D3DFVF_XYZRHW | D3DFVF_DIFFUSE |D3DFVF_TEX2 )
74 
75 // Bitmap & Texture
76 #define rBITMAPSURFACE (0) // Plain bitmap image; fit the backbuffer pixelformat
77 #define rTEXTURESURFACE (1<<0) // Use when loading an image; if flag specified the image fit the texture pixelformat
78 #define rSURFACESTRETCH (1<<1) // Used for bitmaps; strech the pic to a new dimension using DX (could produce very bad results)
79 #define rSURFACECOPY (1<<2) // Not supported yet
80 #define rSURFACEHALF (1<<3) // Used for texture; hal the dimension during loading
81 #define rSURFACEFLIP (1<<4) // Flip upside-down the loaded image
82 
83 struct VertexBuffer {
84  // Just cheat for now, and do this offline.
85  Common::Array<gVertex> _buffer;
86 };
87 
88 struct SHADOW {
89  uint32 totalverts, num_objverts; // number of vertices in the shadow mesh
90  uint32 num_side_indices, num_cap_indices; // number of indices
91 // LPDIRECT3DVERTEXBUFFER7 VB,ProjVertsVB; // holds vertices of shadow volumes
92  void *VB;
93  void *ProjVertsVB; // holds vertices of shadow volumes
94  uint16 *pwShadVolIndices; // tri indices into vertex buffer VB for DrawPrim
95  uint16 *pwShadVolSideIndices; // ptrs into main index array pwShadVolIndices for Side tris of shadow volume
96  int16 *pwShadVolCapIndices; // ptrs into main index array pwShadVolIndices for cap tris of shadow volume
97  gTexture ProjectiveTexture; // texture to be projected
98 };
99 
100 struct SHADOWBOX {
101  SHADOW ShadowsList[MAX_SHADOWS_PER_LIGHT]; // shadow elements
102  unsigned int NumShadowsList; // number of shadow elements
103  int VBO;
104  //LPDIRECT3DVERTEXBUFFER7 VB; // shadow VB
105  uint32 NumVerts; // num verts in shadow box
106  uint32 NumIndices; // num indices
107  uint16 *pwIndices; // pointer to indices list
108  uint16 Intensity; // shadow intensity
109  uint16 ViewMatrixNum; // number of view matrix
110 };
111 
112 struct gBatchBlock {
113  signed short int Texture1 = 0, Texture2 = 0; // texture ID
114  unsigned int Flags1 = 0, Flags2 = 0; // flags
115  signed short int ViewMatrixNum = 0; // view matrix num
116  unsigned short int NumFaces() {
117  return FacesList.size(); // faces number
118  }
119  unsigned short int NumVerts() {
120  if (VBO) return VBO->_buffer.size(); // verts number
121  else return 0;
122  }
123  Common::Array<uint16> FacesList; // pointer to faces list
124  Common::SharedPtr<VertexBuffer> VBO = nullptr;
125 // LPDIRECT3DVERTEXBUFFER7 VB; // block VB
126 
127  gBatchBlock() {}
128  gBatchBlock(signed short int texture1, signed short int texture2, unsigned int flags1, unsigned int flags2) : Texture1(texture1), Texture2(texture2), Flags1(flags1), Flags2(flags2) {}
129 };
130 
131 class WorkDirs;
132 
133 //Rendering control functions
134 gBatchBlock *rNewBatchBlock(signed short int T1, unsigned int F1, signed short int T2, unsigned int F2);
135 void rBuildMaterialList(MaterialTable &MatList, unsigned int NumMat, signed short int ViewMatrixNum);
136 bool rRenderScene();
137 void rResetPipeline();
138 
139 // Function declaration
140 bool rGrabVideo(const char *path, char flags);
141 bool rRenderReady();
142 
143 //Materials, textures and bitmap functions
144 MaterialTable rCreateMaterialList(int num);
145 bool rSetMovieFrame(MaterialPtr mat, uint32 dwCurrFrame);
146 uint32 rGetMovieFrame(MaterialPtr mat);
147 void rReleaseAllTextures(unsigned int NotFlags);
148 class WGame;
149 int rLoadBitmapImage(WGame &game, const char *TextName, unsigned char flags);
150 void rReleaseAllBitmaps(unsigned int NotFlags);
151 void rReleaseBitmap(int i);
152 void rReleaseBitmapDirect(gTexture *b);
153 void rSetLoaderFlags(unsigned int NewLoaderFlags);
154 int rCreateSurface(unsigned int dimx, unsigned int dimy, unsigned char flags);
155 void *rCreateSurfaceP(unsigned int dimx, unsigned int dimy, unsigned char flags);
156 char *rGetBitmapName(unsigned int id);
157 void rSetBitmapName(unsigned int id, const char *s);
158 unsigned char *rLockSurface(int surf, unsigned int *pitch);
159 unsigned char *rLockSurfaceDirect(gTexture *t, unsigned int *pitch);
160 void rUnlockSurface(int surf);
161 void rUnlockSurfaceDirect(gTexture *t);
162 uint16 rRGBAToSurfaceFormat(unsigned int R, unsigned int G, unsigned int B, unsigned int A);
163 uint16 rRGBAToTextureFormat(unsigned int r, unsigned int g, unsigned int b, unsigned int a);
164 void rSurfaceFormatToRGBA(uint32 color, unsigned int *R, unsigned int *G, unsigned int *B, unsigned int *A);
165 void rTextureFormatToRGBA(uint16 color, unsigned int *R, unsigned int *G, unsigned int *B, unsigned int *A);
166 gTexture *rGetSurfaceTexture(int pos);
167 gTexture *rCopyTexture(gTexture *t);
168 
169 
170 //VertexBuffer and triangles functions
171 VertexBuffer rCreateVertexBuffer(unsigned int num);
172 bool rDeleteVertexBuffer(VertexBuffer &vb);
173 gVertex *rLockVertexPtr(void *vb, int flags);
174 void *rGetUserVertexBuffer();
175 unsigned int rGetUserVertexBufferCounter();
176 void rSetUserVertexBufferCounter(unsigned int uvbc);
177 bool rUnlockVertexPtr(void *vb);
178 uint16 *rGetLinesArrayPtr();
179 void rAddLinesArray();
180 unsigned int rGetNumLinesArray();
181 void rAddTrianglesArray(float x, float y, int r, int g, int b, int a);
182 int16 *rGetTrianglesArrayPtr();
183 unsigned int rGetNumTrianglesArray();
184 void *rLockPointArray();
185 void rUnlockPointArray();
186 unsigned int rGetNumPointArray();
187 void rAddPointArray();
188 void rOptimizeVertexArray(void *v);
189 
190 bool rMakeShadowVolume(SHADOWBOX *sb, gVertex *InVerts, DWORD nverts, float lightm[9]);
191 bool rMakeShadowBox(SHADOWBOX *sb, float BoxX, float BoxY, float BoxZ, WORD intens);
192 bool rMakeProjectiveShadow(SHADOWBOX *sb, void *InVerts, DWORD nverts);
193 
194 //Setup & clear functions
195 class WGame;
196 bool rInitialize3DEnvironment(WGame &game, char *cfg);
197 char *rGetRenderDllDesc();
198 void rSetFlagsFullScreen();
199 bool rGetFlagsFullScreen();
200 void rSetRenderMode(int state);
201 bool rClearBuffers(char flags);
202 void rGetScreenInfos(unsigned int *width, unsigned int *height, unsigned int *bpp);
203 void rRelaseFontTable(unsigned short *ft);
204 void rRelaseAllFontTable();
205 void rGetBlitterViewport(unsigned int *left, unsigned int *top, unsigned int *right, unsigned int *bottom);
206 void rUpdateExtends(int x1, int y1, int x2, int y2);
207 void rGetExtends(int *x1, int *y1, int *x2, int *y2);
208 void rResetExtends();
209 int rBlitSetStandardFont(signed int color, unsigned short *table);
210 int DebugQuick(signed int StdPx, signed int StdPy, const char *format, ...);
211 bool rGetStencilBitDepth();
212 
213 //Misc functions
214 void rBlitter(WGame &game, int dst, int src, int dposx, int dposy, int sposx, int sposy, int sdimx, int sdimy);
215 
216 //D3d specific geometry trasf. functions
217 struct t3dM3X3F;
218 struct t3dV3F;
219 void rSetViewMatrix(const t3dM3X3F &viewMatrix, const t3dV3F &translation);
220 int rBuildLinesViewMatrix(const t3dM3X3F &viewMatrix, const t3dV3F &translation);
221 int rAddUserViewMatrix(const t3dM3X3F &viewMatrix, const t3dV3F &translation);
222 void rSetUserViewMatrix(int num);
223 void rSaveViewMatrix();
224 void rRestoreViewMatrix();
225 void rSetLinesViewMatrix();
226 
227 bool checkGlError(const char *when = "");
228 
229 } // End of namespace Watchmaker
230 
231 #endif // WATCHMAKER_RENDER_H
Definition: types3d.h:38
Definition: 2d_stuff.h:30
Definition: array.h:52
Definition: vertex.h:33
Definition: work_dirs.h:30
Definition: render.h:100
Definition: render.h:88
Definition: render.h:83
Definition: texture.h:36
Definition: render.h:112
Definition: game.h:55
Definition: ptr.h:159
Definition: t3d.h:116