IofxRenderCallback.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved. 00003 * 00004 * NVIDIA CORPORATION and its licensors retain all intellectual property 00005 * and proprietary rights in and to this software, related documentation 00006 * and any modifications thereto. Any use, reproduction, disclosure or 00007 * distribution of this software and related documentation without an express 00008 * license agreement from NVIDIA CORPORATION is strictly prohibited. 00009 */ 00010 00011 00012 #ifndef IOFX_RENDER_CALLBACK_H 00013 #define IOFX_RENDER_CALLBACK_H 00014 00015 #include "foundation/Px.h" 00016 #include "UserRenderCallback.h" 00017 00018 namespace nvidia 00019 { 00020 namespace apex 00021 { 00022 00023 PX_PUSH_PACK_DEFAULT 00024 00025 class IofxRenderable; 00026 class IofxSpriteRenderable; 00027 class IofxMeshRenderable; 00028 00032 struct IofxRenderSemantic 00033 { 00037 enum Enum 00038 { 00039 POSITION = 0, 00040 COLOR, 00041 VELOCITY, 00042 SCALE, 00043 LIFE_REMAIN, 00044 DENSITY, 00045 SUBTEXTURE, 00046 ORIENTATION, 00047 ROTATION, 00048 USER_DATA, 00049 00050 NUM_SEMANTICS 00051 }; 00052 }; 00053 00054 00058 struct IofxSpriteRenderLayoutElement 00059 { 00063 enum Enum 00064 { 00065 POSITION_FLOAT3, 00066 COLOR_RGBA8, 00067 COLOR_BGRA8, 00068 COLOR_FLOAT4, 00069 VELOCITY_FLOAT3, 00070 SCALE_FLOAT2, 00071 LIFE_REMAIN_FLOAT1, 00072 DENSITY_FLOAT1, 00073 SUBTEXTURE_FLOAT1, 00074 ORIENTATION_FLOAT1, 00075 USER_DATA_UINT1, 00076 00077 MAX_COUNT 00078 }; 00079 00083 static PX_INLINE RenderDataFormat::Enum getFormat(Enum element) 00084 { 00085 switch (element) 00086 { 00087 case POSITION_FLOAT3: 00088 return RenderDataFormat::FLOAT3; 00089 case COLOR_RGBA8: 00090 return RenderDataFormat::R8G8B8A8; 00091 case COLOR_BGRA8: 00092 return RenderDataFormat::B8G8R8A8; 00093 case COLOR_FLOAT4: 00094 return RenderDataFormat::FLOAT4; 00095 case VELOCITY_FLOAT3: 00096 return RenderDataFormat::FLOAT3; 00097 case SCALE_FLOAT2: 00098 return RenderDataFormat::FLOAT2; 00099 case LIFE_REMAIN_FLOAT1: 00100 return RenderDataFormat::FLOAT1; 00101 case DENSITY_FLOAT1: 00102 return RenderDataFormat::FLOAT1; 00103 case SUBTEXTURE_FLOAT1: 00104 return RenderDataFormat::FLOAT1; 00105 case ORIENTATION_FLOAT1: 00106 return RenderDataFormat::FLOAT1; 00107 case USER_DATA_UINT1: 00108 return RenderDataFormat::UINT1; 00109 default: 00110 PX_ALWAYS_ASSERT(); 00111 return RenderDataFormat::NUM_FORMATS; 00112 } 00113 } 00114 }; 00115 00119 struct IofxSpriteRenderLayoutSurfaceElement 00120 { 00124 enum Enum 00125 { 00126 POSITION_FLOAT4, 00127 SCALE_ORIENT_SUBTEX_FLOAT4, 00128 COLOR_RGBA8, //<! COLOR in RGBA8 format 00129 COLOR_BGRA8, //<! COLOR in BGRA8 format 00130 COLOR_FLOAT4, //<! COLOR in FLOAT4 format 00131 00132 MAX_COUNT 00133 }; 00134 00138 static PX_INLINE RenderDataFormat::Enum getFormat(Enum element) 00139 { 00140 switch (element) 00141 { 00142 case POSITION_FLOAT4: 00143 return RenderDataFormat::FLOAT4; 00144 case SCALE_ORIENT_SUBTEX_FLOAT4: 00145 return RenderDataFormat::FLOAT4; 00146 case COLOR_RGBA8: 00147 return RenderDataFormat::R8G8B8A8; 00148 case COLOR_BGRA8: 00149 return RenderDataFormat::B8G8R8A8; 00150 case COLOR_FLOAT4: 00151 return RenderDataFormat::R32G32B32A32_FLOAT; 00152 default: 00153 PX_ALWAYS_ASSERT(); 00154 return RenderDataFormat::NUM_FORMATS; 00155 } 00156 } 00157 }; 00158 00162 struct IofxSpriteRenderLayout 00163 { 00164 IofxSpriteRenderLayout(void) 00165 { 00166 setDefaults(); 00167 } 00168 00172 void setDefaults() 00173 { 00174 bufferDesc.setDefaults(); 00175 for (uint32_t i = 0; i < IofxSpriteRenderLayoutElement::MAX_COUNT; i++) 00176 { 00177 offsets[i] = uint32_t(-1); 00178 } 00179 stride = 0; 00180 surfaceCount = 0; 00181 for (uint32_t i = 0; i < MAX_SURFACE_COUNT; i++) 00182 { 00183 surfaceElements[i] = IofxSpriteRenderLayoutSurfaceElement::MAX_COUNT; 00184 } 00185 } 00186 00190 bool isValid(void) const 00191 { 00192 uint32_t numFailed = 0; 00193 00194 numFailed += (surfaceCount == 0) && !bufferDesc.isValid(); 00195 numFailed += (surfaceCount == 0) && (stride == 0); 00196 numFailed += (surfaceCount == 0) && (offsets[IofxSpriteRenderLayoutElement::POSITION_FLOAT3] == uint32_t(-1)); 00197 00198 numFailed += ((stride & 0x03) != 0); 00199 for (uint32_t i = 0; i < IofxSpriteRenderLayoutElement::MAX_COUNT; i++) 00200 { 00201 if (offsets[i] != static_cast<uint32_t>(-1)) 00202 { 00203 numFailed += (offsets[i] >= stride); 00204 numFailed += ((offsets[i] & 0x03) != 0); 00205 } 00206 } 00207 for (uint32_t i= 0; i < surfaceCount; ++i) 00208 { 00209 numFailed += (surfaceElements[i] >= IofxSpriteRenderLayoutSurfaceElement::MAX_COUNT); 00210 numFailed += !surfaceDescs[i].isValid(); 00211 numFailed += (surfaceDescs[i].width == 0) || (surfaceDescs[i].height == 0); 00212 numFailed += (IofxSpriteRenderLayoutSurfaceElement::getFormat(surfaceElements[i]) != surfaceDescs[i].format); 00213 } 00214 00215 return (numFailed == 0); 00216 } 00217 00221 bool isTheSameAs(const IofxSpriteRenderLayout& other) const 00222 { 00223 if (surfaceCount != other.surfaceCount) return false; 00224 if (surfaceCount == 0) 00225 { 00226 if (!bufferDesc.isTheSameAs(other.bufferDesc)) return false; 00227 if (stride != other.stride) return false; 00228 for (uint32_t i = 0; i < IofxSpriteRenderLayoutElement::MAX_COUNT; i++) 00229 { 00230 if (offsets[i] != other.offsets[i]) return false; 00231 } 00232 } 00233 else 00234 { 00235 for (uint32_t i = 0; i < surfaceCount; ++i) 00236 { 00237 if (surfaceElements[i] != other.surfaceElements[i]) return false; 00238 if (!surfaceDescs[i].isTheSameAs(other.surfaceDescs[i])) return false; 00239 } 00240 } 00241 return true; 00242 } 00243 00244 public: 00245 UserRenderBufferDesc bufferDesc; 00246 00250 uint32_t offsets[IofxSpriteRenderLayoutElement::MAX_COUNT]; 00251 uint32_t stride; 00252 00253 uint32_t surfaceCount; 00254 00258 static const uint32_t MAX_SURFACE_COUNT = 4; 00259 00263 IofxSpriteRenderLayoutSurfaceElement::Enum surfaceElements[MAX_SURFACE_COUNT]; 00267 UserRenderSurfaceDesc surfaceDescs[MAX_SURFACE_COUNT]; 00268 }; 00269 00270 00274 struct IofxMeshRenderLayoutElement 00275 { 00279 enum Enum 00280 { 00281 POSITION_FLOAT3, 00282 ROTATION_SCALE_FLOAT3x3, 00283 POSE_FLOAT3x4, 00284 VELOCITY_LIFE_FLOAT4, 00285 DENSITY_FLOAT1, 00286 COLOR_RGBA8, 00287 COLOR_BGRA8, 00288 COLOR_FLOAT4, 00289 USER_DATA_UINT1, 00290 00291 MAX_COUNT 00292 }; 00293 00297 static PX_INLINE RenderDataFormat::Enum getFormat(Enum element) 00298 { 00299 switch (element) 00300 { 00301 case POSITION_FLOAT3: 00302 return RenderDataFormat::FLOAT3; 00303 case ROTATION_SCALE_FLOAT3x3: 00304 return RenderDataFormat::FLOAT3x3; 00305 case POSE_FLOAT3x4: 00306 return RenderDataFormat::FLOAT3x4; 00307 case VELOCITY_LIFE_FLOAT4: 00308 return RenderDataFormat::FLOAT4; 00309 case DENSITY_FLOAT1: 00310 return RenderDataFormat::FLOAT1; 00311 case COLOR_RGBA8: 00312 return RenderDataFormat::R8G8B8A8; 00313 case COLOR_BGRA8: 00314 return RenderDataFormat::B8G8R8A8; 00315 case COLOR_FLOAT4: 00316 return RenderDataFormat::FLOAT4; 00317 case USER_DATA_UINT1: 00318 return RenderDataFormat::UINT1; 00319 default: 00320 PX_ALWAYS_ASSERT(); 00321 return RenderDataFormat::NUM_FORMATS; 00322 } 00323 } 00324 }; 00325 00329 struct IofxMeshRenderLayout 00330 { 00331 IofxMeshRenderLayout(void) 00332 { 00333 setDefaults(); 00334 } 00335 00339 void setDefaults() 00340 { 00341 bufferDesc.setDefaults(); 00342 for (uint32_t i = 0; i < IofxMeshRenderLayoutElement::MAX_COUNT; i++) 00343 { 00344 offsets[i] = uint32_t(-1); 00345 } 00346 stride = 0; 00347 } 00348 00352 bool isValid(void) const 00353 { 00354 uint32_t numFailed = 0; 00355 00356 numFailed += !bufferDesc.isValid(); 00357 numFailed += (stride == 0); 00358 numFailed += (offsets[IofxMeshRenderLayoutElement::POSITION_FLOAT3] == uint32_t(-1)) 00359 && (offsets[IofxMeshRenderLayoutElement::POSE_FLOAT3x4] == uint32_t(-1)); 00360 00361 numFailed += ((stride & 0x03) != 0); 00362 for (uint32_t i = 0; i < IofxMeshRenderLayoutElement::MAX_COUNT; i++) 00363 { 00364 if (offsets[i] != static_cast<uint32_t>(-1)) 00365 { 00366 numFailed += (offsets[i] >= stride); 00367 numFailed += ((offsets[i] & 0x03) != 0); 00368 } 00369 } 00370 00371 return (numFailed == 0); 00372 } 00373 00377 bool isTheSameAs(const IofxMeshRenderLayout& other) const 00378 { 00379 if (!bufferDesc.isTheSameAs(other.bufferDesc)) return false; 00380 if (stride != other.stride) return false; 00381 for (uint32_t i = 0; i < IofxMeshRenderLayoutElement::MAX_COUNT; i++) 00382 { 00383 if (offsets[i] != other.offsets[i]) return false; 00384 } 00385 return true; 00386 } 00387 00388 public: 00389 UserRenderBufferDesc bufferDesc; 00390 00394 uint32_t offsets[IofxMeshRenderLayoutElement::MAX_COUNT]; 00395 uint32_t stride; 00396 }; 00397 00398 00402 class IofxRenderCallback : public UserRenderCallback 00403 { 00404 public: 00408 virtual void onCreatedIofxRenderable(IofxRenderable& ) {} 00409 00413 virtual void onUpdatedIofxRenderable(IofxRenderable& ) {} 00414 00418 virtual void onReleasingIofxRenderable(IofxRenderable& ) {} 00419 00427 virtual bool getIofxSpriteRenderLayout(IofxSpriteRenderLayout& spriteRenderLayout, uint32_t spriteCount, uint32_t spriteSemanticsBitmap, RenderInteropFlags::Enum interopFlags) 00428 { 00429 PX_UNUSED(spriteRenderLayout); 00430 PX_UNUSED(spriteCount); 00431 PX_UNUSED(spriteSemanticsBitmap); 00432 PX_UNUSED(interopFlags); 00433 return false; 00434 } 00435 00443 virtual bool getIofxMeshRenderLayout(IofxMeshRenderLayout& meshRenderLayout, uint32_t meshCount, uint32_t meshSemanticsBitmap, RenderInteropFlags::Enum interopFlags) 00444 { 00445 PX_UNUSED(meshRenderLayout); 00446 PX_UNUSED(meshCount); 00447 PX_UNUSED(meshSemanticsBitmap); 00448 PX_UNUSED(interopFlags); 00449 return false; 00450 } 00451 00452 }; 00453 00454 PX_POP_PACK 00455 00456 } 00457 } // end namespace nvidia 00458 00459 #endif // IOFX_RENDER_CALLBACK_H
Generated on Fri Dec 15 2017 13:59:03 Copyright © 2012-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.