UserRenderInstanceBufferDesc.h
Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2018 NVIDIA Corporation. All rights reserved.
00027 
00028 
00029 
00030 #ifndef USER_RENDER_INSTANCE_BUFFER_DESC_H
00031 #define USER_RENDER_INSTANCE_BUFFER_DESC_H
00032 
00038 #include "UserRenderResourceManager.h"
00039 #include "RenderDataFormat.h"
00040 
00041 namespace physx
00042 {
00043     class PxCudaContextManager;
00044 };
00045 
00046 namespace nvidia
00047 {
00048 namespace apex
00049 {
00050 
00051 PX_PUSH_PACK_DEFAULT
00052 
00053 #if !PX_PS4
00054     #pragma warning(push)
00055     #pragma warning(disable:4121)
00056 #endif  //!PX_PS4
00057 
00061 struct RenderInstanceSemantic
00062 {
00066     enum Enum
00067     {
00068         POSITION = 0,   
00069         ROTATION_SCALE, 
00070         VELOCITY_LIFE,  
00071         DENSITY,        
00072         COLOR,          
00073         UV_OFFSET,      
00074         LOCAL_OFFSET,   
00075 
00076         USER_DATA,      
00077 
00078         POSE,           
00079 
00080         NUM_SEMANTICS   
00081     };
00082 };
00083 
00087 struct RenderInstanceLayoutElement
00088 {
00092     enum Enum
00093     {
00094         POSITION_FLOAT3,
00095         ROTATION_SCALE_FLOAT3x3,
00096         VELOCITY_LIFE_FLOAT4,
00097         DENSITY_FLOAT1,
00098         COLOR_RGBA8,
00099         COLOR_BGRA8,
00100         COLOR_FLOAT4,
00101         UV_OFFSET_FLOAT2,
00102         LOCAL_OFFSET_FLOAT3,
00103         USER_DATA_UINT1,
00104         POSE_FLOAT3x4,
00105 
00106         NUM_SEMANTICS
00107     };
00108 
00112     static PX_INLINE RenderDataFormat::Enum getSemanticFormat(Enum semantic)
00113     {
00114         switch (semantic)
00115         {
00116         case POSITION_FLOAT3:
00117             return RenderDataFormat::FLOAT3;        
00118         case ROTATION_SCALE_FLOAT3x3:
00119             return RenderDataFormat::FLOAT3x3;
00120         case VELOCITY_LIFE_FLOAT4:
00121             return RenderDataFormat::FLOAT4;
00122         case DENSITY_FLOAT1:
00123             return RenderDataFormat::FLOAT1;
00124         case COLOR_RGBA8:
00125             return RenderDataFormat::R8G8B8A8;
00126         case COLOR_BGRA8:
00127             return RenderDataFormat::B8G8R8A8;
00128         case COLOR_FLOAT4:
00129             return RenderDataFormat::FLOAT4;
00130         case UV_OFFSET_FLOAT2:
00131             return RenderDataFormat::FLOAT2;
00132         case LOCAL_OFFSET_FLOAT3:
00133             return RenderDataFormat::FLOAT3;
00134         case USER_DATA_UINT1:
00135             return RenderDataFormat::UINT1;
00136         case POSE_FLOAT3x4:
00137             return RenderDataFormat::FLOAT3x4;
00138         default:
00139             PX_ALWAYS_ASSERT();
00140             return RenderDataFormat::NUM_FORMATS;
00141         }
00142     }
00146     static PX_INLINE RenderInstanceSemantic::Enum getSemantic(Enum semantic)
00147     {
00148         switch (semantic)
00149         {
00150         case POSITION_FLOAT3:
00151             return RenderInstanceSemantic::POSITION;        
00152         case ROTATION_SCALE_FLOAT3x3:
00153             return RenderInstanceSemantic::ROTATION_SCALE;
00154         case VELOCITY_LIFE_FLOAT4:
00155             return RenderInstanceSemantic::VELOCITY_LIFE;
00156         case DENSITY_FLOAT1:
00157             return RenderInstanceSemantic::DENSITY;
00158         case COLOR_RGBA8:
00159         case COLOR_BGRA8:
00160         case COLOR_FLOAT4:
00161             return RenderInstanceSemantic::COLOR;
00162         case UV_OFFSET_FLOAT2:
00163             return RenderInstanceSemantic::UV_OFFSET;
00164         case LOCAL_OFFSET_FLOAT3:
00165             return RenderInstanceSemantic::LOCAL_OFFSET;
00166         case USER_DATA_UINT1:
00167             return RenderInstanceSemantic::USER_DATA;
00168         case POSE_FLOAT3x4:
00169             return RenderInstanceSemantic::POSE;
00170         default:
00171             PX_ALWAYS_ASSERT();
00172             return RenderInstanceSemantic::NUM_SEMANTICS;
00173         }
00174     }
00175 };
00176 
00180 class UserRenderInstanceBufferDesc
00181 {
00182 public:
00183     UserRenderInstanceBufferDesc(void)
00184     {
00185         setDefaults();
00186     }
00187 
00191     void setDefaults()
00192     {
00193         registerInCUDA = false;
00194         interopContext = 0;
00195         maxInstances = 0;
00196         hint         = RenderBufferHint::STATIC;
00197         for (uint32_t i = 0; i < RenderInstanceLayoutElement::NUM_SEMANTICS; i++)
00198         {
00199             semanticOffsets[i] = uint32_t(-1);
00200         }
00201         stride = 0;
00202     }
00203 
00207     bool isValid(void) const
00208     {
00209         uint32_t numFailed = 0;
00210 
00211         numFailed += (maxInstances == 0);
00212         numFailed += (stride == 0);
00213         numFailed += (semanticOffsets[RenderInstanceLayoutElement::POSITION_FLOAT3] == uint32_t(-1))
00214             && (semanticOffsets[RenderInstanceLayoutElement::POSE_FLOAT3x4] == uint32_t(-1));
00215         numFailed += registerInCUDA && (interopContext == 0);
00216 
00217         numFailed += ((stride & 0x03) != 0);
00218         for (uint32_t i = 0; i < RenderInstanceLayoutElement::NUM_SEMANTICS; i++)
00219         {
00220             if (semanticOffsets[i] != static_cast<uint32_t>(-1))
00221             {
00222                 numFailed += (semanticOffsets[i] >= stride);
00223                 numFailed += ((semanticOffsets[i] & 0x03) != 0);
00224             }
00225         }
00226 
00227         return (numFailed == 0);
00228     }
00229 
00233     bool isTheSameAs(const UserRenderInstanceBufferDesc& other) const
00234     {
00235         if (registerInCUDA != other.registerInCUDA) return false;
00236         if (maxInstances != other.maxInstances) return false;
00237         if (hint != other.hint) return false;
00238 
00239         if (stride != other.stride) return false;
00240         for (uint32_t i = 0; i < RenderInstanceLayoutElement::NUM_SEMANTICS; i++)
00241         {
00242             if (semanticOffsets[i] != other.semanticOffsets[i]) return false;
00243         }
00244         return true;
00245     }
00246 
00247 public:
00248     uint32_t                    maxInstances; 
00249     RenderBufferHint::Enum      hint; 
00250     
00254     uint32_t                    semanticOffsets[RenderInstanceLayoutElement::NUM_SEMANTICS];
00255 
00256     uint32_t                    stride; 
00257 
00258     bool                        registerInCUDA; 
00259 
00264     PxCudaContextManager*       interopContext;
00265 };
00266 
00267 #if !PX_PS4
00268     #pragma warning(pop)
00269 #endif  //!PX_PS4
00270 
00271 PX_POP_PACK
00272 
00273 }
00274 } // end namespace nvidia::apex
00275 
00276 #endif // USER_RENDER_INSTANCE_BUFFER_DESC_H

Generated on Sat Dec 1 2018 15:52:06

Copyright © 2012-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.