summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/Video.h
blob: 607a9e163ccdb88500f30fca89f00b7abffcf0ef (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
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2024, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.

    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;

    RenderStats() : total_verts {0}, total_polys {0}, total_lines {0} {}
    void  Clear() { nverts = npolys = nlines = ncalls = 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 void   RequestTexSize(int size)   {               }
    virtual int    TexSize()            const { return 256;   }
    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