UserRenderCallback.h
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_CALLBACK_H 00013 #define USER_RENDER_CALLBACK_H 00014 00015 #include "RenderDataFormat.h" 00016 00020 typedef struct CUgraphicsResource_st* CUgraphicsResource; 00021 00022 00023 namespace nvidia 00024 { 00025 namespace apex 00026 { 00027 00028 PX_PUSH_PACK_DEFAULT 00029 00033 struct RenderInteropFlags 00034 { 00038 enum Enum 00039 { 00040 NO_INTEROP = 0, 00041 CUDA_INTEROP, 00042 }; 00043 }; 00044 00048 struct RenderMapType 00049 { 00053 enum Enum 00054 { 00055 MAP_READ = 1, 00056 MAP_WRITE = 2, 00057 MAP_READ_WRITE = 3, 00058 MAP_WRITE_DISCARD = 4, 00059 MAP_WRITE_NO_OVERWRITE = 5 00060 }; 00061 }; 00062 00066 class UserRenderData 00067 { 00068 public: 00069 00073 virtual void addRef() = 0; 00074 00078 virtual void release() = 0; 00079 }; 00080 00084 class UserRenderDataHolder 00085 { 00086 public: 00087 UserRenderDataHolder() 00088 : userData(NULL) 00089 { 00090 } 00091 00092 ~UserRenderDataHolder() 00093 { 00094 if (userData) 00095 { 00096 userData->release(); 00097 } 00098 } 00099 00103 UserRenderDataHolder(const UserRenderDataHolder& other) 00104 : userData(other.userData) 00105 { 00106 if (userData) 00107 { 00108 userData->addRef(); 00109 } 00110 } 00111 00115 UserRenderDataHolder& operator=(const UserRenderDataHolder& other) 00116 { 00117 setUserData(other.userData); 00118 return *this; 00119 } 00120 00125 void setUserData(UserRenderData* newUserData) 00126 { 00127 if (userData != newUserData) 00128 { 00129 if (userData) 00130 { 00131 userData->release(); 00132 } 00133 userData = newUserData; 00134 if (userData) 00135 { 00136 userData->addRef(); 00137 } 00138 } 00139 } 00140 00145 UserRenderData* getUserData() const 00146 { 00147 return userData; 00148 } 00149 00150 private: 00151 00156 UserRenderData* userData; 00157 }; 00158 00162 class UserRenderStorage 00163 { 00164 public: 00165 00169 virtual void release() = 0; 00170 00174 enum Type 00175 { 00176 BUFFER = 0, 00177 SURFACE, 00178 }; 00179 00183 virtual Type getType() const = 0; 00184 }; 00185 00189 struct UserRenderBufferDesc : public UserRenderDataHolder 00190 { 00191 UserRenderBufferDesc(void) 00192 { 00193 setDefaults(); 00194 } 00195 00199 void setDefaults() 00200 { 00201 size = 0; 00202 setUserData(NULL); 00203 userFlags = 0; 00204 interopFlags = RenderInteropFlags::NO_INTEROP; 00205 } 00206 00210 bool isValid(void) const 00211 { 00212 return (size > 0); 00213 } 00214 00218 bool isTheSameAs(const UserRenderBufferDesc& other) const 00219 { 00220 if (size != other.size) return false; 00221 if (userFlags != other.userFlags) return false; 00222 if (getUserData() != other.getUserData()) return false; 00223 if (interopFlags != other.interopFlags) return false; 00224 return true; 00225 } 00226 00227 size_t size; 00228 uint32_t userFlags; 00229 RenderInteropFlags::Enum interopFlags; 00230 }; 00231 00235 class UserRenderBuffer : public UserRenderStorage 00236 { 00237 public: 00238 00242 virtual Type getType() const 00243 { 00244 return BUFFER; 00245 } 00246 00251 virtual void* map(RenderMapType::Enum mapType, size_t offset = 0, size_t size = SIZE_MAX) = 0; 00252 00256 virtual void unmap() = 0; 00257 00262 virtual bool getCUDAgraphicsResource(CUgraphicsResource &ret) = 0; 00263 }; 00264 00268 struct UserRenderSurfaceDesc : public UserRenderDataHolder 00269 { 00270 UserRenderSurfaceDesc(void) 00271 { 00272 setDefaults(); 00273 } 00274 00278 void setDefaults() 00279 { 00280 width = 0; 00281 height = 0; 00282 depth = 0; 00283 format = RenderDataFormat::UNSPECIFIED; 00284 setUserData(NULL); 00285 userFlags = 0; 00286 interopFlags = RenderInteropFlags::NO_INTEROP; 00287 } 00288 00292 bool isValid(void) const 00293 { 00294 uint32_t numFailed = 0; 00295 numFailed += (width == 0); 00296 numFailed += (format == RenderDataFormat::UNSPECIFIED); 00297 return (numFailed == 0); 00298 } 00299 00303 bool isTheSameAs(const UserRenderSurfaceDesc& other) const 00304 { 00305 if (width != other.width) return false; 00306 if (height != other.height) return false; 00307 if (depth != other.depth) return false; 00308 if (format != other.format) return false; 00309 if (userFlags != other.userFlags) return false; 00310 if (getUserData() != other.getUserData()) return false; 00311 if (interopFlags != other.interopFlags) return false; 00312 return true; 00313 } 00314 00315 size_t width; 00316 size_t height; 00317 size_t depth; 00318 RenderDataFormat::Enum format; 00319 uint32_t userFlags; 00320 RenderInteropFlags::Enum interopFlags; 00321 }; 00322 00326 class UserRenderSurface : public UserRenderStorage 00327 { 00328 public: 00329 00333 virtual Type getType() const 00334 { 00335 return SURFACE; 00336 } 00337 00341 struct MappedInfo 00342 { 00343 void* pData; 00344 uint32_t rowPitch; 00345 uint32_t depthPitch; 00346 }; 00347 00352 virtual bool map(RenderMapType::Enum mapType, MappedInfo& info) = 0; 00353 00357 virtual void unmap() = 0; 00358 00363 virtual bool getCUDAgraphicsResource(CUgraphicsResource &ret) = 0; 00364 }; 00365 00369 class UserRenderCallback 00370 { 00371 public: 00372 00376 virtual UserRenderBuffer* createRenderBuffer(const UserRenderBufferDesc& ) 00377 { 00378 return NULL; 00379 } 00383 virtual UserRenderSurface* createRenderSurface(const UserRenderSurfaceDesc& ) 00384 { 00385 return NULL; 00386 } 00387 }; 00388 00389 PX_POP_PACK 00390 00391 } 00392 } // end namespace nvidia::apex 00393 00394 #endif
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.