1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkAbstractContextBufferId.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 // .NAME vtkAbstractContextBufferId - 2D array of ids, used for picking.
17 //
18 // .SECTION Description
19 // An 2D array where each element is the id of an entity drawn at the given
20 // pixel. The access is not specified in this class.
21 // The effective/concrete subclass vtkContextBufferId stores the whole buffer
22 // in RAM. The access to a value is fast and independent of the OpenGL.
23 // However it requires to first fill the whole buffer by transferring the
24 // buffer generated by OpenGL from the VRAM to the RAM. It is inefficient if
25 // the context of the scene changes during interaction.
26 //
27 // The effective/concrete subclass vtkOpenGLContextBufferId keeps the buffer id
28 // on the VRAM in a texture image. The access to a value is slower than a
29 // simple read access to an array but it does not require a large transfer of
30 // data from the VRAM to the RAM.
31 //
32 // .SECTION See Also
33 // vtkContextBufferId, vtkOpenGLContextBufferId
34 
35 #ifndef vtkAbstractContextBufferId_h
36 #define vtkAbstractContextBufferId_h
37 
38 #include "vtkRenderingContext2DModule.h" // For export macro
39 #include "vtkObject.h"
40 
41 class vtkRenderWindow;
42 
43 class VTKRENDERINGCONTEXT2D_EXPORT vtkAbstractContextBufferId : public vtkObject
44 {
45 public:
46   vtkTypeMacro(vtkAbstractContextBufferId, vtkObject);
47   virtual void PrintSelf(ostream &os, vtkIndent indent);
48 
49   static vtkAbstractContextBufferId * New();
50 
51   // Description:
52   // Number of columns. Initial value is 0.
53   vtkGetMacro(Width,int);
54 
55   // Description:
56   // Set the number of columns. Initial value is 0.
57   vtkSetMacro(Width,int);
58 
59   // Description:
60   // Number of rows. Initial value is 0.
61   vtkGetMacro(Height,int);
62 
63   // Description:
64   // Set the number of rows. Initial value is 0.
65   vtkSetMacro(Height,int);
66 
67   // Description:
68   // Set/Get the OpenGL context owning the texture object resource.
69   virtual void SetContext(vtkRenderWindow *context) = 0;
70   virtual vtkRenderWindow *GetContext() = 0;
71 
72   // Description:
73   // Returns if the context supports the required extensions.
74   // \pre context_is_set: this->GetContext()!=0
75   virtual bool IsSupported() = 0;
76 
77   // Description:
78   // Allocate the memory for at least Width*Height elements.
79   // \pre positive_width: GetWidth()>0
80   // \pre positive_height: GetHeight()>0
81   virtual void Allocate()=0;
82 
83   // Description:
84   // Tell if the buffer has been allocated.
85   virtual bool IsAllocated() const=0;
86 
87   // Description:
88   // Copy the contents of the current read buffer to the internal structure
89   // starting at lower left corner of the framebuffer (srcXmin,srcYmin).
90   // \pre is_allocated: this->IsAllocated()
91   virtual void SetValues(int srcXmin,
92                          int srcYmin)=0;
93 
94   // Description:
95   // Return item under abscissa x and ordinate y.
96   // Abscissa go from left to right.
97   // Ordinate go from bottom to top.
98   // The return value is -1 if there is no item.
99   // \pre is_allocated: IsAllocated()
100   // \post valid_result: result>=-1
101   virtual vtkIdType GetPickedItem(int x, int y)=0;
102 
103   // Description:
104   // Release any graphics resources that are being consumed by this object.
105   // Default implementation is empty.
106   virtual void ReleaseGraphicsResources();
107 
108 protected:
109   vtkAbstractContextBufferId();
110   virtual ~vtkAbstractContextBufferId();
111 
112   int Width;
113   int Height;
114 
115 private:
116   vtkAbstractContextBufferId(const vtkAbstractContextBufferId &); // Not implemented.
117   void operator=(const vtkAbstractContextBufferId &);   // Not implemented.
118 };
119 
120 #endif // #ifndef vtkAbstractContextBufferId_h
121