Torque3D Documentation / _generateds / gfxVertexColor.h

gfxVertexColor.h

Engine/source/gfx/gfxVertexColor.h

More...

Classes:

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _GFXVERTEXCOLOR_H_
25#define _GFXVERTEXCOLOR_H_
26
27#ifndef _SWIZZLE_H_
28#include "core/util/swizzle.h"
29#endif
30#include "core/color.h"
31
32class GFXVertexColor 
33{
34
35private:
36   U32 mPackedColorData;
37   static Swizzle<U8, 4> *mDeviceSwizzle;
38   
39public:
40   static void setSwizzle( Swizzle<U8, 4> *val ) { mDeviceSwizzle = val; }
41
42   GFXVertexColor() : mPackedColorData( 0xFFFFFFFF ) {} // White with full alpha
43   GFXVertexColor( const ColorI &color ) { set( color ); }
44   GFXVertexColor( const LinearColorF &color) { set(color); }
45
46   void set( U8 red, U8 green, U8 blue, U8 alpha = 255 )
47   {
48      //we must set the color in linear space
49      LinearColorF linearColor = LinearColorF(ColorI(red, green, blue, alpha));
50      mPackedColorData = linearColor.getRGBAPack();
51      mDeviceSwizzle->InPlace( &mPackedColorData, sizeof( mPackedColorData ) );
52   }
53
54   void set( const ColorI &color )
55   {
56      //we must set the color in linear space
57      LinearColorF linearColor = LinearColorF(color);
58      mPackedColorData = linearColor.getRGBAPack();
59      mDeviceSwizzle->InPlace(&mPackedColorData, sizeof(mPackedColorData));
60   }
61
62   void set(const LinearColorF &color)
63   {
64      mPackedColorData = color.getRGBAPack();
65      mDeviceSwizzle->InPlace(&mPackedColorData, sizeof(mPackedColorData));
66   }
67
68   GFXVertexColor &operator=( const ColorI &color ) { set( color ); return *this; }
69   GFXVertexColor &operator=( const LinearColorF &color ) { set(color); return *this; }
70
71   operator const U32 *() const { return &mPackedColorData; }
72   const U32& getPackedColorData() const { return mPackedColorData; }
73
74   void getColor( ColorI *outColor ) const
75   {
76      ColorI linearColor;
77      mDeviceSwizzle->ToBuffer( &linearColor, &mPackedColorData, sizeof( mPackedColorData ) );
78      //convert color back to srgb space
79      *outColor = linearColor.fromLinear();
80   }
81};
82
83#endif
84