APEX Framework: UserRenderInstanceBufferDesc.h Source File

NVIDIA APEX

UserRenderInstanceBufferDesc.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 USER_RENDER_INSTANCE_BUFFER_DESC_H
00013 #define USER_RENDER_INSTANCE_BUFFER_DESC_H
00014 
00020 #include "UserRenderResourceManager.h"
00021 #include "RenderDataFormat.h"
00022 
00023 namespace physx
00024 {
00025     class PxCudaContextManager;
00026 };
00027 
00028 namespace nvidia
00029 {
00030 namespace apex
00031 {
00032 
00033 PX_PUSH_PACK_DEFAULT
00034 
00035 #if !PX_PS4
00036     #pragma warning(push)
00037     #pragma warning(disable:4121)
00038 #endif  //!PX_PS4
00039 
00043 struct RenderInstanceSemantic
00044 {
00048     enum Enum
00049     {
00050         POSITION = 0,   
00051         ROTATION_SCALE, 
00052         VELOCITY_LIFE,  
00053         DENSITY,        
00054         COLOR,          
00055         UV_OFFSET,      
00056         LOCAL_OFFSET,   
00057 
00058         USER_DATA,      
00059 
00060         POSE,           
00061 
00062         NUM_SEMANTICS   
00063     };
00064 };
00065 
00069 struct RenderInstanceLayoutElement
00070 {
00074     enum Enum
00075     {
00076         POSITION_FLOAT3,
00077         ROTATION_SCALE_FLOAT3x3,
00078         VELOCITY_LIFE_FLOAT4,
00079         DENSITY_FLOAT1,
00080         COLOR_RGBA8,
00081         COLOR_BGRA8,
00082         COLOR_FLOAT4,
00083         UV_OFFSET_FLOAT2,
00084         LOCAL_OFFSET_FLOAT3,
00085         USER_DATA_UINT1,
00086         POSE_FLOAT3x4,
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 ROTATION_SCALE_FLOAT3x3:
00101             return RenderDataFormat::FLOAT3x3;
00102         case VELOCITY_LIFE_FLOAT4:
00103             return RenderDataFormat::FLOAT4;
00104         case DENSITY_FLOAT1:
00105             return RenderDataFormat::FLOAT1;
00106         case COLOR_RGBA8:
00107             return RenderDataFormat::R8G8B8A8;
00108         case COLOR_BGRA8:
00109             return RenderDataFormat::B8G8R8A8;
00110         case COLOR_FLOAT4:
00111             return RenderDataFormat::FLOAT4;
00112         case UV_OFFSET_FLOAT2:
00113             return RenderDataFormat::FLOAT2;
00114         case LOCAL_OFFSET_FLOAT3:
00115             return RenderDataFormat::FLOAT3;
00116         case USER_DATA_UINT1:
00117             return RenderDataFormat::UINT1;
00118         case POSE_FLOAT3x4:
00119             return RenderDataFormat::FLOAT3x4;
00120         default:
00121             PX_ALWAYS_ASSERT();
00122             return RenderDataFormat::NUM_FORMATS;
00123         }
00124     }
00128     static PX_INLINE RenderInstanceSemantic::Enum getSemantic(Enum semantic)
00129     {
00130         switch (semantic)
00131         {
00132         case POSITION_FLOAT3:
00133             return RenderInstanceSemantic::POSITION;        
00134         case ROTATION_SCALE_FLOAT3x3:
00135             return RenderInstanceSemantic::ROTATION_SCALE;
00136         case VELOCITY_LIFE_FLOAT4:
00137             return RenderInstanceSemantic::VELOCITY_LIFE;
00138         case DENSITY_FLOAT1:
00139             return RenderInstanceSemantic::DENSITY;
00140         case COLOR_RGBA8:
00141         case COLOR_BGRA8:
00142         case COLOR_FLOAT4:
00143             return RenderInstanceSemantic::COLOR;
00144         case UV_OFFSET_FLOAT2:
00145             return RenderInstanceSemantic::UV_OFFSET;
00146         case LOCAL_OFFSET_FLOAT3:
00147             return RenderInstanceSemantic::LOCAL_OFFSET;
00148         case USER_DATA_UINT1:
00149             return RenderInstanceSemantic::USER_DATA;
00150         case POSE_FLOAT3x4:
00151             return RenderInstanceSemantic::POSE;
00152         default:
00153             PX_ALWAYS_ASSERT();
00154             return RenderInstanceSemantic::NUM_SEMANTICS;
00155         }
00156     }
00157 };
00158 
00162 class UserRenderInstanceBufferDesc
00163 {
00164 public:
00165     UserRenderInstanceBufferDesc(void)
00166     {
00167         setDefaults();
00168     }
00169 
00173     void setDefaults()
00174     {
00175         registerInCUDA = false;
00176         interopContext = 0;
00177         maxInstances = 0;
00178         hint         = RenderBufferHint::STATIC;
00179         for (uint32_t i = 0; i < RenderInstanceLayoutElement::NUM_SEMANTICS; i++)
00180         {
00181             semanticOffsets[i] = uint32_t(-1);
00182         }
00183         stride = 0;
00184     }
00185 
00189     bool isValid(void) const
00190     {
00191         uint32_t numFailed = 0;
00192 
00193         numFailed += (maxInstances == 0);
00194         numFailed += (stride == 0);
00195         numFailed += (semanticOffsets[RenderInstanceLayoutElement::POSITION_FLOAT3] == uint32_t(-1))
00196             && (semanticOffsets[RenderInstanceLayoutElement::POSE_FLOAT3x4] == uint32_t(-1));
00197         numFailed += registerInCUDA && (interopContext == 0);
00198 
00199         numFailed += ((stride & 0x03) != 0);
00200         for (uint32_t i = 0; i < RenderInstanceLayoutElement::NUM_SEMANTICS; i++)
00201         {
00202             if (semanticOffsets[i] != static_cast<uint32_t>(-1))
00203             {
00204                 numFailed += (semanticOffsets[i] >= stride);
00205                 numFailed += ((semanticOffsets[i] & 0x03) != 0);
00206             }
00207         }
00208 
00209         return (numFailed == 0);
00210     }
00211 
00215     bool isTheSameAs(const UserRenderInstanceBufferDesc& other) const
00216     {
00217         if (registerInCUDA != other.registerInCUDA) return false;
00218         if (maxInstances != other.maxInstances) return false;
00219         if (hint != other.hint) return false;
00220 
00221         if (stride != other.stride) return false;
00222         for (uint32_t i = 0; i < RenderInstanceLayoutElement::NUM_SEMANTICS; i++)
00223         {
00224             if (semanticOffsets[i] != other.semanticOffsets[i]) return false;
00225         }
00226         return true;
00227     }
00228 
00229 public:
00230     uint32_t                    maxInstances; 
00231     RenderBufferHint::Enum      hint; 
00232     
00236     uint32_t                    semanticOffsets[RenderInstanceLayoutElement::NUM_SEMANTICS];
00237 
00238     uint32_t                    stride; 
00239 
00240     bool                        registerInCUDA; 
00241 
00246     PxCudaContextManager*       interopContext;
00247 };
00248 
00249 #if !PX_PS4
00250     #pragma warning(pop)
00251 #endif  //!PX_PS4
00252 
00253 PX_POP_PACK
00254 
00255 }
00256 } // end namespace nvidia::apex
00257 
00258 #endif // USER_RENDER_INSTANCE_BUFFER_DESC_H

Generated on Fri Dec 15 2017 13:58:35
Copyright © 2012-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.