Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef USER_RENDER_SPRITE_BUFFER_DESC_H
00013 #define USER_RENDER_SPRITE_BUFFER_DESC_H
00014
00020 #include "ApexUsingNamespace.h"
00021 #include "RenderDataFormat.h"
00022 #include "UserRenderResourceManager.h"
00023
00024 namespace physx
00025 {
00026 class PxCudaContextManager;
00027 };
00028
00029 namespace nvidia
00030 {
00031 namespace apex
00032 {
00033
00034 PX_PUSH_PACK_DEFAULT
00035
00036 #if !PX_PS4
00037 #pragma warning(push)
00038 #pragma warning(disable:4121)
00039 #endif //!PX_PS4
00040
00044 struct RenderSpriteSemantic
00045 {
00049 enum Enum
00050 {
00051 POSITION = 0,
00052 COLOR,
00053 VELOCITY,
00054 SCALE,
00055 LIFE_REMAIN,
00056 DENSITY,
00057 SUBTEXTURE,
00058 ORIENTATION,
00059
00060 USER_DATA,
00061
00062 NUM_SEMANTICS
00063 };
00064 };
00065
00069 struct RenderSpriteLayoutElement
00070 {
00074 enum Enum
00075 {
00076 POSITION_FLOAT3,
00077 COLOR_RGBA8,
00078 COLOR_BGRA8,
00079 COLOR_FLOAT4,
00080 VELOCITY_FLOAT3,
00081 SCALE_FLOAT2,
00082 LIFE_REMAIN_FLOAT1,
00083 DENSITY_FLOAT1,
00084 SUBTEXTURE_FLOAT1,
00085 ORIENTATION_FLOAT1,
00086 USER_DATA_UINT1,
00087
00088 NUM_SEMANTICS
00089 };
00090
00094 static PX_INLINE RenderDataFormat::Enum getSemanticFormat(Enum semantic)
00095 {
00096 switch (semantic)
00097 {
00098 case POSITION_FLOAT3:
00099 return RenderDataFormat::FLOAT3;
00100 case COLOR_RGBA8:
00101 return RenderDataFormat::R8G8B8A8;
00102 case COLOR_BGRA8:
00103 return RenderDataFormat::B8G8R8A8;
00104 case COLOR_FLOAT4:
00105 return RenderDataFormat::FLOAT4;
00106 case VELOCITY_FLOAT3:
00107 return RenderDataFormat::FLOAT3;
00108 case SCALE_FLOAT2:
00109 return RenderDataFormat::FLOAT2;
00110 case LIFE_REMAIN_FLOAT1:
00111 return RenderDataFormat::FLOAT1;
00112 case DENSITY_FLOAT1:
00113 return RenderDataFormat::FLOAT1;
00114 case SUBTEXTURE_FLOAT1:
00115 return RenderDataFormat::FLOAT1;
00116 case ORIENTATION_FLOAT1:
00117 return RenderDataFormat::FLOAT1;
00118 case USER_DATA_UINT1:
00119 return RenderDataFormat::UINT1;
00120 default:
00121 PX_ALWAYS_ASSERT();
00122 return RenderDataFormat::NUM_FORMATS;
00123 }
00124 }
00128 static PX_INLINE RenderSpriteSemantic::Enum getSemantic(Enum semantic)
00129 {
00130 switch (semantic)
00131 {
00132 case POSITION_FLOAT3:
00133 return RenderSpriteSemantic::POSITION;
00134 case COLOR_RGBA8:
00135 case COLOR_BGRA8:
00136 case COLOR_FLOAT4:
00137 return RenderSpriteSemantic::COLOR;
00138 case VELOCITY_FLOAT3:
00139 return RenderSpriteSemantic::VELOCITY;
00140 case SCALE_FLOAT2:
00141 return RenderSpriteSemantic::SCALE;
00142 case LIFE_REMAIN_FLOAT1:
00143 return RenderSpriteSemantic::LIFE_REMAIN;
00144 case DENSITY_FLOAT1:
00145 return RenderSpriteSemantic::DENSITY;
00146 case SUBTEXTURE_FLOAT1:
00147 return RenderSpriteSemantic::SUBTEXTURE;
00148 case ORIENTATION_FLOAT1:
00149 return RenderSpriteSemantic::ORIENTATION;
00150 case USER_DATA_UINT1:
00151 return RenderSpriteSemantic::USER_DATA;
00152 default:
00153 PX_ALWAYS_ASSERT();
00154 return RenderSpriteSemantic::NUM_SEMANTICS;
00155 }
00156 }
00157 };
00158
00162 struct RenderSpriteTextureLayout
00163 {
00167 enum Enum
00168 {
00169 NONE = 0,
00170 POSITION_FLOAT4,
00171 SCALE_ORIENT_SUBTEX_FLOAT4,
00172 COLOR_RGBA8,
00173 COLOR_BGRA8,
00174 COLOR_FLOAT4,
00175 NUM_LAYOUTS
00176 };
00177
00181 static PX_INLINE RenderDataFormat::Enum getLayoutFormat(Enum layout)
00182 {
00183 switch (layout)
00184 {
00185 case NONE:
00186 return RenderDataFormat::UNSPECIFIED;
00187 case POSITION_FLOAT4:
00188 return RenderDataFormat::FLOAT4;
00189 case SCALE_ORIENT_SUBTEX_FLOAT4:
00190 return RenderDataFormat::FLOAT4;
00191 case COLOR_RGBA8:
00192 return RenderDataFormat::R8G8B8A8;
00193 case COLOR_BGRA8:
00194 return RenderDataFormat::B8G8R8A8;
00195 case COLOR_FLOAT4:
00196 return RenderDataFormat::R32G32B32A32_FLOAT;
00197 default:
00198 PX_ALWAYS_ASSERT();
00199 return RenderDataFormat::NUM_FORMATS;
00200 }
00201 }
00202
00203 };
00204
00208 class UserRenderSpriteTextureDesc
00209 {
00210 public:
00211 RenderSpriteTextureLayout::Enum layout;
00212 uint32_t width;
00213 uint32_t height;
00214 uint32_t pitchBytes;
00215 uint32_t arrayIndex;
00216 uint32_t mipLevel;
00217
00218 public:
00219 PX_INLINE UserRenderSpriteTextureDesc(void)
00220 {
00221 layout = RenderSpriteTextureLayout::NONE;
00222 width = 0;
00223 height = 0;
00224 pitchBytes = 0;
00225
00226 arrayIndex = 0;
00227 mipLevel = 0;
00228 }
00229
00233 bool isTheSameAs(const UserRenderSpriteTextureDesc& other) const
00234 {
00235 if (layout != other.layout) return false;
00236 if (width != other.width) return false;
00237 if (height != other.height) return false;
00238 if (pitchBytes != other.pitchBytes) return false;
00239 if (arrayIndex != other.arrayIndex) return false;
00240 if (mipLevel != other.mipLevel) return false;
00241 return true;
00242 }
00243 };
00244
00248 class UserRenderSpriteBufferDesc
00249 {
00250 public:
00254 static const uint32_t MAX_SPRITE_TEXTURES = 4;
00255
00256 UserRenderSpriteBufferDesc(void)
00257 {
00258 setDefaults();
00259 }
00260
00264 void setDefaults()
00265 {
00266 maxSprites = 0;
00267 hint = RenderBufferHint::STATIC;
00268 registerInCUDA = false;
00269 interopContext = 0;
00270
00271 for (uint32_t i = 0; i < RenderSpriteLayoutElement::NUM_SEMANTICS; i++)
00272 {
00273 semanticOffsets[i] = static_cast<uint32_t>(-1);
00274 }
00275 stride = 0;
00276
00277 textureCount = 0;
00278 }
00279
00283 bool isValid(void) const
00284 {
00285 uint32_t numFailed = 0;
00286
00287 numFailed += (maxSprites == 0);
00288 numFailed += (textureCount == 0) && (stride == 0);
00289 numFailed += (textureCount == 0) && (semanticOffsets[RenderSpriteLayoutElement::POSITION_FLOAT3] == uint32_t(-1));
00290 numFailed += registerInCUDA && (interopContext == 0);
00291
00292 numFailed += ((stride & 0x03) != 0);
00293 for (uint32_t i = 0; i < RenderSpriteLayoutElement::NUM_SEMANTICS; i++)
00294 {
00295 if (semanticOffsets[i] != static_cast<uint32_t>(-1))
00296 {
00297 numFailed += (semanticOffsets[i] >= stride);
00298 numFailed += ((semanticOffsets[i] & 0x03) != 0);
00299 }
00300 }
00301
00302 return (numFailed == 0);
00303 }
00304
00308 bool isTheSameAs(const UserRenderSpriteBufferDesc& other) const
00309 {
00310 if (registerInCUDA != other.registerInCUDA) return false;
00311 if (maxSprites != other.maxSprites) return false;
00312 if (hint != other.hint) return false;
00313 if (textureCount != other.textureCount) return false;
00314 if (textureCount == 0)
00315 {
00316 if (stride != other.stride) return false;
00317 for (uint32_t i = 0; i < RenderSpriteLayoutElement::NUM_SEMANTICS; i++)
00318 {
00319 if (semanticOffsets[i] != other.semanticOffsets[i]) return false;
00320 }
00321 }
00322 else
00323 {
00324 for (uint32_t i = 0; i < textureCount; i++)
00325 {
00326 if (textureDescs[i].isTheSameAs(other.textureDescs[i]) == false) return false;
00327 }
00328 }
00329 return true;
00330 }
00331
00332 public:
00333 uint32_t maxSprites;
00334 RenderBufferHint::Enum hint;
00335
00339 uint32_t semanticOffsets[RenderSpriteLayoutElement::NUM_SEMANTICS];
00340
00341 uint32_t stride;
00342
00343 bool registerInCUDA;
00344
00349 PxCudaContextManager* interopContext;
00350
00351 uint32_t textureCount;
00352 UserRenderSpriteTextureDesc textureDescs[MAX_SPRITE_TEXTURES];
00353 };
00354
00355 #if !PX_PS4
00356 #pragma warning(pop)
00357 #endif //!PX_PS4
00358
00359 PX_POP_PACK
00360
00361 }
00362 }
00363
00364 #endif // USER_RENDER_SPRITE_BUFFER_DESC_H