1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkPainterDeviceAdapter.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 * Copyright 2004 Sandia Corporation.
17 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
18 * license for use of this work by or on behalf of the
19 * U.S. Government. Redistribution and use in source and binary forms, with
20 * or without modification, are permitted provided that this Notice and any
21 * statement of authorship are reproduced on all copies.
22 */
23
24 // .NAME vtkPainterDeviceAdapter - An adapter between a vtkPainter and a rendering device.
25 //
26 // .SECTION Description
27 //
28 // This class is an adapter between a vtkPainter and a rendering device (such
29 // as an OpenGL machine). Having an abstract adapter allows vtkPainters
30 // to be re-used for any rendering system.
31 //
32 // Although VTK really only uses OpenGL right now, there are reasons to
33 // swap out the rendering functions. Sometimes MESA with mangled names
34 // is used. Also, different shader extensions use different functions.
35 // Furthermore, Cg also has its own interface.
36 //
37 // The interface for this class should be familier to anyone experienced
38 // with OpenGL.
39 //
40 // .SECTION See Also
41 // vtkPainter
42 //
43
44 #ifndef vtkPainterDeviceAdapter_h
45 #define vtkPainterDeviceAdapter_h
46
47 #include "vtkRenderingCoreModule.h" // For export macro
48 #include "vtkObject.h"
49 #include "vtkDataArray.h" // needed for inline functions.
50 class vtkRenderer;
51
52 class VTKRENDERINGCORE_EXPORT vtkPainterDeviceAdapter : public vtkObject
53 {
54 public:
55 static vtkPainterDeviceAdapter* New();
56 vtkTypeMacro(vtkPainterDeviceAdapter, vtkObject);
57 virtual void PrintSelf(ostream &os, vtkIndent indent);
58
59 // Description:
60 // Signals the start of sending a primitive to the graphics card. The
61 // mode is one of VTK_VERTEX, VTK_POLY_VERTEX, VTK_LINE, VTK_POLY_LINE,
62 // VTK_TRIANGLE, VTK_TRIANGLE_STRIP, VTK_POLYGON, or VTK_QUAD. The
63 // primitive is defined by the attributes sent between the calls to
64 // BeginPrimitive and EndPrimitive. You do not need to call
65 // EndPrimitive/BeginPrimitive between primitives that have a constant
66 // number of points (i.e. VTK_VERTEX, VTK_LINE, VTK_TRIANGLE, and
67 // VTK_QUAD).
68 virtual void BeginPrimitive(int mode) = 0;
69
70 // Description:
71 // Signals the end of sending a primitive to the graphics card.
72 virtual void EndPrimitive() = 0;
73
74 // Description:
75 // Returns if the given attribute type is supported by the device.
76 // Returns 1 is supported, 0 otherwise.
77 virtual int IsAttributesSupported(int attribute)=0;
78
79 // Description:
80 // Calls glMultiTex
81 virtual void SendMultiTextureCoords(int numcomp, int type, const void *attribute,
82 int idx, vtkIdType offset) = 0;
83
84 // Description:
85 // Sends a single attribute to the graphics card. The index parameter
86 // identifies the attribute. Some indices have special meaning (see
87 // vtkPainter for details). The components parameter gives the number of
88 // components in the attribute. In general, components must be between
89 // 1-4, but a rendering system may impose even more constraints. The
90 // type parameter is a VTK type enumeration (VTK_FLOAT, VTK_INT, etc.).
91 // Again, a rendering system may not support all types for all
92 // attributes. The attribute parameter is the actual data for the
93 // attribute.
94 // If offset is specified, it is added to attribute pointer after
95 // it has been casted to the proper type.
96 virtual void SendAttribute(int index, int components, int type,
97 const void *attribute, vtkIdType offset=0) = 0;
98
99 // Description:
100 // Sets an array of attributes. This allows you to send all the data for
101 // a particular attribute with one call, thus greatly reducing function
102 // call overhead. Once set, the array is enabled with
103 // EnableAttributeArray, and the data is sent with a call to DrawArrays
104 // DrawElements.
105 void SetAttributePointer(int index, vtkDataArray *attributeArray);
106
107 // Description:
108 // Sets an array of attributes. This allows you to send all the data for
109 // a particular attribute with one call, thus greatly reducing function
110 // call overhead. Once set, the array is enabled with
111 // EnableAttributeArray, and the data is sent with a call to DrawArrays
112 // DrawElements.
113 //
114 // \arg \c index the index of the attribute.
115 // \arg \c numcomponents the number of components in each attribute entry.
116 // \arg \c type the data type (VTK_FLOAT, VTK_UNSIGNED_CHAR, etc.).
117 // \arg \c stride the byte offset between entries in the array (0 for
118 // tightly packed).
119 // \arg \c pointer the array holding the data.
120 virtual void SetAttributePointer(int index, int numcomponents, int type,
121 int stride, const void *pointer) = 0;
122
123 // Description:
124 // Enable/disable the attribute array set with SetAttributePointer.
125 virtual void EnableAttributeArray(int index) = 0;
126 virtual void DisableAttributeArray(int index) = 0;
127
128 // Description:
129 // Send a section of the enabled attribute pointers to the graphics card
130 // to define a primitive. The mode is one of VTK_VERTEX,
131 // VTK_POLY_VERTEX, VTK_LINE, VTK_POLY_LINE, VTK_TRIANGLE,
132 // VTK_TRIANGLE_STRIP, VTK_POLYGON, or VTK_QUAD. It identifies which
133 // type of primitive the attribute data is defining. The parameters
134 // first and count identify what part of the attribute arrays define the
135 // given primitive. If mode is a primitive that has a constant number of
136 // points (i.e. VTK_VERTEX, VTK_LINE, VTK_TRIANGLE, and VTK_QUAD), you
137 // may draw multiple primitives with one call to DrawArrays.
138 virtual void DrawArrays(int mode, vtkIdType first, vtkIdType count) = 0;
139
140 // Description:
141 // Send items in the attribute pointers to the graphics card to define a
142 // primitive. The mode is one of VTK_VERTEX, VTK_POLY_VERTEX, VTK_LINE,
143 // VTK_POLY_LINE, VTK_TRIANGLE, VTK_TRIANGLE_STRIP, VTK_POLYGON, or
144 // VTK_QUAD. It identifies which type of primitive the attribute data is
145 // defining. The indices array holds the list of attribute elements that
146 // define the primitive. The count and type parameters give the number
147 // and data type of the indices array. The type parameter is a VTK type
148 // enumeration (VTK_UNSIGNED_INT, ...). The type should be an integer
149 // type (for obvious reasons). If mode is a primitive that has a
150 // constant number of points (i.e. VTK_VERTEX, VTK_LINE, VTK_TRIANGLE,
151 // and VTK_QUAD), you may draw multiple primitives with one call to
152 // DrawArrays.
153 virtual void DrawElements(int mode, vtkIdType count, int type,
154 void *indices) = 0;
155
156 // Description:
157 // Returns true if this device adapter is compatible with the given
158 // vtkRenderer.
159 virtual int Compatible(vtkRenderer *renderer) = 0;
160
161 #ifndef VTK_LEGACY_REMOVE
162 // Description:
163 // @deprecated code that needs access directly to OpenGL state should
164 // manage it locally.
165 // Turns lighting on and off.
166 virtual void MakeLighting(int mode) = 0;
167
168 // Description:
169 // @deprecated code that needs access directly to OpenGL state should
170 // manage it locally.
171 // Returns current lighting setting.
172 virtual int QueryLighting() = 0;
173
174 // Description:
175 // @deprecated code that needs access directly to OpenGL state should
176 // manage it locally.
177 // Turns antialiasing on and off.
178 virtual void MakeMultisampling(int mode) = 0;
179
180 // Description:
181 // @deprecated code that needs access directly to OpenGL state should
182 // manage it locally.
183 // Returns current antialiasing setting.
184 virtual int QueryMultisampling() = 0;
185
186 // Description:
187 // @deprecated code that needs access directly to OpenGL state should
188 // manage it locally.
189 // Turns blending on and off.
190 virtual void MakeBlending(int mode) = 0;
191
192 // Description:
193 // @deprecated code that needs access directly to OpenGL state should
194 // manage it locally.
195 // Returns current blending setting.
196 virtual int QueryBlending() = 0;
197 #endif
198
199 // Description:
200 // Turns emphasis of vertices on or off for vertex selection.
201 virtual void MakeVertexEmphasis(bool mode) = 0;
202
203 // Description:
204 // Control use of the stencil buffer (for vertex selection).
205 virtual void Stencil(int on) = 0;
206 virtual void WriteStencil(vtkIdType value) = 0;
207 virtual void TestStencil(vtkIdType value) = 0;
208
209 protected:
210 vtkPainterDeviceAdapter();
211 ~vtkPainterDeviceAdapter();
212
213 private:
214 vtkPainterDeviceAdapter(const vtkPainterDeviceAdapter &); // Not implemented.
215 void operator=(const vtkPainterDeviceAdapter &); // Not implemented.
216 };
217
SetAttributePointer(int index,vtkDataArray * attributeArray)218 inline void vtkPainterDeviceAdapter::SetAttributePointer(int index,
219 vtkDataArray *attributeArray)
220 {
221 this->SetAttributePointer(index, attributeArray->GetNumberOfComponents(),
222 attributeArray->GetDataType(), 0,
223 attributeArray->GetVoidPointer(0));
224 }
225
226 #endif //_vtkPainterDeviceAdapter_h
227