summaryrefslogtreecommitdiffhomepage
path: root/Stars45/Video.h
blob: d9b96f07bf6890779dff908a22c9d4e4cd9b9f35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*  Starshatter OpenSource Distribution
    Copyright (c) 1997-2004, Destroyer Studios LLC.
    All Rights Reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name "Destroyer Studios" nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

    SUBSYSTEM:    nGen.lib
    FILE:         Video.h
    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    Abstract Video Interface
*/

#ifndef Video_h
#define Video_h

#include "Geometry.h"
#include "Color.h"
#include "List.h"

// +--------------------------------------------------------------------+

class  Video;
struct VideoMode;
class  VideoSettings;
class  VideoPrivateData;

class  Bitmap;
class  Camera;
struct Rect;
struct Poly;
struct Material;
struct VertexSet;
class  Light;
class  Solid;
class  Surface;

// +--------------------------------------------------------------------+

struct RenderStats
{
    int   nframe;
    int   nverts;
    int   npolys;
    int   nlines;

    int   ncalls;

    int   total_verts;
    int   total_polys;
    int   total_lines;

    void  Clear() { nverts = npolys = nlines = ncalls =
        total_verts = total_polys = total_lines = 0; }
};

// +--------------------------------------------------------------------+

class Video
{
public:
    enum STATUS { VIDEO_OK, VIDEO_ERR, VIDEO_BAD_PARM };

    enum RENDER_STATE {
        FILL_MODE,
        SHADE_MODE,
        LIGHTING_ENABLE,
        Z_ENABLE,
        Z_WRITE_ENABLE,
        Z_BIAS,
        TEXTURE_FILTER,
        DITHER_ENABLE,
        SPECULAR_ENABLE,
        FOG_ENABLE,
        FOG_COLOR,
        FOG_DENSITY,
        STENCIL_ENABLE,
        TEXTURE_WRAP,
        LIGHTING_PASS,

        RENDER_STATE_MAX
    };

    enum BLEND_TYPE {
        BLEND_SOLID             = 1,
        BLEND_ALPHA             = 2,
        BLEND_ADDITIVE          = 4,
        BLEND_FORCE_DWORD       = 0x7fffffff,
    };

    enum SHADE_TYPE {
        SHADE_FLAT              = 1,
        SHADE_GOURAUD           = 2,
        SHADE_PHONG             = 3,
        SHADE_FORCE_DWORD       = 0x7fffffff,
    };

    enum FILL_TYPE {
        FILL_POINT              = 1,
        FILL_WIREFRAME          = 2,
        FILL_SOLID              = 3,
        FILL_FORCE_DWORD        = 0x7fffffff,
    };

    enum FILTER_TYPE {
        FILTER_NONE             = 1,
        FILTER_LINEAR           = 2,
        FILTER_MIPMAP           = 3,
        FILTER_MIPLINEAR        = 4,
        FILTER_TRILINEAR        = 6,
        FILTER_FORCE_DWORD      = 0x7fffffff,
    };

    enum PROJECTION_TYPE {
        PROJECTION_PERSPECTIVE  = 1,
        PROJECTION_ORTHOGONAL   = 2,
        PROJECTION_FORCE_DWORD  = 0x7fffffff,
    };

    Video();
    virtual ~Video();

    STATUS         Status()    const                               { return status; }
    virtual const VideoSettings*
    GetVideoSettings() const                        { return 0;     }
    virtual bool   SetVideoSettings(const VideoSettings* vs)       { return false; }
    virtual bool   Reset(const VideoSettings* vs)                  { return false; }

    virtual bool   SetBackgroundColor(Color c)                     { return false; }
    virtual bool   SetGammaLevel(int g)                            { return true;  }
    virtual bool   SetObjTransform(const Matrix& o, const Point& l){ return false; }

    virtual int    Width()     const                               { return 0;     }
    virtual int    Height()    const                               { return 0;     }
    virtual int    Depth()     const                               { return 0;     }

    virtual void   RecoverSurfaces()                               { }

    virtual bool   ClearAll()                                      { return false; }
    virtual bool   ClearDepthBuffer()                              { return false; }
    virtual bool   Present()                                       { return false; }
    virtual bool   Pause()                                         { return false; }
    virtual bool   Resume()                                        { return false; }

    virtual bool   IsWindowed()         const;
    virtual bool   IsFullScreen()       const;
    virtual bool   IsModeSupported(int width, int height, int bpp)
    const { return true;  }
    virtual bool   IsHardware()         const { return false; }
    virtual bool   IsHardwareTL()       const { return false; }
    virtual int    ZDepth()             const { return 0;     }
    virtual DWORD  VidMemFree()         const { return 0;     }
    virtual int    D3DLevel()           const { return 0;     }
    virtual int    MaxTexSize()         const { return 256;   }
    virtual int    MaxTexAspect()       const { return 0;     }
    virtual int    GammaLevel()         const { return 190;   }

    virtual bool   IsShadowEnabled()    const { return shadow_enabled;   }
    virtual bool   IsBumpMapEnabled()   const { return bump_enabled;     }
    virtual bool   IsSpecMapEnabled()   const { return spec_enabled;     }

    virtual void   SetShadowEnabled(bool e)   { shadow_enabled = e;      }
    virtual void   SetBumpMapEnabled(bool e)  { bump_enabled   = e;      }
    virtual void   SetSpecMapEnabled(bool e)  { spec_enabled   = e;      }

    virtual bool   Capture(Bitmap& bmp)                                  { return false;   }
    virtual bool   GetWindowRect(Rect& r)                                { return false;   }
    virtual bool   SetWindowRect(const Rect& r)                          { return false;   }
    virtual bool   SetViewport(int x, int y, int w, int h)               { return false;   }
    virtual bool   SetCamera(const Camera* cam)                          { camera = cam;
        return false;   }
    virtual bool   SetProjection(float fov,
    float znear=1.0f,
    float zfar=1.0e6f,
    DWORD type=PROJECTION_PERSPECTIVE)      { return false;   }
    virtual bool   SetEnvironment(Bitmap** faces)                        { return false;   }
    virtual bool   SetAmbient(Color c)                                   { return false;   }
    virtual bool   SetLights(const List<Light>& lights)                  { return false;   }
    virtual bool   SetRenderState(RENDER_STATE state, DWORD value)       { return false;   }
    virtual bool   SetBlendType(int blend_type)                          { return false;   }
    virtual bool   StartFrame()                                          { return false;   }
    virtual bool   EndFrame()                                            { return false;   }

    virtual bool   DrawPolys(int npolys, Poly* p)                        { return false;   }
    virtual bool   DrawScreenPolys(int npolys, Poly* p, int blend=0)     { return false;   }
    virtual bool   DrawSolid(Solid* s, DWORD blend_modes=0xf)            { return false;   }
    virtual bool   DrawShadow(Solid* s, int nverts, Vec3* verts, bool vis=false)
    { return false;   }
    virtual bool   DrawLines(int nlines, Vec3* v, Color c, int blend=0)  { return false;   }
    virtual bool   DrawScreenLines(int nlines, float* v, Color c, int blend=0)
    { return false;   }
    virtual bool   DrawPoints(VertexSet* v)                              { return false;   }
    virtual bool   DrawPolyOutline(Poly* p)                              { return false;   }
    virtual bool   UseMaterial(Material* m)                              { return false;   }

    virtual bool   UseXFont(const char* name, int size, bool b, bool i)  { return false;   }
    virtual bool   DrawText(const char* text, int count, const Rect& rect,
    DWORD format, Color c)                       { return false;   }

    virtual void   PreloadTexture(Bitmap* bmp)   { }
    virtual void   PreloadSurface(Surface* s)    { }
    virtual void   InvalidateCache()             { }

    const Camera*        GetCamera()       const { return camera;  }
    const RenderStats&   GetStats()        const { return stats; }
    static Video*        GetInstance()           { return video_instance; }

protected:
    STATUS            status;
    RenderStats       stats;
    const Camera*     camera;

    bool              shadow_enabled;
    bool              bump_enabled;
    bool              spec_enabled;

    static Video*     video_instance;
};

// +--------------------------------------------------------------------+

class VideoPrivateData
{
public:
    VideoPrivateData() : valid(false)   { }
    virtual ~VideoPrivateData()         { }

    virtual int    GetType()      const { return 0;       }

    virtual bool   IsValid()      const { return valid;   }
    virtual void   Invalidate()         { valid = false;  }
    virtual void   Validate()           { valid = true;   }

protected:
    bool valid;
};

// +--------------------------------------------------------------------+

#endif  // Video_h