Serious-Engine/Sources/Engine/Graphics/Vertex.h

146 lines
3.1 KiB
C
Raw Normal View History

2016-03-11 14:57:17 +01:00
/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */
#ifndef SE_INCL_VERTEX_H
#define SE_INCL_VERTEX_H
#ifdef PRAGMA_ONCE
#pragma once
#endif
#include "Color.h"
// !!! FIXME: rcg11162001 I have the structures packed to assure positioning.
// !!! FIXME: rcg11162001 This should be fixed on win32, and then this
// !!! FIXME: rcg11162001 ifndef should be removed.
#ifndef PLATFORM_WIN32
#pragma pack(1)
#endif
2016-03-11 14:57:17 +01:00
struct GFXVertex3
{
FLOAT x,y,z;
};
struct GFXNormal3
{
FLOAT nx,ny,nz;
};
struct GFXTexCoord
{
union {
struct { FLOAT u,v; } uv;
struct { FLOAT s,t; } st;
2016-03-11 14:57:17 +01:00
};
};
struct GFXTexCoord4
{
FLOAT s,t,r,q;
};
struct GFXColor
{
union {
struct { UBYTE r,g,b,a; } ub;
struct { ULONG abgr; } ul; // reverse order - use ByteSwap()!
2016-03-11 14:57:17 +01:00
};
GFXColor() {};
/*
* rcg10052001 This is a REALLY bad idea;
* never rely on the memory layout of even a
* simple class. It works for MSVC, though,
* so we'll keep it.
*/
#if (defined _MSC_VER)
2016-03-11 14:57:17 +01:00
GFXColor( COLOR col) {
_asm mov ecx,dword ptr [this]
_asm mov eax,dword ptr [col]
_asm bswap eax
_asm mov dword ptr [ecx],eax
}
__forceinline void Set( COLOR col) {
_asm mov ecx,dword ptr [this]
_asm mov eax,dword ptr [col]
_asm bswap eax
_asm mov dword ptr [ecx],eax
}
#else
GFXColor( COLOR col) { ul.abgr = ByteSwap(col); }
__forceinline void Set( COLOR col) { ul.abgr = ByteSwap(col); }
#endif
2016-03-11 14:57:17 +01:00
void MultiplyRGBA( const GFXColor &col1, const GFXColor &col2) {
ub.r = (ULONG(col1.ub.r)*col2.ub.r)>>8;
ub.g = (ULONG(col1.ub.g)*col2.ub.g)>>8;
ub.b = (ULONG(col1.ub.b)*col2.ub.b)>>8;
ub.a = (ULONG(col1.ub.a)*col2.ub.a)>>8;
2016-03-11 14:57:17 +01:00
}
void MultiplyRGB( const GFXColor &col1, const GFXColor &col2) {
ub.r = (ULONG(col1.ub.r)*col2.ub.r)>>8;
ub.g = (ULONG(col1.ub.g)*col2.ub.g)>>8;
ub.b = (ULONG(col1.ub.b)*col2.ub.b)>>8;
2016-03-11 14:57:17 +01:00
}
void MultiplyRGBCopyA1( const GFXColor &col1, const GFXColor &col2) {
ub.r = (ULONG(col1.ub.r)*col2.ub.r)>>8;
ub.g = (ULONG(col1.ub.g)*col2.ub.g)>>8;
ub.b = (ULONG(col1.ub.b)*col2.ub.b)>>8;
ub.a = col1.ub.a;
2016-03-11 14:57:17 +01:00
}
void AttenuateRGB( ULONG ulA) {
ub.r = (ULONG(ub.r)*ulA)>>8;
ub.g = (ULONG(ub.g)*ulA)>>8;
ub.b = (ULONG(ub.b)*ulA)>>8;
2016-03-11 14:57:17 +01:00
}
void AttenuateA( ULONG ulA) {
ub.a = (ULONG(ub.a)*ulA)>>8;
2016-03-11 14:57:17 +01:00
}
};
#define GFXVertex GFXVertex4
/*
* rcg10042001 Removed the union; objects with constructors can't be
* safely unioned, and there's not a whole lot of memory lost here anyhow.
*/
// IF YOU CHANGE THIS STRUCT, YOU WILL BREAK THE INLINE ASSEMBLY
// ON GNU PLATFORMS! THIS INCLUDES CHANGING THE STRUCTURE'S PACKING.
// You have been warned.
struct GFXVertex4 {
2016-03-11 14:57:17 +01:00
FLOAT x,y,z;
struct GFXColor col;
SLONG shade;
void Clear(void) {};
2016-03-11 14:57:17 +01:00
};
#define GFXNormal GFXNormal4
struct GFXNormal4
{
FLOAT nx,ny,nz;
ULONG ul;
};
// !!! FIXME: rcg11162001 I have the structures packed to assure positioning.
// !!! FIXME: rcg11162001 This should be fixed on win32, and then this
// !!! FIXME: rcg11162001 ifndef should be removed.
#ifndef PLATFORM_WIN32
#pragma pack()
#endif
2016-03-11 14:57:17 +01:00
#endif /* include-once check. */