Image RT.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /******************************************************************************/
  2. enum IMAGERT_TYPE : Byte // Image Render Target Type, this describes a group of Image Types
  3. {
  4. IMAGERT_RGBA , // IMAGE_DEFAULT ( 32-bit total with Alpha)
  5. IMAGERT_RGB , // IMAGE_R10G10B10A2, IMAGE_DEFAULT ( 32-bit total no Alpha)
  6. IMAGERT_RGB_P , // IMAGE_R10G10B10A2, IMAGE_F16_3, IMAGE_F16_4, IMAGE_DEFAULT (at least 10-bit per channel no Alpha)
  7. IMAGERT_RGBA_H, // IMAGE_F16_4, IMAGE_DEFAULT (at least 16-bit per channel with Alpha)
  8. IMAGERT_RGB_H , // IMAGE_F16_3, IMAGE_F16_4, IMAGE_R10G10B10A2, IMAGE_DEFAULT (at least 16-bit per channel no Alpha)
  9. IMAGERT_RGBA_F, // IMAGE_F32_4, IMAGE_F16_4, IMAGE_DEFAULT (at least 32-bit per channel with Alpha)
  10. IMAGERT_RGB_F , // IMAGE_F32_3, IMAGE_F32_4, IMAGE_F16_3, IMAGE_F16_4, IMAGE_R10G10B10A2, IMAGE_DEFAULT (at least 32-bit per channel no Alpha)
  11. IMAGERT_RGBA_S, // IMAGE_R8G8B8A8_SIGN, IMAGE_F16_4 (signed 32-bit total with Alpha)
  12. IMAGERT_F32 , // IMAGE_F32, IMAGE_F16
  13. IMAGERT_F16 , // IMAGE_F16, IMAGE_F32
  14. IMAGERT_ONE , // (DX9: IMAGE_A8, IMAGE_L8A8, Rest: IMAGE_R8, IMAGE_R8G8), IMAGE_DEFAULT
  15. IMAGERT_ONE_S , // IMAGE_R8_SIGN, IMAGE_R8G8_SIGN, IMAGE_F16, IMAGE_R8G8B8A8_SIGN, IMAGE_F32
  16. IMAGERT_TWO , // IMAGE_R8G8, IMAGE_DEFAULT
  17. IMAGERT_TWO_S , // IMAGE_R8G8_SIGN, IMAGE_R8G8B8A8_SIGN, IMAGE_F16_2
  18. IMAGERT_DS , // (DX9: IMAGE_INTZ, IMAGE_RAWZ, IMAGE_DF24), IMAGE_D24S8, IMAGE_D24X8, IMAGE_D32, IMAGE_D16
  19. IMAGERT_NUM , // number of Image render targets
  20. IMAGERT_RGBA_P =IMAGERT_RGBA_H, // (at least 10-bit per channel with Alpha)
  21. IMAGERT_RGBA_SP=IMAGERT_RGBA_H, // (at least signed 10-bit per channel with Alpha)
  22. IMAGERT_RGB_S =IMAGERT_RGBA_S, // ( signed 32-bit total no Alpha)
  23. };
  24. /******************************************************************************/
  25. struct ImageRC : Image // Reference Counted Image
  26. {
  27. ImageRC() {_ptr_num=0;}
  28. #if EE_PRIVATE
  29. Bool available()C {return _ptr_num==0;} // if this image is not currently used
  30. #endif
  31. #if !EE_PRIVATE
  32. private:
  33. #endif
  34. UInt _ptr_num;
  35. NO_COPY_CONSTRUCTOR(ImageRC);
  36. };
  37. /******************************************************************************/
  38. #if EE_PRIVATE
  39. struct ImageRTDesc // Render Target Description
  40. {
  41. VecI2 size;
  42. Byte samples;
  43. IMAGERT_TYPE rt_type;
  44. ImageRTDesc() {}
  45. explicit ImageRTDesc(Int w, Int h, IMAGERT_TYPE rt_type, Byte samples=1) {size.set(w, h); T.rt_type=rt_type; T.samples=samples;}
  46. //private:
  47. IMAGE_TYPE _type;
  48. };
  49. #endif
  50. /******************************************************************************/
  51. struct ImageRTPtr // Render Target Pointer
  52. {
  53. #if EE_PRIVATE
  54. Bool find (C ImageRTDesc &desc); // find Render Target, false on fail
  55. ImageRTPtr& get (C ImageRTDesc &desc); // find Render Target, Exit on fail
  56. ImageRTPtr& getDS(Int w, Int h, Byte samples=1, Bool reuse_main=true);
  57. ImageRC * rc ()C {return _data;}
  58. #endif
  59. Bool find(Int w, Int h, IMAGERT_TYPE rt_type, Byte samples=1); // find Render Target, false on fail, 'samples'=number of samples per-pixel (allows multi-sampling)
  60. ImageRTPtr& get(Int w, Int h, IMAGERT_TYPE rt_type, Byte samples=1); // find Render Target, Exit on fail, 'samples'=number of samples per-pixel (allows multi-sampling)
  61. Image* operator () ( )C {return T._data ;} // access the data, you can use the returned reference as long as this 'ImageRTPtr' object exists and not modified
  62. Image* operator -> ( )C {return T._data ;} // access the data, you can use the returned reference as long as this 'ImageRTPtr' object exists and not modified
  63. Image& operator * ( )C {return *T._data ;} // access the data, you can use the returned reference as long as this 'ImageRTPtr' object exists and not modified
  64. Bool operator == ( null_t )C {return T._data==null ;} // if pointers are equal
  65. Bool operator != ( null_t )C {return T._data!=null ;} // if pointers are different
  66. Bool operator == (C Image *p)C {return T._data==p ;} // if pointers are equal
  67. Bool operator != (C Image *p)C {return T._data!=p ;} // if pointers are different
  68. Bool operator == (C ImageRTPtr &p)C {return T._data==p._data;} // if pointers are equal
  69. Bool operator != (C ImageRTPtr &p)C {return T._data!=p._data;} // if pointers are different
  70. operator Bool( )C {return T._data!=null ;} // if pointer is valid
  71. ImageRTPtr& clear ( ); // clear the pointer to null, this automatically decreases the reference count of current data
  72. ImageRTPtr& operator=( null_t ) {return clear();} // clear the pointer to null, this automatically decreases the reference count of current data
  73. ImageRTPtr& operator=(C ImageRTPtr &p); // set pointer to 'p' , this automatically decreases the reference count of current data and increases the reference count of the new data
  74. ImageRTPtr& operator=( ImageRC *p); // set pointer to 'p' , this automatically decreases the reference count of current data and increases the reference count of the new data
  75. ImageRTPtr( null_t=null ) {_data=null; _last_index=-1;}
  76. ImageRTPtr(C ImageRTPtr &p);
  77. ImageRTPtr( ImageRC *p);
  78. #if EE_PRIVATE
  79. explicit ImageRTPtr(C ImageRTDesc &desc) {_data=null; _last_index=-1; get(desc);}
  80. #endif
  81. ~ImageRTPtr( ) {clear();}
  82. #if !EE_PRIVATE
  83. private:
  84. #endif
  85. ImageRC *_data;
  86. Int _last_index;
  87. };
  88. /******************************************************************************/
  89. #if EE_PRIVATE
  90. struct ImageRTPtrRef
  91. {
  92. ImageRTPtr &ref;
  93. ImageRTPtr& get(C ImageRTDesc &desc) {return ref.get(desc);}
  94. Image* operator() ()C {return ref();}
  95. Image* operator-> ()C {return ref();}
  96. Image& operator* ()C {return *ref ;}
  97. operator ImageRTPtr&()C {return ref ;}
  98. void clear() {ref.clear();}
  99. explicit ImageRTPtrRef(ImageRTPtr &image_rt_ptr) : ref(image_rt_ptr) {}
  100. ~ImageRTPtrRef( ) {ref.clear();}
  101. NO_COPY_CONSTRUCTOR(ImageRTPtrRef);
  102. };
  103. IMAGERT_TYPE GetImageRTType( Bool alpha, IMAGE_PRECISION precision);
  104. IMAGERT_TYPE GetImageRTType(IMAGE_TYPE type );
  105. IMAGERT_TYPE GetImageRTType(IMAGE_TYPE type, Bool allow_alpha );
  106. IMAGERT_TYPE GetImageRTType(IMAGE_TYPE type, Bool allow_alpha, IMAGE_PRECISION max_precision);
  107. void ResetImageTypeCreateResult();
  108. #endif
  109. /******************************************************************************/