HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_PickBuffer.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Render Library (C++)
7  *
8  * COMMENTS:
9  * Holds a frame buffer object that can receive pick information.
10  */
11 
12 #ifndef __RE_PickBuffer_h__
13 #define __RE_PickBuffer_h__
14 
15 #include "RE_API.h"
16 #include "RE_Texture.h"
17 #include "RE_OGLFramebuffer.h"
18 #include <UT/UT_Rect.h>
19 #include <UT/UT_UniquePtr.h>
20 #include <UT/UT_VectorTypes.h>
21 #include <SYS/SYS_Types.h>
22 
23 
24 class RE_Geometry;
25 class RE_Render;
26 class RE_VertexArray;
27 template <typename T> class UT_Array;
28 class UT_TokenString;
29 
30 class re_BoxPickData;
31 
32 
34 {
35 public:
36  RE_PickBuffer();
37  ~RE_PickBuffer();
38 
39  bool resize(RE_Render *r, int w, int h);
40  void invalidate();
41  void startRender(RE_Render *r);
42  void drawToBuffer(RE_Render *r,
44  int colorbufnum = 0);
45  void drawToAllBuffers(RE_Render *r);
46  void endRender(RE_Render *r, UT_TokenString *&new_hash);
47 
48  // The picks returned by this method are sequential in pick_dist in that
49  // if a pick_dist of d returns a sequence of n picks, these will also be
50  // the first n picks in the sequence for a pick_dist of d + 1.
51  //
52  // The sample_counts_by_dist parameter is provided to aid in determining
53  // which of the returned picks would also be picks for distances less
54  // than pick_dist. If a nonzero pointer is supplied, it will be set to
55  // point to an array such that the first (*sample_counts_by_dist)[i] of
56  // the returned picks would also be picks for a pick_dist of i, for i
57  // in [0 .. RE_MAX_PICK_DIST]. This array pointer will only be set if
58  // this method returns a nonzero count, and should *NOT* be deleted.
59  //
60  // The sample_offsets parameter is provided to allow querying the pixel
61  // offset of a given pick index in the picks returned by this method
62  // using the helper getPickSampleOffset() method. This array pointer
63  // will only be set if this method returns a nonzero count, and should
64  // *NOT* be deleted.
65  int getPicks(RE_Render *r,
66  int x, int y, int pick_dist,
67  RE_VertexArray *&high_array,
68  RE_VertexArray *&low_array,
69  RE_VertexArray *&z_array,
70  const UT_IntArray **sample_counts_by_dist
71  = nullptr,
72  const UT_Array<int16> **sample_offsets
73  = nullptr);
74 
75  int getPicks(RE_Render *r,
76  const UT_DimRect &area,
77  uint8 *texture,
78  UT_Vector3iArray &pick_high,
79  UT_Vector3iArray &pick_low);
80  RE_Texture *getZTexture();
81 
82  // Helper method for correctly using the sample_offsets array obtained
83  // from getPicks().
84  UT_Vector2i getPickSampleOffset(
85  const UT_Array<int16> *sample_offsets,
86  exint sample_index) const;
87 
88  bool initialized() const;
89  bool checkHash(const UT_TokenString *hash) const;
90 
91  void saveBuffers(RE_Render *r,
92  const char *path,
93  const char *prefix,
94  bool mid_render) const;
95 
96 private:
97  int normalPickFetch(RE_Render *r,
98  const UT_DimRect &area,
99  uint8 *texture,
100  UT_Vector3iArray &pick_high,
101  UT_Vector3iArray &pick_low);
102  int slowPickFetch(RE_Render *r,
103  const UT_DimRect &area,
104  uint8 *texture,
105  UT_Vector3iArray &pick_high,
106  UT_Vector3iArray &pick_low);
107  RE_FBOStatus create(RE_Render *r, int w, int h);
108  void destroy();
109 
111  UT_UniquePtr<RE_Texture> myHighIdTexture;
112  UT_UniquePtr<RE_Texture> myLowIdTexture;
113  UT_UniquePtr<RE_Texture> myZTexture;
114  UT_UniquePtr<RE_Geometry> mySinglePickGeometry;
115  UT_UniquePtr<re_BoxPickData> myBoxPickData;
116  UT_TokenString *myBufferHash;
117  int myBufferVecSize;
118  mutable int mySaveCount;
119 };
120 
121 #endif
#define RE_API
Definition: RE_API.h:10
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:53
int64 exint
Definition: SYS_Types.h:125
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
GLint GLenum GLint x
Definition: glcorearb.h:408
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
unsigned char uint8
Definition: SYS_Types.h:36
RE_FBOStatus
RE_BufferAttachment
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
ImageBuf OIIO_API resize(const ImageBuf &src, string_view filtername="", float filterwidth=0.0f, ROI roi={}, int nthreads=0)
GLuint texture
Definition: glcorearb.h:414
GLboolean r
Definition: glcorearb.h:1221
GLint y
Definition: glcorearb.h:102
GA_API const UT_StringHolder area