Add proper initializations in basic graphics structures
parent
7097ec38e3
commit
91658c7df0
|
@ -54,55 +54,38 @@ namespace Gfx
|
||||||
struct DeviceConfig
|
struct DeviceConfig
|
||||||
{
|
{
|
||||||
//! Screen size
|
//! Screen size
|
||||||
Math::IntPoint size;
|
Math::IntPoint size = Math::IntPoint(800, 600);
|
||||||
//! Bits per pixel
|
//! Bits per pixel
|
||||||
int bpp;
|
int bpp = 32;
|
||||||
//! Full screen
|
//! Full screen
|
||||||
bool fullScreen;
|
bool fullScreen = false;
|
||||||
//! Resizeable window
|
//! Resizeable window
|
||||||
bool resizeable;
|
bool resizeable = true;
|
||||||
//! Double buffering
|
//! Double buffering
|
||||||
bool doubleBuf;
|
bool doubleBuf = true;
|
||||||
//! No window frame (also set with full screen)
|
//! No window frame (also set with full screen)
|
||||||
bool noFrame;
|
bool noFrame = false;
|
||||||
|
|
||||||
//! Size of red channel in bits
|
//! Size of red channel in bits
|
||||||
int redSize;
|
int redSize = 8;
|
||||||
//! Size of green channel in bits
|
//! Size of green channel in bits
|
||||||
int greenSize;
|
int greenSize = 8;
|
||||||
//! Size of blue channel in bits
|
//! Size of blue channel in bits
|
||||||
int blueSize;
|
int blueSize = 8;
|
||||||
//! Size of alpha channel in bits
|
//! Size of alpha channel in bits
|
||||||
int alphaSize;
|
int alphaSize = 8;
|
||||||
//! Color depth in bits
|
//! Color depth in bits
|
||||||
int depthSize;
|
int depthSize = 24;
|
||||||
//! Stencil depth in bits
|
//! Stencil depth in bits
|
||||||
int stencilSize;
|
int stencilSize = 8;
|
||||||
|
|
||||||
//! Force hardware acceleration (video mode set will fail on lack of hw accel)
|
//! Force hardware acceleration (video mode set will fail on lack of hw accel)
|
||||||
bool hardwareAccel;
|
bool hardwareAccel = true;
|
||||||
|
|
||||||
//! Constructor calls LoadDefault()
|
|
||||||
DeviceConfig() { LoadDefault(); }
|
|
||||||
|
|
||||||
//! Loads the default values
|
//! Loads the default values
|
||||||
inline void LoadDefault()
|
void LoadDefault()
|
||||||
{
|
{
|
||||||
size = Math::IntPoint(800, 600);
|
*this = DeviceConfig();
|
||||||
bpp = 32;
|
|
||||||
fullScreen = false;
|
|
||||||
resizeable = true;
|
|
||||||
doubleBuf = true;
|
|
||||||
noFrame = false;
|
|
||||||
|
|
||||||
hardwareAccel = true;
|
|
||||||
|
|
||||||
redSize = 8;
|
|
||||||
blueSize = 8;
|
|
||||||
greenSize = 8;
|
|
||||||
alphaSize = 8;
|
|
||||||
depthSize = 24;
|
|
||||||
stencilSize = 8;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,34 +34,22 @@ namespace Gfx
|
||||||
struct FramebufferParams
|
struct FramebufferParams
|
||||||
{
|
{
|
||||||
//! Requested width of buffers
|
//! Requested width of buffers
|
||||||
int width;
|
int width = 1024;
|
||||||
//! Requested height of buffers
|
//! Requested height of buffers
|
||||||
int height;
|
int height = 1024;
|
||||||
//! Requested depth buffer
|
//! Requested depth buffer
|
||||||
int depth;
|
int depth = 16;
|
||||||
//! Requested number of samples for multisampling
|
//! Requested number of samples for multisampling
|
||||||
int samples;
|
int samples = 1;
|
||||||
//! true requests color texture
|
//! true requests color texture
|
||||||
bool colorTexture;
|
bool colorTexture = false;
|
||||||
//! true requests depth texture
|
//! true requests depth texture
|
||||||
bool depthTexture;
|
bool depthTexture = false;
|
||||||
|
|
||||||
|
|
||||||
//! Initializes
|
|
||||||
FramebufferParams()
|
|
||||||
{
|
|
||||||
LoadDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Loads default values
|
//! Loads default values
|
||||||
void LoadDefault()
|
void LoadDefault()
|
||||||
{
|
{
|
||||||
width = 1024;
|
*this = FramebufferParams();
|
||||||
height = 1024;
|
|
||||||
depth = 16;
|
|
||||||
samples = 1;
|
|
||||||
colorTexture = false;
|
|
||||||
depthTexture = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -54,48 +54,32 @@ enum LightType
|
||||||
struct Light
|
struct Light
|
||||||
{
|
{
|
||||||
//! Type of light source
|
//! Type of light source
|
||||||
LightType type;
|
LightType type = LIGHT_POINT;
|
||||||
//! Color of ambient light
|
//! Color of ambient light
|
||||||
Color ambient;
|
Color ambient = Color(0.4f, 0.4f, 0.4f);
|
||||||
//! Color of diffuse light
|
//! Color of diffuse light
|
||||||
Color diffuse;
|
Color diffuse = Color(0.8f, 0.8f, 0.8f);
|
||||||
//! Color of specular light
|
//! Color of specular light
|
||||||
Color specular;
|
Color specular = Color(1.0f, 1.0f, 1.0f);
|
||||||
//! Position in world space (for point & spot lights)
|
//! Position in world space (for point & spot lights)
|
||||||
Math::Vector position;
|
Math::Vector position = Math::Vector(0.0f, 0.0f, 0.0f);
|
||||||
//! Direction in world space (for directional & spot lights)
|
//! Direction in world space (for directional & spot lights)
|
||||||
Math::Vector direction;
|
Math::Vector direction = Math::Vector(0.0f, 0.0f, 1.0f);
|
||||||
//! Constant attenuation factor
|
//! Constant attenuation factor
|
||||||
float attenuation0;
|
float attenuation0 = 1.0f;
|
||||||
//! Linear attenuation factor
|
//! Linear attenuation factor
|
||||||
float attenuation1;
|
float attenuation1 = 0.0f;
|
||||||
//! Quadratic attenuation factor
|
//! Quadratic attenuation factor
|
||||||
float attenuation2;
|
float attenuation2 = 0.0f;
|
||||||
//! Angle of spotlight cone (0-PI/2 radians)
|
//! Angle of spotlight cone (0-PI/2 radians)
|
||||||
float spotAngle;
|
float spotAngle = Math::PI/2.0f;
|
||||||
|
|
||||||
//! Intensity of spotlight (0 = uniform; 128 = most intense)
|
//! Intensity of spotlight (0 = uniform; 128 = most intense)
|
||||||
float spotIntensity;
|
float spotIntensity = 0.0f;
|
||||||
|
|
||||||
//! Constructor; calls LoadDefault()
|
|
||||||
Light()
|
|
||||||
{
|
|
||||||
LoadDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Loads default values
|
//! Loads default values
|
||||||
void LoadDefault()
|
void LoadDefault()
|
||||||
{
|
{
|
||||||
type = LIGHT_POINT;
|
*this = Light();
|
||||||
ambient = Color(0.4f, 0.4f, 0.4f);
|
|
||||||
diffuse = Color(0.8f, 0.8f, 0.8f);
|
|
||||||
specular = Color(1.0f, 1.0f, 1.0f);
|
|
||||||
position = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
||||||
direction = Math::Vector(0.0f, 0.0f, 1.0f);
|
|
||||||
attenuation0 = 1.0f;
|
|
||||||
attenuation1 = attenuation2 = 0.0f;
|
|
||||||
spotAngle = Math::PI/2.0f;
|
|
||||||
spotIntensity = 0.0f;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -155,26 +155,18 @@ enum TexMixArgument
|
||||||
struct TextureCreateParams
|
struct TextureCreateParams
|
||||||
{
|
{
|
||||||
//! Whether to generate mipmaps
|
//! Whether to generate mipmaps
|
||||||
bool mipmap;
|
bool mipmap = false;
|
||||||
//! Format of source image data
|
//! Format of source image data
|
||||||
TexImgFormat format;
|
TexImgFormat format = TEX_IMG_RGB;
|
||||||
//! General texture filtering mode
|
//! General texture filtering mode
|
||||||
TexFilter filter;
|
TexFilter filter = TEX_FILTER_NEAREST;
|
||||||
//! Pad the image to nearest power of 2 dimensions
|
//! Pad the image to nearest power of 2 dimensions
|
||||||
bool padToNearestPowerOfTwo;
|
bool padToNearestPowerOfTwo = false;
|
||||||
|
|
||||||
//! Constructor; calls LoadDefault()
|
|
||||||
TextureCreateParams()
|
|
||||||
{ LoadDefault(); }
|
|
||||||
|
|
||||||
//! Loads the default values
|
//! Loads the default values
|
||||||
inline void LoadDefault()
|
void LoadDefault()
|
||||||
{
|
{
|
||||||
format = TEX_IMG_RGB;
|
*this = TextureCreateParams();
|
||||||
mipmap = false;
|
|
||||||
padToNearestPowerOfTwo = false;
|
|
||||||
|
|
||||||
filter = TEX_FILTER_NEAREST;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -188,40 +180,28 @@ struct TextureCreateParams
|
||||||
struct TextureStageParams
|
struct TextureStageParams
|
||||||
{
|
{
|
||||||
//! Mixing operation done on color values
|
//! Mixing operation done on color values
|
||||||
TexMixOperation colorOperation;
|
TexMixOperation colorOperation = TEX_MIX_OPER_DEFAULT;
|
||||||
//! 1st argument of color operations
|
//! 1st argument of color operations
|
||||||
TexMixArgument colorArg1;
|
TexMixArgument colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
||||||
//! 2nd argument of color operations
|
//! 2nd argument of color operations
|
||||||
TexMixArgument colorArg2;
|
TexMixArgument colorArg2 = TEX_MIX_ARG_TEXTURE;
|
||||||
//! Mixing operation done on alpha values
|
//! Mixing operation done on alpha values
|
||||||
TexMixOperation alphaOperation;
|
TexMixOperation alphaOperation = TEX_MIX_OPER_DEFAULT;
|
||||||
//! 1st argument of alpha operations
|
//! 1st argument of alpha operations
|
||||||
TexMixArgument alphaArg1;
|
TexMixArgument alphaArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
||||||
//! 2nd argument of alpha operations
|
//! 2nd argument of alpha operations
|
||||||
TexMixArgument alphaArg2;
|
TexMixArgument alphaArg2 = TEX_MIX_ARG_TEXTURE;
|
||||||
//! Wrap mode for 1st tex coord
|
//! Wrap mode for 1st tex coord
|
||||||
TexWrapMode wrapS;
|
TexWrapMode wrapS = TEX_WRAP_REPEAT;
|
||||||
//! Wrap mode for 2nd tex coord
|
//! Wrap mode for 2nd tex coord
|
||||||
TexWrapMode wrapT;
|
TexWrapMode wrapT = TEX_WRAP_REPEAT;
|
||||||
//! Constant color factor (for TEX_MIX_ARG_FACTOR)
|
//! Constant color factor (for TEX_MIX_ARG_FACTOR)
|
||||||
Color factor;
|
Color factor;
|
||||||
|
|
||||||
//! Constructor; calls LoadDefault()
|
|
||||||
TextureStageParams()
|
|
||||||
{ LoadDefault(); }
|
|
||||||
|
|
||||||
//! Loads the default values
|
//! Loads the default values
|
||||||
inline void LoadDefault()
|
void LoadDefault()
|
||||||
{
|
{
|
||||||
colorOperation = TEX_MIX_OPER_DEFAULT;
|
*this = TextureStageParams();
|
||||||
colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
|
||||||
colorArg2 = TEX_MIX_ARG_TEXTURE;
|
|
||||||
|
|
||||||
alphaOperation = TEX_MIX_OPER_DEFAULT;
|
|
||||||
alphaArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
|
||||||
alphaArg2 = TEX_MIX_ARG_TEXTURE;
|
|
||||||
|
|
||||||
wrapS = wrapT = TEX_WRAP_REPEAT;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -255,22 +235,14 @@ struct TextureGenerationParams
|
||||||
{
|
{
|
||||||
struct Coord
|
struct Coord
|
||||||
{
|
{
|
||||||
TexGenMode mode;
|
TexGenMode mode = TEX_GEN_NONE;
|
||||||
float plane[4];
|
float plane[4] = {};
|
||||||
};
|
};
|
||||||
Coord coords[4];
|
Coord coords[4];
|
||||||
|
|
||||||
TextureGenerationParams()
|
void LoadDefault()
|
||||||
{
|
{
|
||||||
LoadDefault();
|
*this = TextureGenerationParams();
|
||||||
}
|
|
||||||
|
|
||||||
inline void LoadDefault()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
coords[i].mode = TEX_GEN_NONE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -284,19 +256,13 @@ struct TextureGenerationParams
|
||||||
struct Texture
|
struct Texture
|
||||||
{
|
{
|
||||||
//! ID of the texture in graphics engine; 0 = invalid texture
|
//! ID of the texture in graphics engine; 0 = invalid texture
|
||||||
unsigned int id;
|
unsigned int id = 0;
|
||||||
//! Size of texture
|
//! Size of texture
|
||||||
Math::IntPoint size;
|
Math::IntPoint size;
|
||||||
//! Original size of texture (as loaded from image)
|
//! Original size of texture (as loaded from image)
|
||||||
Math::IntPoint originalSize;
|
Math::IntPoint originalSize;
|
||||||
//! Whether the texture has alpha channel
|
//! Whether the texture has alpha channel
|
||||||
bool alpha;
|
bool alpha = false;
|
||||||
|
|
||||||
Texture()
|
|
||||||
{
|
|
||||||
id = 0;
|
|
||||||
alpha = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Returns whether the texture is valid (ID != 0)
|
//! Returns whether the texture is valid (ID != 0)
|
||||||
bool Valid() const
|
bool Valid() const
|
||||||
|
@ -311,7 +277,7 @@ struct Texture
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Comparator for use in texture maps and sets
|
//! Comparator for use in texture maps and sets
|
||||||
inline bool operator<(const Texture &other) const
|
bool operator<(const Texture &other) const
|
||||||
{
|
{
|
||||||
// Invalid textures are always "less than" every other texture
|
// Invalid textures are always "less than" every other texture
|
||||||
|
|
||||||
|
@ -328,7 +294,7 @@ struct Texture
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Comparator
|
//! Comparator
|
||||||
inline bool operator==(const Texture &other) const
|
bool operator==(const Texture &other) const
|
||||||
{
|
{
|
||||||
if (Valid() != other.Valid())
|
if (Valid() != other.Valid())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
|
|
||||||
#include "graphics/model/model_triangle.h"
|
#include "graphics/model/model_triangle.h"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace Gfx
|
namespace Gfx
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -166,18 +164,13 @@ struct ModelTriangleV3 : ModelTriangle {};
|
||||||
struct OldModelHeader
|
struct OldModelHeader
|
||||||
{
|
{
|
||||||
//! Revision number
|
//! Revision number
|
||||||
int revision;
|
int revision = 0;
|
||||||
//! Version number
|
//! Version number
|
||||||
int version;
|
int version = 0;
|
||||||
//! Total number of triangles
|
//! Total number of triangles
|
||||||
int totalTriangles;
|
int totalTriangles = 0;
|
||||||
//! Reserved area
|
//! Reserved area
|
||||||
int reserved[10];
|
int reserved[10] = {0};
|
||||||
|
|
||||||
OldModelHeader()
|
|
||||||
{
|
|
||||||
memset(this, 0, sizeof(*this));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,20 +182,15 @@ struct OldModelHeader
|
||||||
*/
|
*/
|
||||||
struct OldModelTriangleV1
|
struct OldModelTriangleV1
|
||||||
{
|
{
|
||||||
char used;
|
char used = 0;
|
||||||
char selected;
|
char selected = 0;
|
||||||
Vertex p1;
|
Vertex p1;
|
||||||
Vertex p2;
|
Vertex p2;
|
||||||
Vertex p3;
|
Vertex p3;
|
||||||
Material material;
|
Material material;
|
||||||
char texName[20];
|
char texName[20] = {0};
|
||||||
float min;
|
float min = 0;
|
||||||
float max;
|
float max = 0;
|
||||||
|
|
||||||
OldModelTriangleV1()
|
|
||||||
{
|
|
||||||
memset(this, 0, sizeof(*this));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -213,25 +201,20 @@ struct OldModelTriangleV1
|
||||||
*/
|
*/
|
||||||
struct OldModelTriangleV2
|
struct OldModelTriangleV2
|
||||||
{
|
{
|
||||||
char used;
|
char used = 0;
|
||||||
char selected;
|
char selected = 0;
|
||||||
Vertex p1;
|
Vertex p1;
|
||||||
Vertex p2;
|
Vertex p2;
|
||||||
Vertex p3;
|
Vertex p3;
|
||||||
Material material;
|
Material material;
|
||||||
char texName[20];
|
char texName[20] = {0};
|
||||||
float min;
|
float min = 0.0f;
|
||||||
float max;
|
float max = 0.0f;
|
||||||
long state;
|
long state = 0;
|
||||||
short reserved1;
|
short reserved1 = 0;
|
||||||
short reserved2;
|
short reserved2 = 0;
|
||||||
short reserved3;
|
short reserved3 = 0;
|
||||||
short reserved4;
|
short reserved4 = 0;
|
||||||
|
|
||||||
OldModelTriangleV2()
|
|
||||||
{
|
|
||||||
memset(this, 0, sizeof(*this));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -242,25 +225,20 @@ struct OldModelTriangleV2
|
||||||
*/
|
*/
|
||||||
struct OldModelTriangleV3
|
struct OldModelTriangleV3
|
||||||
{
|
{
|
||||||
char used;
|
char used = 0;
|
||||||
char selected;
|
char selected = 0;
|
||||||
VertexTex2 p1;
|
VertexTex2 p1;
|
||||||
VertexTex2 p2;
|
VertexTex2 p2;
|
||||||
VertexTex2 p3;
|
VertexTex2 p3;
|
||||||
Material material;
|
Material material;
|
||||||
char texName[20];
|
char texName[20] = {0};
|
||||||
float min;
|
float min = 0.0f;
|
||||||
float max;
|
float max = 0.0f;
|
||||||
long state;
|
long state = 0;
|
||||||
short texNum2;
|
short texNum2 = 0;
|
||||||
short reserved2;
|
short reserved2 = 0;
|
||||||
short reserved3;
|
short reserved3 = 0;
|
||||||
short reserved4;
|
short reserved4 = 0;
|
||||||
|
|
||||||
OldModelTriangleV3()
|
|
||||||
{
|
|
||||||
memset(this, 0, sizeof(*this));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Gfx
|
} // namespace Gfx
|
||||||
|
|
Loading…
Reference in New Issue