2023-11-19 09:38:07 -05:00
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
#ifndef _tgl_h
|
|
|
|
#define _tgl_h
|
|
|
|
|
|
|
|
#include "tglvector.h"
|
2023-11-19 09:38:07 -05:00
|
|
|
|
|
|
|
#include <d3d.h>
|
|
|
|
#include <ddraw.h>
|
2023-12-07 07:10:42 -05:00
|
|
|
#include <windows.h>
|
2023-11-19 09:38:07 -05:00
|
|
|
|
|
|
|
namespace Tgl
|
|
|
|
{
|
|
|
|
|
|
|
|
enum ColorModel {
|
2023-12-07 07:10:42 -05:00
|
|
|
// Note: Not used in shipped game, no way to verify contents.
|
2023-11-19 09:38:07 -05:00
|
|
|
Ramp,
|
|
|
|
RGB
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ShadingModel {
|
|
|
|
Wireframe,
|
|
|
|
UnlitFlat,
|
|
|
|
Flat,
|
|
|
|
Gouraud,
|
|
|
|
Phong
|
|
|
|
};
|
|
|
|
|
|
|
|
enum LightType {
|
|
|
|
Ambient,
|
|
|
|
Point,
|
|
|
|
Spot,
|
|
|
|
Directional,
|
|
|
|
ParallelPoint
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ProjectionType {
|
|
|
|
Perspective,
|
|
|
|
Orthographic
|
|
|
|
};
|
|
|
|
|
|
|
|
enum TextureMappingMode {
|
|
|
|
Linear,
|
|
|
|
PerspectiveCorrect
|
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// Not in the Tgl leak, inferred from the assembly
|
|
|
|
enum MaterialMode {
|
|
|
|
FromParent,
|
|
|
|
FromFrame,
|
|
|
|
FromMesh,
|
|
|
|
};
|
|
|
|
|
2023-11-19 09:38:07 -05:00
|
|
|
struct PaletteEntry {
|
|
|
|
unsigned char m_red;
|
|
|
|
unsigned char m_green;
|
|
|
|
unsigned char m_blue;
|
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
struct DeviceDirect3DCreateData {
|
2024-01-05 14:38:34 -05:00
|
|
|
IDirect3D2* m_pDirect3D;
|
|
|
|
IDirect3DDevice2* m_pDirect3DDevice;
|
2023-12-07 07:10:42 -05:00
|
|
|
};
|
2023-11-19 09:38:07 -05:00
|
|
|
|
|
|
|
struct DeviceDirectDrawCreateData {
|
|
|
|
const GUID* m_driverGUID;
|
2023-12-07 07:10:42 -05:00
|
|
|
HWND m_hWnd;
|
2023-11-19 09:38:07 -05:00
|
|
|
IDirectDraw* m_pDirectDraw;
|
2023-12-07 07:10:42 -05:00
|
|
|
IDirectDrawSurface* m_pFrontBuffer;
|
2023-11-19 09:38:07 -05:00
|
|
|
IDirectDrawSurface* m_pBackBuffer;
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// These have possibly been removed in the shipped game
|
|
|
|
// (Put them back if we can verify when we find a callsite
|
|
|
|
// which constructs this type)
|
|
|
|
// IDirectDrawPalette* m_pPalette;
|
|
|
|
// int m_isFullScreen;
|
2023-11-19 09:38:07 -05:00
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// Result type used for all methods in the Tgl API
|
2023-11-19 09:38:07 -05:00
|
|
|
enum Result {
|
|
|
|
Error = 0,
|
|
|
|
Success = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
inline int Succeeded(Result result)
|
|
|
|
{
|
|
|
|
return (result == Success);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class Renderer;
|
|
|
|
class Object;
|
|
|
|
class Device;
|
|
|
|
class View;
|
|
|
|
class Light;
|
|
|
|
class Camera;
|
|
|
|
class Group;
|
|
|
|
class Mesh;
|
|
|
|
class Texture;
|
2023-12-07 07:10:42 -05:00
|
|
|
class Unk;
|
2023-11-19 09:38:07 -05:00
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// VTABLE 0x100db980
|
2023-11-19 09:38:07 -05:00
|
|
|
class Object {
|
|
|
|
public:
|
|
|
|
virtual ~Object() {}
|
|
|
|
|
|
|
|
virtual void* ImplementationDataPtr() = 0;
|
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// VTABLE 0x100db948
|
2023-11-19 09:38:07 -05:00
|
|
|
class Renderer : public Object {
|
|
|
|
public:
|
2023-12-07 07:10:42 -05:00
|
|
|
// vtable+0x08
|
|
|
|
virtual Device* CreateDevice(const DeviceDirectDrawCreateData&) = 0;
|
2024-01-06 21:29:32 -05:00
|
|
|
virtual Device* CreateDevice(const DeviceDirect3DCreateData&) = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
|
|
|
|
// vtable+0x10
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual View* CreateView(
|
|
|
|
const Device*,
|
|
|
|
const Camera*,
|
|
|
|
unsigned long x,
|
|
|
|
unsigned long y,
|
|
|
|
unsigned long width,
|
|
|
|
unsigned long height
|
|
|
|
) = 0;
|
|
|
|
virtual Camera* CreateCamera() = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Light* CreateLight(LightType, float r, float g, float b) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Group* CreateGroup(const Group* pParent = 0) = 0;
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// vtable+0x20
|
|
|
|
virtual Unk* CreateUnk() = 0;
|
|
|
|
virtual Texture* CreateTexture() = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Texture* CreateTexture(
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int bitsPerTexel,
|
|
|
|
const void* pTexels,
|
|
|
|
int pTexelsArePersistent,
|
|
|
|
int paletteEntryCount,
|
|
|
|
const PaletteEntry* pEntries
|
|
|
|
) = 0;
|
|
|
|
virtual Result SetTextureDefaultShadeCount(unsigned long) = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
|
|
|
|
// vtable+0x30
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Result SetTextureDefaultColorCount(unsigned long) = 0;
|
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
Renderer* CreateRenderer();
|
2023-11-19 09:38:07 -05:00
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// VTABLE 0x100db9b8
|
2023-11-19 09:38:07 -05:00
|
|
|
class Device : public Object {
|
|
|
|
public:
|
2023-12-07 07:10:42 -05:00
|
|
|
// vtable+0x08
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual unsigned long GetWidth() = 0;
|
|
|
|
virtual unsigned long GetHeight() = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
|
|
|
|
// vtable+0x10
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Result SetColorModel(ColorModel) = 0;
|
|
|
|
virtual Result SetShadingModel(ShadingModel) = 0;
|
|
|
|
virtual Result SetShadeCount(unsigned long) = 0;
|
|
|
|
virtual Result SetDither(int) = 0;
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// vtable+0x20
|
|
|
|
virtual Result Update() = 0;
|
|
|
|
virtual void InitFromD3DDevice(Device*) = 0;
|
|
|
|
virtual void InitFromWindowsDevice(Device*) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// VTABLE 0x100dba28
|
2023-11-19 09:38:07 -05:00
|
|
|
class View : public Object {
|
|
|
|
public:
|
|
|
|
virtual Result Add(const Light*) = 0;
|
|
|
|
virtual Result Remove(const Light*) = 0;
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// vtable+0x10
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Result SetCamera(const Camera*) = 0;
|
|
|
|
virtual Result SetProjection(ProjectionType) = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Result SetFrustrum(float frontClippingDistance, float backClippingDistance, float degrees) = 0;
|
|
|
|
virtual Result SetBackgroundColor(float r, float g, float b) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// vtable+0x20
|
|
|
|
virtual Result GetBackgroundColor(float* r, float* g, float* b) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Result Clear() = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Result Render(const Light*) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Result ForceUpdate(unsigned long x, unsigned long y, unsigned long width, unsigned long height) = 0;
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// vtable+0x30
|
|
|
|
virtual Result TransformWorldToScreen(const float world[3], float screen[4]) = 0;
|
|
|
|
virtual Result TransformScreenToWorld(const float screen[4], float world[3]) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
|
|
|
|
// Pick():
|
|
|
|
// x, y:
|
|
|
|
// view coordinates
|
|
|
|
//
|
|
|
|
// ppGroupsToPickFrom:
|
|
|
|
// array of (Group*) in any order
|
|
|
|
// Groups to pick from
|
|
|
|
//
|
|
|
|
// groupsToPickFromCount:
|
|
|
|
// size of ppGroupsToPickFrom
|
|
|
|
//
|
|
|
|
// rppPickedGroups:
|
|
|
|
// output parameter
|
|
|
|
// array of (Group*) representing a Group hierarchy
|
|
|
|
// top-down order (element 0 is root/scene)
|
|
|
|
// caller must deallocate array
|
|
|
|
// ref count of each element (Group*) has not been increased
|
|
|
|
// an element will be 0, if a corresponding Group was not found in ppGroupsToPickFrom
|
|
|
|
//
|
|
|
|
// rPickedGroupCount:
|
|
|
|
// output parameter
|
|
|
|
// size of rppPickedGroups
|
|
|
|
virtual Result Pick(
|
|
|
|
unsigned long x,
|
|
|
|
unsigned long y,
|
|
|
|
const Group** ppGroupsToPickFrom,
|
|
|
|
int groupsToPickFromCount,
|
|
|
|
const Group**& rppPickedGroups,
|
|
|
|
int& rPickedGroupCount
|
|
|
|
) = 0;
|
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// VTABLE 0x100dbae8
|
2023-11-19 09:38:07 -05:00
|
|
|
class Camera : public Object {
|
|
|
|
public:
|
2024-01-12 19:34:38 -05:00
|
|
|
virtual Result SetTransformation(FloatMatrix4&) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// VTABLE 0x100dbb08
|
2023-11-19 09:38:07 -05:00
|
|
|
class Light : public Object {
|
|
|
|
public:
|
2024-01-12 19:34:38 -05:00
|
|
|
virtual Result SetTransformation(FloatMatrix4&) = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Result SetColor(float r, float g, float b) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// VTABLE 0x100dbbb0
|
|
|
|
class Mesh : public Object {
|
|
|
|
public:
|
|
|
|
virtual Result SetColor(float r, float g, float b, float a) = 0;
|
|
|
|
virtual Result SetTexture(const Texture*) = 0;
|
|
|
|
virtual Result GetTexture(Texture*&) = 0;
|
|
|
|
|
|
|
|
virtual Result SetTextureMappingMode(ProjectionType) = 0;
|
|
|
|
virtual Result SetShadingModel(ShadingModel) = 0;
|
|
|
|
|
|
|
|
// Clone data in underlying group
|
|
|
|
virtual Mesh* DeepClone(Unk*) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// Just get another Group pointing to the same underlying data
|
|
|
|
virtual Mesh* ShallowClone(Unk*) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// VTABLE 0x100dbaa0
|
2023-11-19 09:38:07 -05:00
|
|
|
class Group : public Object {
|
|
|
|
public:
|
2024-01-12 19:34:38 -05:00
|
|
|
virtual Result SetTransformation(FloatMatrix4&) = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Result SetColor(float r, float g, float b, float a) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Result SetTexture(const Texture*) = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Result GetTexture(Texture*&) = 0;
|
|
|
|
virtual Result SetMaterialMode(MaterialMode) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Result Add(const Group*) = 0;
|
|
|
|
virtual Result Add(const Mesh*) = 0;
|
|
|
|
virtual Result Remove(const Group*) = 0;
|
|
|
|
virtual Result Remove(const Mesh*) = 0;
|
|
|
|
virtual Result RemoveAll() = 0;
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// This is TransformLocalToWorld in the leak, however it seems
|
|
|
|
// to have been replaced by something else in the shipped code.
|
|
|
|
virtual Result Unknown() = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// Don't know what this is. Seems like another Tgl object which
|
|
|
|
// was not in the leaked Tgl code. My suspicion is that it's
|
|
|
|
// some kind of builder class for creating meshes.
|
|
|
|
// VTABLE 0x100dbb30
|
|
|
|
class Unk : public Object {
|
2023-11-19 09:38:07 -05:00
|
|
|
public:
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Result SetMeshData(
|
|
|
|
unsigned long faceCount,
|
|
|
|
unsigned long vertexCount,
|
|
|
|
const float (*pPositions)[3],
|
|
|
|
const float (*pNormals)[3],
|
|
|
|
const float (*pTextureCoordinates)[2],
|
|
|
|
unsigned long vertexPerFaceCount,
|
|
|
|
unsigned long* pFaceData
|
|
|
|
) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
virtual Result GetBoundingBox(float min[3], float max[3]) = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Unk* Clone() = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
};
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
// VTABLE 0x100dbb68
|
2023-11-19 09:38:07 -05:00
|
|
|
class Texture : public Object {
|
|
|
|
public:
|
2023-12-07 07:10:42 -05:00
|
|
|
// vtable+0x08
|
|
|
|
virtual Result SetTexels(int width, int height, int bitsPerTexel, void* pTexels) = 0;
|
|
|
|
virtual void FillRowsOfTexture(int y, int height, void* pBuffer) = 0;
|
|
|
|
|
|
|
|
// vtable+0x10
|
|
|
|
virtual Result Changed(int texelsChanged, int paletteChanged) = 0;
|
|
|
|
virtual Result GetBufferAndPalette(
|
|
|
|
int* pWidth,
|
|
|
|
int* pHeight,
|
|
|
|
int* pDepth,
|
|
|
|
void** ppBuffer,
|
|
|
|
int* pPaletteSize,
|
|
|
|
PaletteEntry** ppPalette
|
2023-11-19 09:38:07 -05:00
|
|
|
) = 0;
|
2023-12-07 07:10:42 -05:00
|
|
|
virtual Result SetPalette(int entryCount, PaletteEntry* pEntries) = 0;
|
2023-11-19 09:38:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Tgl
|
|
|
|
|
2023-12-07 07:10:42 -05:00
|
|
|
#endif /* _tgl_h */
|