Triton
Visual simulation library for ocean rendering.
TritonCommon.h
Go to the documentation of this file.
1// Copyright (c) 2011-2014 Sundog Software LLC. All rights reserved worldwide.
2
7#ifndef TRITONCOMMON_H
8#define TRITONCOMMON_H
9
10#include "MemAlloc.h"
11#include <stdlib.h>
12#include <string>
13#include <limits.h>
14
15#define TRITON_PI 3.14159265
16#define TRITON_TWOPI (TRITON_PI * 2.0)
17#define TRITON_SQRT2 1.414213562373095
18
19#define TRITON_PIF 3.14159265f
20#define TRITON_TWOPIF (TRITON_PIF * 2.0f)
21#define TRITON_SQRT2F 1.414213562373095f
22
23#define RADIANS(x) ( (x) * (TRITON_PI / 180.0) )
24#define DEGREES(x) ( (x) * (180.0 / TRITON_PI ) )
25
26#define TRITON_MIN(a,b) (((a) < (b)) ? (a) : (b))
27
28struct ID3D11Texture2D;
29struct ID3D11ShaderResourceView;
30struct ID3D11UnorderedAccessView;
31struct _D3DXMACRO;
32struct IDirect3DDevice9;
33
34namespace Triton
35{
36
37class Environment;
38class Stream;
39
40#if _WIN32
41#if (_MSC_VER >= 1900)
42#pragma warning (disable: 4302 4311 4312)
43#endif
45typedef void * ShaderHandle;
47typedef void * TextureHandle;
49typedef void * DecalHandle;
51typedef void * BufferHandle;
52#else
54typedef int ShaderHandle;
56typedef int TextureHandle;
58typedef void * DecalHandle;
60typedef void * BufferHandle;
61#endif
62
64class Utils
65{
66public:
67
71 static void TRITONAPI SetDebugMsgCB( void (*debug_msg_cb)( const char * ));
72
75 static void TRITONAPI DebugMsg(const char *debugMessage);
76
78 static void TRITONAPI ClearGLErrors(Stream* stream = 0);
79
82 static bool TRITONAPI PrintGLErrors(const char *file, int line, Stream* stream = 0);
83
86 static TRITON_STRING TRITONAPI GetDLLPath() {
87 TRITON_STRING path;
88#ifdef _WIN32
89
90#if _MSC_VER >= 1930
91 path += "vc143\\";
92#elif _MSC_VER >= 1900
93 path += "vc14\\";
94#elif _MSC_VER >= 1800
95 path += "vc12\\";
96#elif _MSC_VER >= 1700
97 path += "vc11\\";
98#elif _MSC_VER >= 1600
99 path += "vc10\\";
100#elif _MSC_VER >= 1500
101 path += "vc9\\";
102#elif _MSC_VER >= 1400
103 path += "vc8\\";
104#else
105 path += "vc7\\";
106#endif
107
108#if _M_X64
109 path += "x64\\";
110#else
111 path += "win32\\";
112#endif
113#else
114#if ( __WORDSIZE == 64 )
115 path += "linux/x64/";
116#else
117 path += "linux/x86/";
118#endif
119#endif
120
121 /*
122 #ifdef _WIN32
123 #if (DIRECTX9_FOUND == 0 && DIRECTX11_FOUND == 0)
124 path += "NODX\\";
125 #endif
126 #endif
127 */
128 return path;
129 }
130
131 static void TRITONAPI Sprintf(char *string, size_t sizeInBytes, const char *format, float val);
132 static void TRITONAPI Sprintf(char *string, size_t sizeInBytes, const char *format, double val);
133 static void TRITONAPI Sprintf(char *string, size_t sizeInBytes,const char *format, int val);
134
137 static TRITON_STRING TRITONAPI GetDLLSuffix();
140 static TRITON_STRING TRITONAPI GetDLLExtension() {
141#ifdef _WIN32
142 return ".dll";
143#else
144 return ".so";
145#endif
146 }
147
150 static struct _D3DXMACRO * TRITONAPI GetDX9Macros(IDirect3DDevice9 *device, bool hdr, bool breakingWaves);
153 static TRITON_STRING TRITONAPI GetWaterShaderFileName(const Environment *env, bool tessendorf, bool fragment, bool patch);
156 static TRITON_STRING TRITONAPI GetParticleShaderFileName(const Environment *env, bool fragment);
159 static TRITON_STRING TRITONAPI GetUserShaderFileName();
162 static TRITON_STRING TRITONAPI GetUserVertShaderFileName();
165 static TRITON_STRING TRITONAPI GetDecalShaderFileName(const Environment *env, bool fragment);
168 static TRITON_STRING TRITONAPI GetGodRayShaderFileName(const Environment *env, bool fragment);
169};
170
171// A collection of DirectX11 resources that make up a texture that might be bound to a compute shader.
172typedef struct DX11Texture_S {
173 ID3D11Texture2D *tex2D;
174 ID3D11Texture2D *staging;
175 ID3D11ShaderResourceView *srv;
176 ID3D11UnorderedAccessView *uav;
177} DX11Texture;
178}
179
180#endif
Memory allocation interface for SilverLining.
int ShaderHandle
A renderer-agnostic handle for a shader.
Definition: TritonCommon.h:54
void * BufferHandle
A renderer-agnostic handle for a buffer.
Definition: TritonCommon.h:60
void * DecalHandle
A renderer-agnostic handle for a decal.
Definition: TritonCommon.h:58
int TextureHandle
A renderer-agnostic handle for a texture.
Definition: TritonCommon.h:56
Triton's public interface for specifying the environmental conditions and camera properties.
Definition: Environment.h:214
A collection of static utility methods used by Triton.
Definition: TritonCommon.h:65
static TRITON_STRING TRITONAPI GetWaterShaderFileName(const Environment *env, bool tessendorf, bool fragment, bool patch)
Returns the filename for the main water shaders, which may be overridden via config.
static struct _D3DXMACRO *TRITONAPI GetDX9Macros(IDirect3DDevice9 *device, bool hdr, bool breakingWaves)
Returns HLSL preprocessor defines for DirectX9, indicating the shader models avaialble to our shaders...
static TRITON_STRING TRITONAPI GetGodRayShaderFileName(const Environment *env, bool fragment)
Returns the filename for the god ray shaders, which may be overridden via config.
static TRITON_STRING TRITONAPI GetDLLExtension()
Retrieves the DLL extension.
Definition: TritonCommon.h:138
static TRITON_STRING TRITONAPI GetDecalShaderFileName(const Environment *env, bool fragment)
Returns the filename for the volumetric deferred decal shaders, which may be overridden via config.
static TRITON_STRING TRITONAPI GetUserShaderFileName()
Returns the filename for the user-defined fragment shader functions (OpenGL only; see the Resources/u...
static TRITON_STRING TRITONAPI GetParticleShaderFileName(const Environment *env, bool fragment)
Returns the filename for the particle shaders, which may be overridden via config.
static TRITON_STRING TRITONAPI GetUserVertShaderFileName()
Returns the filename for the user-defined vertex shader functions (OpenGL only; see the Resources/use...
static void TRITONAPI ClearGLErrors(Stream *stream=0)
Clears any existing OpenGL error codes so we may test for new ones.
static void TRITONAPI DebugMsg(const char *debugMessage)
Prints out an error message to the debugger's output window only if the setting enable-debug-messages...
static TRITON_STRING TRITONAPI GetDLLPath()
Returns the resources subdirectory where our FFT implementation DLL's live for this specific build's ...
Definition: TritonCommon.h:86
static TRITON_STRING TRITONAPI GetDLLSuffix()
Retrieves the suffix on the FFT implementation DLL's for this specific build flavor's runtime library...
static bool TRITONAPI PrintGLErrors(const char *file, int line, Stream *stream=0)
Prints out (and clears) any existing GL errors using Utils::DebugMsg.
static void TRITONAPI SetDebugMsgCB(void(*debug_msg_cb)(const char *))
Allows the client to plug in a routine which will be called to print/log DebugMsg() calls when "enabl...