UserRenderCallback.h
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_CALLBACK_H
00031 #define USER_RENDER_CALLBACK_H
00032 
00033 #include "RenderDataFormat.h"
00034 
00038 typedef struct CUgraphicsResource_st* CUgraphicsResource;
00039 
00040 
00041 namespace nvidia
00042 {
00043 namespace apex
00044 {
00045 
00046 PX_PUSH_PACK_DEFAULT
00047 
00051 struct RenderInteropFlags
00052 {
00056     enum Enum
00057     {
00058         NO_INTEROP = 0,
00059         CUDA_INTEROP,
00060     };
00061 };
00062 
00066 struct RenderMapType
00067 {
00071     enum Enum
00072     {
00073         MAP_READ                 = 1,
00074         MAP_WRITE                = 2,
00075         MAP_READ_WRITE           = 3,
00076         MAP_WRITE_DISCARD        = 4,
00077         MAP_WRITE_NO_OVERWRITE   = 5 
00078     };
00079 };
00080 
00084 class UserRenderData
00085 {
00086 public:
00087     
00091     virtual void addRef() = 0;
00092     
00096     virtual void release() = 0;
00097 };
00098 
00102 class UserRenderDataHolder
00103 {
00104 public:
00105     UserRenderDataHolder()
00106         : userData(NULL)
00107     {
00108     }
00109     
00110     ~UserRenderDataHolder()
00111     {
00112         if (userData)
00113         {
00114             userData->release();
00115         }
00116     }
00117     
00121     UserRenderDataHolder(const UserRenderDataHolder& other)
00122         : userData(other.userData)
00123     {
00124         if (userData)
00125         {
00126             userData->addRef();
00127         }
00128     }
00129     
00133     UserRenderDataHolder& operator=(const UserRenderDataHolder& other)
00134     {
00135         setUserData(other.userData);
00136         return *this;
00137     }
00138 
00143     void setUserData(UserRenderData* newUserData)
00144     {
00145         if (userData != newUserData)
00146         {
00147             if (userData)
00148             {
00149                 userData->release();
00150             }
00151             userData = newUserData;
00152             if (userData)
00153             {
00154                 userData->addRef();
00155             }
00156         }
00157     }
00158     
00163     UserRenderData* getUserData() const
00164     {
00165         return userData;
00166     }
00167 
00168 private:
00169 
00174     UserRenderData* userData;
00175 };
00176 
00180 class UserRenderStorage
00181 {
00182 public:
00183 
00187     virtual void release() = 0;
00188 
00192     enum Type
00193     {
00194         BUFFER = 0,
00195         SURFACE,
00196     };
00197     
00201     virtual Type getType() const = 0;
00202 };
00203 
00207 struct UserRenderBufferDesc : public UserRenderDataHolder
00208 {
00209     UserRenderBufferDesc(void)
00210     {
00211         setDefaults();
00212     }
00213 
00217     void setDefaults()
00218     {
00219         size = 0;
00220         setUserData(NULL);
00221         userFlags = 0;
00222         interopFlags = RenderInteropFlags::NO_INTEROP;
00223     }
00224 
00228     bool isValid(void) const
00229     {
00230         return (size > 0);
00231     }
00232 
00236     bool isTheSameAs(const UserRenderBufferDesc& other) const
00237     {
00238         if (size != other.size) return false;
00239         if (userFlags != other.userFlags) return false;
00240         if (getUserData() != other.getUserData()) return false;
00241         if (interopFlags != other.interopFlags) return false;
00242         return true;
00243     }
00244 
00245     size_t                      size;           
00246     uint32_t                    userFlags;      
00247     RenderInteropFlags::Enum    interopFlags;   
00248 };
00249 
00253 class UserRenderBuffer : public UserRenderStorage
00254 {
00255 public:
00256 
00260     virtual Type getType() const
00261     {
00262         return BUFFER;
00263     }
00264 
00269     virtual void* map(RenderMapType::Enum mapType, size_t offset = 0, size_t size = SIZE_MAX) = 0;
00270     
00274     virtual void unmap() = 0;
00275 
00280     virtual bool getCUDAgraphicsResource(CUgraphicsResource &ret) = 0;
00281 };
00282 
00286 struct UserRenderSurfaceDesc : public UserRenderDataHolder
00287 {
00288     UserRenderSurfaceDesc(void)
00289     {
00290         setDefaults();
00291     }
00292 
00296     void setDefaults()
00297     {
00298         width = 0;
00299         height = 0;
00300         depth = 0;
00301         format = RenderDataFormat::UNSPECIFIED;
00302         setUserData(NULL);
00303         userFlags = 0;
00304         interopFlags = RenderInteropFlags::NO_INTEROP;
00305     }
00306 
00310     bool isValid(void) const
00311     {
00312         uint32_t numFailed = 0;
00313         numFailed += (width == 0);
00314         numFailed += (format == RenderDataFormat::UNSPECIFIED);
00315         return (numFailed == 0);
00316     }
00317 
00321     bool isTheSameAs(const UserRenderSurfaceDesc& other) const
00322     {
00323         if (width != other.width) return false;
00324         if (height != other.height) return false;
00325         if (depth != other.depth) return false;
00326         if (format != other.format) return false;
00327         if (userFlags != other.userFlags) return false;
00328         if (getUserData() != other.getUserData()) return false;
00329         if (interopFlags != other.interopFlags) return false;
00330         return true;
00331     }
00332 
00333     size_t                      width;          
00334     size_t                      height;         
00335     size_t                      depth;          
00336     RenderDataFormat::Enum      format;         
00337     uint32_t                    userFlags;      
00338     RenderInteropFlags::Enum    interopFlags;   
00339 };
00340 
00344 class UserRenderSurface : public UserRenderStorage
00345 {
00346 public:
00347 
00351     virtual Type getType() const
00352     {
00353         return SURFACE;
00354     }
00355 
00359     struct MappedInfo
00360     {
00361         void*       pData;      
00362         uint32_t    rowPitch;   
00363         uint32_t    depthPitch; 
00364     };
00365 
00370     virtual bool map(RenderMapType::Enum mapType, MappedInfo& info) = 0;
00371     
00375     virtual void unmap() = 0;
00376 
00381     virtual bool getCUDAgraphicsResource(CUgraphicsResource &ret) = 0;
00382 };
00383 
00387 class UserRenderCallback
00388 {
00389 public:
00390     
00394     virtual UserRenderBuffer* createRenderBuffer(const UserRenderBufferDesc& )
00395     {
00396         return NULL;
00397     }
00401     virtual UserRenderSurface* createRenderSurface(const UserRenderSurfaceDesc& )
00402     {
00403         return NULL;
00404     }
00405 };
00406 
00407 PX_POP_PACK
00408 
00409 }
00410 } // end namespace nvidia::apex
00411 
00412 #endif

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.