00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef IOFX_RENDER_CALLBACK_H
00031 #define IOFX_RENDER_CALLBACK_H
00032
00033 #include "foundation/Px.h"
00034 #include "UserRenderCallback.h"
00035
00036 namespace nvidia
00037 {
00038 namespace apex
00039 {
00040
00041 PX_PUSH_PACK_DEFAULT
00042
00043 class IofxRenderable;
00044 class IofxSpriteRenderable;
00045 class IofxMeshRenderable;
00046
00050 struct IofxRenderSemantic
00051 {
00055 enum Enum
00056 {
00057 POSITION = 0,
00058 COLOR,
00059 VELOCITY,
00060 SCALE,
00061 LIFE_REMAIN,
00062 DENSITY,
00063 SUBTEXTURE,
00064 ORIENTATION,
00065 ROTATION,
00066 USER_DATA,
00067
00068 NUM_SEMANTICS
00069 };
00070 };
00071
00072
00076 struct IofxSpriteRenderLayoutElement
00077 {
00081 enum Enum
00082 {
00083 POSITION_FLOAT3,
00084 COLOR_RGBA8,
00085 COLOR_BGRA8,
00086 COLOR_FLOAT4,
00087 VELOCITY_FLOAT3,
00088 SCALE_FLOAT2,
00089 LIFE_REMAIN_FLOAT1,
00090 DENSITY_FLOAT1,
00091 SUBTEXTURE_FLOAT1,
00092 ORIENTATION_FLOAT1,
00093 USER_DATA_UINT1,
00094
00095 MAX_COUNT
00096 };
00097
00101 static PX_INLINE RenderDataFormat::Enum getFormat(Enum element)
00102 {
00103 switch (element)
00104 {
00105 case POSITION_FLOAT3:
00106 return RenderDataFormat::FLOAT3;
00107 case COLOR_RGBA8:
00108 return RenderDataFormat::R8G8B8A8;
00109 case COLOR_BGRA8:
00110 return RenderDataFormat::B8G8R8A8;
00111 case COLOR_FLOAT4:
00112 return RenderDataFormat::FLOAT4;
00113 case VELOCITY_FLOAT3:
00114 return RenderDataFormat::FLOAT3;
00115 case SCALE_FLOAT2:
00116 return RenderDataFormat::FLOAT2;
00117 case LIFE_REMAIN_FLOAT1:
00118 return RenderDataFormat::FLOAT1;
00119 case DENSITY_FLOAT1:
00120 return RenderDataFormat::FLOAT1;
00121 case SUBTEXTURE_FLOAT1:
00122 return RenderDataFormat::FLOAT1;
00123 case ORIENTATION_FLOAT1:
00124 return RenderDataFormat::FLOAT1;
00125 case USER_DATA_UINT1:
00126 return RenderDataFormat::UINT1;
00127 default:
00128 PX_ALWAYS_ASSERT();
00129 return RenderDataFormat::NUM_FORMATS;
00130 }
00131 }
00132 };
00133
00137 struct IofxSpriteRenderLayoutSurfaceElement
00138 {
00142 enum Enum
00143 {
00144 POSITION_FLOAT4,
00145 SCALE_ORIENT_SUBTEX_FLOAT4,
00146 COLOR_RGBA8,
00147 COLOR_BGRA8,
00148 COLOR_FLOAT4,
00149
00150 MAX_COUNT
00151 };
00152
00156 static PX_INLINE RenderDataFormat::Enum getFormat(Enum element)
00157 {
00158 switch (element)
00159 {
00160 case POSITION_FLOAT4:
00161 return RenderDataFormat::FLOAT4;
00162 case SCALE_ORIENT_SUBTEX_FLOAT4:
00163 return RenderDataFormat::FLOAT4;
00164 case COLOR_RGBA8:
00165 return RenderDataFormat::R8G8B8A8;
00166 case COLOR_BGRA8:
00167 return RenderDataFormat::B8G8R8A8;
00168 case COLOR_FLOAT4:
00169 return RenderDataFormat::R32G32B32A32_FLOAT;
00170 default:
00171 PX_ALWAYS_ASSERT();
00172 return RenderDataFormat::NUM_FORMATS;
00173 }
00174 }
00175 };
00176
00180 struct IofxSpriteRenderLayout
00181 {
00182 IofxSpriteRenderLayout(void)
00183 {
00184 setDefaults();
00185 }
00186
00190 void setDefaults()
00191 {
00192 bufferDesc.setDefaults();
00193 for (uint32_t i = 0; i < IofxSpriteRenderLayoutElement::MAX_COUNT; i++)
00194 {
00195 offsets[i] = uint32_t(-1);
00196 }
00197 stride = 0;
00198 surfaceCount = 0;
00199 for (uint32_t i = 0; i < MAX_SURFACE_COUNT; i++)
00200 {
00201 surfaceElements[i] = IofxSpriteRenderLayoutSurfaceElement::MAX_COUNT;
00202 }
00203 }
00204
00208 bool isValid(void) const
00209 {
00210 uint32_t numFailed = 0;
00211
00212 numFailed += (surfaceCount == 0) && !bufferDesc.isValid();
00213 numFailed += (surfaceCount == 0) && (stride == 0);
00214 numFailed += (surfaceCount == 0) && (offsets[IofxSpriteRenderLayoutElement::POSITION_FLOAT3] == uint32_t(-1));
00215
00216 numFailed += ((stride & 0x03) != 0);
00217 for (uint32_t i = 0; i < IofxSpriteRenderLayoutElement::MAX_COUNT; i++)
00218 {
00219 if (offsets[i] != static_cast<uint32_t>(-1))
00220 {
00221 numFailed += (offsets[i] >= stride);
00222 numFailed += ((offsets[i] & 0x03) != 0);
00223 }
00224 }
00225 for (uint32_t i= 0; i < surfaceCount; ++i)
00226 {
00227 numFailed += (surfaceElements[i] >= IofxSpriteRenderLayoutSurfaceElement::MAX_COUNT);
00228 numFailed += !surfaceDescs[i].isValid();
00229 numFailed += (surfaceDescs[i].width == 0) || (surfaceDescs[i].height == 0);
00230 numFailed += (IofxSpriteRenderLayoutSurfaceElement::getFormat(surfaceElements[i]) != surfaceDescs[i].format);
00231 }
00232
00233 return (numFailed == 0);
00234 }
00235
00239 bool isTheSameAs(const IofxSpriteRenderLayout& other) const
00240 {
00241 if (surfaceCount != other.surfaceCount) return false;
00242 if (surfaceCount == 0)
00243 {
00244 if (!bufferDesc.isTheSameAs(other.bufferDesc)) return false;
00245 if (stride != other.stride) return false;
00246 for (uint32_t i = 0; i < IofxSpriteRenderLayoutElement::MAX_COUNT; i++)
00247 {
00248 if (offsets[i] != other.offsets[i]) return false;
00249 }
00250 }
00251 else
00252 {
00253 for (uint32_t i = 0; i < surfaceCount; ++i)
00254 {
00255 if (surfaceElements[i] != other.surfaceElements[i]) return false;
00256 if (!surfaceDescs[i].isTheSameAs(other.surfaceDescs[i])) return false;
00257 }
00258 }
00259 return true;
00260 }
00261
00262 public:
00263 UserRenderBufferDesc bufferDesc;
00264
00268 uint32_t offsets[IofxSpriteRenderLayoutElement::MAX_COUNT];
00269 uint32_t stride;
00270
00271 uint32_t surfaceCount;
00272
00276 static const uint32_t MAX_SURFACE_COUNT = 4;
00277
00281 IofxSpriteRenderLayoutSurfaceElement::Enum surfaceElements[MAX_SURFACE_COUNT];
00285 UserRenderSurfaceDesc surfaceDescs[MAX_SURFACE_COUNT];
00286 };
00287
00288
00292 struct IofxMeshRenderLayoutElement
00293 {
00297 enum Enum
00298 {
00299 POSITION_FLOAT3,
00300 ROTATION_SCALE_FLOAT3x3,
00301 POSE_FLOAT3x4,
00302 VELOCITY_LIFE_FLOAT4,
00303 DENSITY_FLOAT1,
00304 COLOR_RGBA8,
00305 COLOR_BGRA8,
00306 COLOR_FLOAT4,
00307 USER_DATA_UINT1,
00308
00309 MAX_COUNT
00310 };
00311
00315 static PX_INLINE RenderDataFormat::Enum getFormat(Enum element)
00316 {
00317 switch (element)
00318 {
00319 case POSITION_FLOAT3:
00320 return RenderDataFormat::FLOAT3;
00321 case ROTATION_SCALE_FLOAT3x3:
00322 return RenderDataFormat::FLOAT3x3;
00323 case POSE_FLOAT3x4:
00324 return RenderDataFormat::FLOAT3x4;
00325 case VELOCITY_LIFE_FLOAT4:
00326 return RenderDataFormat::FLOAT4;
00327 case DENSITY_FLOAT1:
00328 return RenderDataFormat::FLOAT1;
00329 case COLOR_RGBA8:
00330 return RenderDataFormat::R8G8B8A8;
00331 case COLOR_BGRA8:
00332 return RenderDataFormat::B8G8R8A8;
00333 case COLOR_FLOAT4:
00334 return RenderDataFormat::FLOAT4;
00335 case USER_DATA_UINT1:
00336 return RenderDataFormat::UINT1;
00337 default:
00338 PX_ALWAYS_ASSERT();
00339 return RenderDataFormat::NUM_FORMATS;
00340 }
00341 }
00342 };
00343
00347 struct IofxMeshRenderLayout
00348 {
00349 IofxMeshRenderLayout(void)
00350 {
00351 setDefaults();
00352 }
00353
00357 void setDefaults()
00358 {
00359 bufferDesc.setDefaults();
00360 for (uint32_t i = 0; i < IofxMeshRenderLayoutElement::MAX_COUNT; i++)
00361 {
00362 offsets[i] = uint32_t(-1);
00363 }
00364 stride = 0;
00365 }
00366
00370 bool isValid(void) const
00371 {
00372 uint32_t numFailed = 0;
00373
00374 numFailed += !bufferDesc.isValid();
00375 numFailed += (stride == 0);
00376 numFailed += (offsets[IofxMeshRenderLayoutElement::POSITION_FLOAT3] == uint32_t(-1))
00377 && (offsets[IofxMeshRenderLayoutElement::POSE_FLOAT3x4] == uint32_t(-1));
00378
00379 numFailed += ((stride & 0x03) != 0);
00380 for (uint32_t i = 0; i < IofxMeshRenderLayoutElement::MAX_COUNT; i++)
00381 {
00382 if (offsets[i] != static_cast<uint32_t>(-1))
00383 {
00384 numFailed += (offsets[i] >= stride);
00385 numFailed += ((offsets[i] & 0x03) != 0);
00386 }
00387 }
00388
00389 return (numFailed == 0);
00390 }
00391
00395 bool isTheSameAs(const IofxMeshRenderLayout& other) const
00396 {
00397 if (!bufferDesc.isTheSameAs(other.bufferDesc)) return false;
00398 if (stride != other.stride) return false;
00399 for (uint32_t i = 0; i < IofxMeshRenderLayoutElement::MAX_COUNT; i++)
00400 {
00401 if (offsets[i] != other.offsets[i]) return false;
00402 }
00403 return true;
00404 }
00405
00406 public:
00407 UserRenderBufferDesc bufferDesc;
00408
00412 uint32_t offsets[IofxMeshRenderLayoutElement::MAX_COUNT];
00413 uint32_t stride;
00414 };
00415
00416
00420 class IofxRenderCallback : public UserRenderCallback
00421 {
00422 public:
00426 virtual void onCreatedIofxRenderable(IofxRenderable& ) {}
00427
00431 virtual void onUpdatedIofxRenderable(IofxRenderable& ) {}
00432
00436 virtual void onReleasingIofxRenderable(IofxRenderable& ) {}
00437
00445 virtual bool getIofxSpriteRenderLayout(IofxSpriteRenderLayout& spriteRenderLayout, uint32_t spriteCount, uint32_t spriteSemanticsBitmap, RenderInteropFlags::Enum interopFlags)
00446 {
00447 PX_UNUSED(spriteRenderLayout);
00448 PX_UNUSED(spriteCount);
00449 PX_UNUSED(spriteSemanticsBitmap);
00450 PX_UNUSED(interopFlags);
00451 return false;
00452 }
00453
00461 virtual bool getIofxMeshRenderLayout(IofxMeshRenderLayout& meshRenderLayout, uint32_t meshCount, uint32_t meshSemanticsBitmap, RenderInteropFlags::Enum interopFlags)
00462 {
00463 PX_UNUSED(meshRenderLayout);
00464 PX_UNUSED(meshCount);
00465 PX_UNUSED(meshSemanticsBitmap);
00466 PX_UNUSED(interopFlags);
00467 return false;
00468 }
00469
00470 };
00471
00472 PX_POP_PACK
00473
00474 }
00475 }
00476
00477 #endif // IOFX_RENDER_CALLBACK_H