UserRenderSpriteBufferDesc.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_SPRITE_BUFFER_DESC_H
00031 #define USER_RENDER_SPRITE_BUFFER_DESC_H
00032 
00038 #include "ApexUsingNamespace.h"
00039 #include "RenderDataFormat.h"
00040 #include "UserRenderResourceManager.h"
00041 
00042 namespace physx
00043 {
00044     class PxCudaContextManager;
00045 };
00046 
00047 namespace nvidia
00048 {
00049 namespace apex
00050 {
00051 
00052 PX_PUSH_PACK_DEFAULT
00053 
00054 #if !PX_PS4
00055     #pragma warning(push)
00056     #pragma warning(disable:4121)
00057 #endif  //!PX_PS4
00058 
00062 struct RenderSpriteSemantic
00063 {
00067     enum Enum
00068     {
00069         POSITION = 0,   
00070         COLOR,          
00071         VELOCITY,       
00072         SCALE,          
00073         LIFE_REMAIN,    
00074         DENSITY,        
00075         SUBTEXTURE,     
00076         ORIENTATION,    
00077 
00078         USER_DATA,      
00079 
00080         NUM_SEMANTICS   
00081     };
00082 };
00083 
00087 struct RenderSpriteLayoutElement
00088 {
00092     enum Enum
00093     {
00094         POSITION_FLOAT3,
00095         COLOR_RGBA8,
00096         COLOR_BGRA8,
00097         COLOR_FLOAT4,
00098         VELOCITY_FLOAT3,
00099         SCALE_FLOAT2,
00100         LIFE_REMAIN_FLOAT1,
00101         DENSITY_FLOAT1,
00102         SUBTEXTURE_FLOAT1,
00103         ORIENTATION_FLOAT1,
00104         USER_DATA_UINT1,
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 COLOR_RGBA8:
00119             return RenderDataFormat::R8G8B8A8;
00120         case COLOR_BGRA8:
00121             return RenderDataFormat::B8G8R8A8;
00122         case COLOR_FLOAT4:
00123             return RenderDataFormat::FLOAT4;
00124         case VELOCITY_FLOAT3:
00125             return RenderDataFormat::FLOAT3;
00126         case SCALE_FLOAT2:
00127             return RenderDataFormat::FLOAT2;
00128         case LIFE_REMAIN_FLOAT1:
00129             return RenderDataFormat::FLOAT1;
00130         case DENSITY_FLOAT1:
00131             return RenderDataFormat::FLOAT1;
00132         case SUBTEXTURE_FLOAT1:
00133             return RenderDataFormat::FLOAT1;
00134         case ORIENTATION_FLOAT1:
00135             return RenderDataFormat::FLOAT1;
00136         case USER_DATA_UINT1:
00137             return RenderDataFormat::UINT1;
00138         default:
00139             PX_ALWAYS_ASSERT();
00140             return RenderDataFormat::NUM_FORMATS;
00141         }
00142     }
00146     static PX_INLINE RenderSpriteSemantic::Enum getSemantic(Enum semantic)
00147     {
00148         switch (semantic)
00149         {
00150         case POSITION_FLOAT3:
00151             return RenderSpriteSemantic::POSITION;
00152         case COLOR_RGBA8:
00153         case COLOR_BGRA8:
00154         case COLOR_FLOAT4:
00155             return RenderSpriteSemantic::COLOR;
00156         case VELOCITY_FLOAT3:
00157             return RenderSpriteSemantic::VELOCITY;
00158         case SCALE_FLOAT2:
00159             return RenderSpriteSemantic::SCALE;
00160         case LIFE_REMAIN_FLOAT1:
00161             return RenderSpriteSemantic::LIFE_REMAIN;
00162         case DENSITY_FLOAT1:
00163             return RenderSpriteSemantic::DENSITY;
00164         case SUBTEXTURE_FLOAT1:
00165             return RenderSpriteSemantic::SUBTEXTURE;
00166         case ORIENTATION_FLOAT1:
00167             return RenderSpriteSemantic::ORIENTATION;
00168         case USER_DATA_UINT1:
00169             return RenderSpriteSemantic::USER_DATA;
00170         default:
00171             PX_ALWAYS_ASSERT();
00172             return RenderSpriteSemantic::NUM_SEMANTICS;
00173         }
00174     }
00175 };
00176 
00180 struct RenderSpriteTextureLayout
00181 {
00185     enum Enum
00186     {
00187         NONE = 0,
00188         POSITION_FLOAT4, //float4(POSITION.x, POSITION.y, POSITION.z, 1)
00189         SCALE_ORIENT_SUBTEX_FLOAT4, //float4(SCALE.x, SCALE.y, ORIENTATION, SUBTEXTURE)
00190         COLOR_RGBA8,
00191         COLOR_BGRA8,
00192         COLOR_FLOAT4,
00193         NUM_LAYOUTS
00194     };
00195 
00199     static PX_INLINE RenderDataFormat::Enum getLayoutFormat(Enum layout)
00200     {
00201         switch (layout)
00202         {
00203         case NONE:
00204             return RenderDataFormat::UNSPECIFIED;
00205         case POSITION_FLOAT4:
00206             return RenderDataFormat::FLOAT4;
00207         case SCALE_ORIENT_SUBTEX_FLOAT4:
00208             return RenderDataFormat::FLOAT4;
00209         case COLOR_RGBA8:
00210             return RenderDataFormat::R8G8B8A8;
00211         case COLOR_BGRA8:
00212             return RenderDataFormat::B8G8R8A8;
00213         case COLOR_FLOAT4:
00214             return RenderDataFormat::R32G32B32A32_FLOAT;
00215         default:
00216             PX_ALWAYS_ASSERT();
00217             return RenderDataFormat::NUM_FORMATS;
00218         }
00219     }
00220 
00221 };
00222 
00226 class UserRenderSpriteTextureDesc
00227 {
00228 public:
00229     RenderSpriteTextureLayout::Enum layout; 
00230     uint32_t width;                         
00231     uint32_t height;                        
00232     uint32_t pitchBytes;                    
00233     uint32_t arrayIndex;                    
00234     uint32_t mipLevel;                      
00235 
00236 public:
00237     PX_INLINE UserRenderSpriteTextureDesc(void)
00238     {
00239         layout = RenderSpriteTextureLayout::NONE;
00240         width = 0;
00241         height = 0;
00242         pitchBytes = 0;
00243 
00244         arrayIndex = 0;
00245         mipLevel = 0;
00246     }
00247 
00251     bool isTheSameAs(const UserRenderSpriteTextureDesc& other) const
00252     {
00253         if (layout != other.layout) return false;
00254         if (width != other.width) return false;
00255         if (height != other.height) return false;
00256         if (pitchBytes != other.pitchBytes) return false;
00257         if (arrayIndex != other.arrayIndex) return false;
00258         if (mipLevel != other.mipLevel) return false;
00259         return true;
00260     }
00261 };
00262 
00266 class UserRenderSpriteBufferDesc
00267 {
00268 public:
00272     static const uint32_t MAX_SPRITE_TEXTURES = 4;
00273 
00274     UserRenderSpriteBufferDesc(void)
00275     {
00276         setDefaults();
00277     }
00278 
00282     void setDefaults()
00283     {
00284         maxSprites = 0;
00285         hint         = RenderBufferHint::STATIC;
00286         registerInCUDA = false;
00287         interopContext = 0;
00288 
00289         for (uint32_t i = 0; i < RenderSpriteLayoutElement::NUM_SEMANTICS; i++)
00290         {
00291             semanticOffsets[i] = static_cast<uint32_t>(-1);
00292         }
00293         stride = 0;
00294 
00295         textureCount = 0;
00296     }
00297 
00301     bool isValid(void) const
00302     {
00303         uint32_t numFailed = 0;
00304 
00305         numFailed += (maxSprites == 0);
00306         numFailed += (textureCount == 0) && (stride == 0);
00307         numFailed += (textureCount == 0) && (semanticOffsets[RenderSpriteLayoutElement::POSITION_FLOAT3] == uint32_t(-1));
00308         numFailed += registerInCUDA && (interopContext == 0);
00309 
00310         numFailed += ((stride & 0x03) != 0);
00311         for (uint32_t i = 0; i < RenderSpriteLayoutElement::NUM_SEMANTICS; i++)
00312         {
00313             if (semanticOffsets[i] != static_cast<uint32_t>(-1))
00314             {
00315                 numFailed += (semanticOffsets[i] >= stride);
00316                 numFailed += ((semanticOffsets[i] & 0x03) != 0);
00317             }
00318         }
00319 
00320         return (numFailed == 0);
00321     }
00322 
00326     bool isTheSameAs(const UserRenderSpriteBufferDesc& other) const
00327     {
00328         if (registerInCUDA != other.registerInCUDA) return false;
00329         if (maxSprites != other.maxSprites) return false;
00330         if (hint != other.hint) return false;
00331         if (textureCount != other.textureCount) return false;
00332         if (textureCount == 0)
00333         {
00334             if (stride != other.stride) return false;
00335             for (uint32_t i = 0; i < RenderSpriteLayoutElement::NUM_SEMANTICS; i++)
00336             {
00337                 if (semanticOffsets[i] != other.semanticOffsets[i]) return false;
00338             }
00339         }
00340         else
00341         {
00342             for (uint32_t i = 0; i < textureCount; i++)
00343             {
00344                 if (textureDescs[i].isTheSameAs(other.textureDescs[i]) == false) return false;
00345             }
00346         }
00347         return true;
00348     }
00349 
00350 public:
00351     uint32_t                    maxSprites;     
00352     RenderBufferHint::Enum      hint;           
00353 
00357     uint32_t                    semanticOffsets[RenderSpriteLayoutElement::NUM_SEMANTICS];
00358 
00359     uint32_t                    stride;         
00360 
00361     bool                        registerInCUDA;  
00362 
00367     PxCudaContextManager*       interopContext;
00368 
00369     uint32_t                    textureCount;                       
00370     UserRenderSpriteTextureDesc textureDescs[MAX_SPRITE_TEXTURES];  
00371 };
00372 
00373 #if !PX_PS4
00374     #pragma warning(pop)
00375 #endif  //!PX_PS4
00376 
00377 PX_POP_PACK
00378 
00379 }
00380 } // end namespace nvidia::apex
00381 
00382 #endif // USER_RENDER_SPRITE_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.