| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osg/ArrayDispatchers> |
|---|
| 14 | #include <osg/State> |
|---|
| 15 | #include <osg/Drawable> |
|---|
| 16 | |
|---|
| 17 | #include <osg/Notify> |
|---|
| 18 | #include <osg/io_utils> |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | namespace osg |
|---|
| 22 | { |
|---|
| 23 | |
|---|
| 24 | #if defined(OSG_GLES1_AVAILABLE) |
|---|
| 25 | inline void APIENTRY glColor4ubv(const GLubyte* c) { glColor4ub(c[0], c[1], c[2], c[3]); } |
|---|
| 26 | inline void APIENTRY glColor3fv(const GLfloat* c) { glColor4f(c[0], c[1], c[2], 1.0f); } |
|---|
| 27 | inline void APIENTRY glColor4fv(const GLfloat* c) { glColor4f(c[0], c[1], c[2], c[3]); } |
|---|
| 28 | inline void APIENTRY glColor3dv(const GLdouble* c) { glColor4f(c[0], c[1], c[2], 1.0f); } |
|---|
| 29 | inline void APIENTRY glColor4dv(const GLdouble* c) { glColor4f(c[0], c[1], c[2], c[3]); } |
|---|
| 30 | |
|---|
| 31 | inline void APIENTRY glNormal3bv(const GLbyte* n) { const float div = 1.0f/128.0f; glNormal3f(float(n[0])*div, float(n[1])*div, float(n[3])*div); } |
|---|
| 32 | inline void APIENTRY glNormal3sv(const GLshort* n) { const float div = 1.0f/32768.0f; glNormal3f(float(n[0])*div, float(n[1])*div, float(n[3])*div); } |
|---|
| 33 | inline void APIENTRY glNormal3fv(const GLfloat* n) { glNormal3f(n[0], n[1], n[3]); } |
|---|
| 34 | inline void APIENTRY glNormal3dv(const GLdouble* n) { glNormal3f(n[0], n[1], n[3]); } |
|---|
| 35 | #endif |
|---|
| 36 | |
|---|
| 37 | template<typename T> |
|---|
| 38 | class TemplateAttributeDispatch : public AttributeDispatch |
|---|
| 39 | { |
|---|
| 40 | public: |
|---|
| 41 | |
|---|
| 42 | typedef void (APIENTRY * F) (const T*); |
|---|
| 43 | |
|---|
| 44 | TemplateAttributeDispatch(F functionPtr, unsigned int stride): |
|---|
| 45 | _functionPtr(functionPtr), _stride(stride), _array(0) {} |
|---|
| 46 | |
|---|
| 47 | virtual void assign(const GLvoid* array, const IndexArray*) |
|---|
| 48 | { |
|---|
| 49 | _array = reinterpret_cast<const T*>(array); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | virtual void operator () (unsigned int pos) |
|---|
| 53 | { |
|---|
| 54 | _functionPtr(&(_array[pos*_stride])); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | F _functionPtr; |
|---|
| 58 | unsigned int _stride; |
|---|
| 59 | const T* _array; |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | template<typename T> |
|---|
| 63 | class TemplateAttributeWithIndicesDispatch : public AttributeDispatch |
|---|
| 64 | { |
|---|
| 65 | public: |
|---|
| 66 | |
|---|
| 67 | typedef void (APIENTRY * F) (const T*); |
|---|
| 68 | |
|---|
| 69 | TemplateAttributeWithIndicesDispatch(F functionPtr, unsigned int stride): |
|---|
| 70 | _functionPtr(functionPtr), _stride(stride), _array(0), _indices(0) {} |
|---|
| 71 | |
|---|
| 72 | virtual void assign(const GLvoid* array, const IndexArray* indices) |
|---|
| 73 | { |
|---|
| 74 | _array = reinterpret_cast<const T*>(array); |
|---|
| 75 | _indices = indices; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | virtual void operator () (unsigned int pos) |
|---|
| 79 | { |
|---|
| 80 | _functionPtr(&(_array[_indices->index(pos) * _stride])); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | F _functionPtr; |
|---|
| 84 | unsigned int _stride; |
|---|
| 85 | const T* _array; |
|---|
| 86 | const IndexArray* _indices; |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | template<typename T> |
|---|
| 90 | class TemplateBeginEndAttributeDispatch : public AttributeDispatch |
|---|
| 91 | { |
|---|
| 92 | public: |
|---|
| 93 | |
|---|
| 94 | typedef void (GLBeginEndAdapter::*F) (const T*); |
|---|
| 95 | |
|---|
| 96 | TemplateBeginEndAttributeDispatch(GLBeginEndAdapter* glBeginEndAdapter, F functionPtr, unsigned int stride): |
|---|
| 97 | _glBeginEndAdapter(glBeginEndAdapter), |
|---|
| 98 | _functionPtr(functionPtr), _stride(stride), _array(0) {} |
|---|
| 99 | |
|---|
| 100 | virtual void assign(const GLvoid* array, const IndexArray*) |
|---|
| 101 | { |
|---|
| 102 | _array = reinterpret_cast<const T*>(array); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | virtual void operator () (unsigned int pos) |
|---|
| 106 | { |
|---|
| 107 | (_glBeginEndAdapter->*_functionPtr)(&(_array[pos*_stride])); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | GLBeginEndAdapter* _glBeginEndAdapter; |
|---|
| 111 | F _functionPtr; |
|---|
| 112 | unsigned int _stride; |
|---|
| 113 | const T* _array; |
|---|
| 114 | }; |
|---|
| 115 | |
|---|
| 116 | template<typename T> |
|---|
| 117 | class TemplateBeginEndAttributeWithIndicesDispatch : public AttributeDispatch |
|---|
| 118 | { |
|---|
| 119 | public: |
|---|
| 120 | |
|---|
| 121 | typedef void (GLBeginEndAdapter::*F) (const T*); |
|---|
| 122 | |
|---|
| 123 | TemplateBeginEndAttributeWithIndicesDispatch(GLBeginEndAdapter* glBeginEndAdapter, F functionPtr, unsigned int stride): |
|---|
| 124 | _glBeginEndAdapter(glBeginEndAdapter), |
|---|
| 125 | _functionPtr(functionPtr), _stride(stride), _array(0), _indices(0) {} |
|---|
| 126 | |
|---|
| 127 | virtual void assign(const GLvoid* array, const IndexArray* indices) |
|---|
| 128 | { |
|---|
| 129 | _array = reinterpret_cast<const T*>(array); |
|---|
| 130 | _indices = indices; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | virtual void operator () (unsigned int pos) |
|---|
| 134 | { |
|---|
| 135 | (_glBeginEndAdapter->*_functionPtr)(&(_array[_indices->index(pos) * _stride])); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | GLBeginEndAdapter* _glBeginEndAdapter; |
|---|
| 139 | F _functionPtr; |
|---|
| 140 | unsigned int _stride; |
|---|
| 141 | const T* _array; |
|---|
| 142 | const IndexArray* _indices; |
|---|
| 143 | }; |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | template<typename I, typename T> |
|---|
| 147 | class TemplateTargetAttributeDispatch : public AttributeDispatch |
|---|
| 148 | { |
|---|
| 149 | public: |
|---|
| 150 | |
|---|
| 151 | typedef void (APIENTRY * F) (I, const T*); |
|---|
| 152 | |
|---|
| 153 | TemplateTargetAttributeDispatch(I target, F functionPtr, unsigned int stride): |
|---|
| 154 | _functionPtr(functionPtr), _target(target), _stride(stride), _array(0) {} |
|---|
| 155 | |
|---|
| 156 | virtual void assign(const GLvoid* array, const IndexArray*) |
|---|
| 157 | { |
|---|
| 158 | _array = reinterpret_cast<const T*>(array); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | virtual void operator () (unsigned int pos) |
|---|
| 162 | { |
|---|
| 163 | _functionPtr(_target, &(_array[pos * _stride])); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | GLBeginEndAdapter* _glBeginEndAdapter; |
|---|
| 167 | F _functionPtr; |
|---|
| 168 | I _target; |
|---|
| 169 | unsigned int _stride; |
|---|
| 170 | const T* _array; |
|---|
| 171 | }; |
|---|
| 172 | |
|---|
| 173 | template<typename I, typename T> |
|---|
| 174 | class TemplateTargetAttributeWithIndicesDispatch : public AttributeDispatch |
|---|
| 175 | { |
|---|
| 176 | public: |
|---|
| 177 | |
|---|
| 178 | typedef void (APIENTRY * F) (I, const T*); |
|---|
| 179 | |
|---|
| 180 | TemplateTargetAttributeWithIndicesDispatch(I target, F functionPtr, unsigned int stride): |
|---|
| 181 | _functionPtr(functionPtr), _target(target), _stride(stride), _array(0), _indices(0) {} |
|---|
| 182 | |
|---|
| 183 | virtual void assign(const GLvoid* array, const IndexArray* indices) |
|---|
| 184 | { |
|---|
| 185 | _array = reinterpret_cast<const T*>(array); |
|---|
| 186 | _indices = indices; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | virtual void operator () (unsigned int pos) |
|---|
| 190 | { |
|---|
| 191 | _functionPtr(_target, &(_array[_indices->index(pos) * _stride])); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | F _functionPtr; |
|---|
| 195 | I _target; |
|---|
| 196 | unsigned int _stride; |
|---|
| 197 | const T* _array; |
|---|
| 198 | const IndexArray* _indices; |
|---|
| 199 | }; |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | template<typename I, typename T> |
|---|
| 203 | class TemplateBeginEndTargetAttributeDispatch : public AttributeDispatch |
|---|
| 204 | { |
|---|
| 205 | public: |
|---|
| 206 | |
|---|
| 207 | typedef void (GLBeginEndAdapter::*F) (I, const T*); |
|---|
| 208 | |
|---|
| 209 | TemplateBeginEndTargetAttributeDispatch(GLBeginEndAdapter* glBeginEndAdapter, I target, F functionPtr, unsigned int stride): |
|---|
| 210 | _glBeginEndAdapter(glBeginEndAdapter), |
|---|
| 211 | _functionPtr(functionPtr), _target(target), _stride(stride), _array(0) {} |
|---|
| 212 | |
|---|
| 213 | virtual void assign(const GLvoid* array, const IndexArray*) |
|---|
| 214 | { |
|---|
| 215 | _array = reinterpret_cast<const T*>(array); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | virtual void operator () (unsigned int pos) |
|---|
| 219 | { |
|---|
| 220 | (_glBeginEndAdapter->*_functionPtr)(_target, &(_array[pos * _stride])); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | GLBeginEndAdapter* _glBeginEndAdapter; |
|---|
| 224 | F _functionPtr; |
|---|
| 225 | I _target; |
|---|
| 226 | unsigned int _stride; |
|---|
| 227 | const T* _array; |
|---|
| 228 | }; |
|---|
| 229 | |
|---|
| 230 | template<typename I, typename T> |
|---|
| 231 | class TemplateBeginEndTargetAttributeWithIndicesDispatch : public AttributeDispatch |
|---|
| 232 | { |
|---|
| 233 | public: |
|---|
| 234 | |
|---|
| 235 | typedef void (GLBeginEndAdapter::*F) (I, const T*); |
|---|
| 236 | |
|---|
| 237 | TemplateBeginEndTargetAttributeWithIndicesDispatch(GLBeginEndAdapter* glBeginEndAdapter, I target, F functionPtr, unsigned int stride): |
|---|
| 238 | _glBeginEndAdapter(glBeginEndAdapter), |
|---|
| 239 | _functionPtr(functionPtr), _target(target), _stride(stride), _array(0), _indices(0) {} |
|---|
| 240 | |
|---|
| 241 | virtual void assign(const GLvoid* array, const IndexArray* indices) |
|---|
| 242 | { |
|---|
| 243 | _array = reinterpret_cast<const T*>(array); |
|---|
| 244 | _indices = indices; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | virtual void operator () (unsigned int pos) |
|---|
| 248 | { |
|---|
| 249 | (_glBeginEndAdapter->*_functionPtr)(_target, &(_array[_indices->index(pos) * _stride])); |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | GLBeginEndAdapter* _glBeginEndAdapter; |
|---|
| 253 | F _functionPtr; |
|---|
| 254 | I _target; |
|---|
| 255 | unsigned int _stride; |
|---|
| 256 | const T* _array; |
|---|
| 257 | const IndexArray* _indices; |
|---|
| 258 | }; |
|---|
| 259 | |
|---|
| 260 | class AttributeDispatchMap |
|---|
| 261 | { |
|---|
| 262 | public: |
|---|
| 263 | |
|---|
| 264 | AttributeDispatchMap(GLBeginEndAdapter* glBeginEndAdapter): |
|---|
| 265 | _glBeginEndAdapter(glBeginEndAdapter) {} |
|---|
| 266 | |
|---|
| 267 | template<typename T> |
|---|
| 268 | void assign(Array::Type type, void (APIENTRY *functionPtr) (const T*), unsigned int stride) |
|---|
| 269 | { |
|---|
| 270 | if ((unsigned int)type >= _attributeDispatchList.size()) _attributeDispatchList.resize(type+1); |
|---|
| 271 | _attributeDispatchList[type] = functionPtr ? new TemplateAttributeDispatch<T>(functionPtr, stride) : 0; |
|---|
| 272 | |
|---|
| 273 | if ((unsigned int)type >= _attributeDispatchWithIndicesList.size()) _attributeDispatchWithIndicesList.resize(type+1); |
|---|
| 274 | _attributeDispatchWithIndicesList[type] = functionPtr ? new TemplateAttributeWithIndicesDispatch<T>(functionPtr, stride) : 0; |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | template<typename I, typename T> |
|---|
| 278 | void targetAssign(I target, Array::Type type, void (APIENTRY *functionPtr) (I, const T*), unsigned int stride) |
|---|
| 279 | { |
|---|
| 280 | if ((unsigned int)type >= _attributeDispatchList.size()) _attributeDispatchList.resize(type+1); |
|---|
| 281 | _attributeDispatchList[type] = functionPtr ? new TemplateTargetAttributeDispatch<I,T>(target, functionPtr, stride) : 0; |
|---|
| 282 | |
|---|
| 283 | if ((unsigned int)type >= _attributeDispatchWithIndicesList.size()) _attributeDispatchWithIndicesList.resize(type+1); |
|---|
| 284 | _attributeDispatchWithIndicesList[type] = functionPtr ? new TemplateTargetAttributeWithIndicesDispatch<I,T>(target, functionPtr, stride) : 0; |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | template<typename T> |
|---|
| 288 | void assignGLBeginEnd(Array::Type type, void (GLBeginEndAdapter::*functionPtr) (const T*), unsigned int stride) |
|---|
| 289 | { |
|---|
| 290 | if ((unsigned int)type >= _glBeginEndAttributeDispatchList.size()) _glBeginEndAttributeDispatchList.resize(type+1); |
|---|
| 291 | _glBeginEndAttributeDispatchList[type] = functionPtr ? new TemplateBeginEndAttributeDispatch<T>(_glBeginEndAdapter, functionPtr, stride) : 0; |
|---|
| 292 | |
|---|
| 293 | if ((unsigned int)type >= _glBeginEndAttributeDispatchWithIndicesList.size()) _glBeginEndAttributeDispatchWithIndicesList.resize(type+1); |
|---|
| 294 | _glBeginEndAttributeDispatchWithIndicesList[type] = functionPtr ? new TemplateBeginEndAttributeWithIndicesDispatch<T>(_glBeginEndAdapter, functionPtr, stride) : 0; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | template<typename I, typename T> |
|---|
| 298 | void targetGLBeginEndAssign(I target, Array::Type type, void (GLBeginEndAdapter::*functionPtr) (I, const T*), unsigned int stride) |
|---|
| 299 | { |
|---|
| 300 | if ((unsigned int)type >= _glBeginEndAttributeDispatchList.size()) _glBeginEndAttributeDispatchList.resize(type+1); |
|---|
| 301 | _glBeginEndAttributeDispatchList[type] = functionPtr ? new TemplateBeginEndTargetAttributeDispatch<I,T>(_glBeginEndAdapter, target, functionPtr, stride) : 0; |
|---|
| 302 | |
|---|
| 303 | if ((unsigned int)type >= _glBeginEndAttributeDispatchWithIndicesList.size()) _glBeginEndAttributeDispatchWithIndicesList.resize(type+1); |
|---|
| 304 | _glBeginEndAttributeDispatchWithIndicesList[type] = functionPtr ? new TemplateBeginEndTargetAttributeWithIndicesDispatch<I,T>(_glBeginEndAdapter, target, functionPtr, stride) : 0; |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | AttributeDispatch* dispatcher(bool useGLBeginEndAdapter, const Array* array, const IndexArray* indices) |
|---|
| 309 | { |
|---|
| 310 | if (!array) return 0; |
|---|
| 311 | |
|---|
| 312 | Array::Type type = array->getType(); |
|---|
| 313 | AttributeDispatch* dispatcher = 0; |
|---|
| 314 | if (useGLBeginEndAdapter) |
|---|
| 315 | { |
|---|
| 316 | if (indices) |
|---|
| 317 | { |
|---|
| 318 | if ((unsigned int)type<_glBeginEndAttributeDispatchWithIndicesList.size()) |
|---|
| 319 | { |
|---|
| 320 | dispatcher = _glBeginEndAttributeDispatchWithIndicesList[array->getType()].get(); |
|---|
| 321 | } |
|---|
| 322 | } |
|---|
| 323 | else if ((unsigned int)type<_glBeginEndAttributeDispatchList.size()) |
|---|
| 324 | { |
|---|
| 325 | dispatcher = _glBeginEndAttributeDispatchList[array->getType()].get(); |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | else |
|---|
| 329 | { |
|---|
| 330 | if (indices) |
|---|
| 331 | { |
|---|
| 332 | if ((unsigned int)type<_attributeDispatchWithIndicesList.size()) |
|---|
| 333 | { |
|---|
| 334 | dispatcher = _attributeDispatchWithIndicesList[array->getType()].get(); |
|---|
| 335 | } |
|---|
| 336 | } |
|---|
| 337 | else if ((unsigned int)type<_attributeDispatchList.size()) |
|---|
| 338 | { |
|---|
| 339 | dispatcher = _attributeDispatchList[array->getType()].get(); |
|---|
| 340 | } |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | if (dispatcher) |
|---|
| 344 | { |
|---|
| 345 | dispatcher->assign(array->getDataPointer(), indices); |
|---|
| 346 | return dispatcher; |
|---|
| 347 | } |
|---|
| 348 | else |
|---|
| 349 | { |
|---|
| 350 | return 0; |
|---|
| 351 | } |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | typedef std::vector< ref_ptr<AttributeDispatch> > AttributeDispatchList; |
|---|
| 355 | GLBeginEndAdapter* _glBeginEndAdapter; |
|---|
| 356 | AttributeDispatchList _attributeDispatchList; |
|---|
| 357 | AttributeDispatchList _attributeDispatchWithIndicesList; |
|---|
| 358 | AttributeDispatchList _glBeginEndAttributeDispatchList; |
|---|
| 359 | AttributeDispatchList _glBeginEndAttributeDispatchWithIndicesList; |
|---|
| 360 | }; |
|---|
| 361 | |
|---|
| 362 | ArrayDispatchers::ArrayDispatchers(): |
|---|
| 363 | _initialized(false), |
|---|
| 364 | _state(0), |
|---|
| 365 | _glBeginEndAdapter(0), |
|---|
| 366 | _vertexDispatchers(0), |
|---|
| 367 | _normalDispatchers(0), |
|---|
| 368 | _colorDispatchers(0), |
|---|
| 369 | _secondaryColorDispatchers(0), |
|---|
| 370 | _fogCoordDispatchers(0), |
|---|
| 371 | _useGLBeginEndAdapter(false) |
|---|
| 372 | { |
|---|
| 373 | |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | ArrayDispatchers::~ArrayDispatchers() |
|---|
| 377 | { |
|---|
| 378 | delete _vertexDispatchers; |
|---|
| 379 | delete _normalDispatchers; |
|---|
| 380 | delete _colorDispatchers; |
|---|
| 381 | delete _secondaryColorDispatchers; |
|---|
| 382 | delete _fogCoordDispatchers; |
|---|
| 383 | |
|---|
| 384 | for(AttributeDispatchMapList::iterator itr = _texCoordDispatchers.begin(); |
|---|
| 385 | itr != _texCoordDispatchers.end(); |
|---|
| 386 | ++itr) |
|---|
| 387 | { |
|---|
| 388 | delete *itr; |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | for(AttributeDispatchMapList::iterator itr = _vertexAttribDispatchers.begin(); |
|---|
| 392 | itr != _vertexAttribDispatchers.end(); |
|---|
| 393 | ++itr) |
|---|
| 394 | { |
|---|
| 395 | delete *itr; |
|---|
| 396 | } |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | void ArrayDispatchers::setState(osg::State* state) |
|---|
| 400 | { |
|---|
| 401 | _state = state; |
|---|
| 402 | _glBeginEndAdapter = &(state->getGLBeginEndAdapter()); |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | void ArrayDispatchers::init() |
|---|
| 406 | { |
|---|
| 407 | if (_initialized) return; |
|---|
| 408 | |
|---|
| 409 | _initialized = true; |
|---|
| 410 | |
|---|
| 411 | _vertexDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter())); |
|---|
| 412 | _normalDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter())); |
|---|
| 413 | _colorDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter())); |
|---|
| 414 | _secondaryColorDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter())); |
|---|
| 415 | _fogCoordDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter())); |
|---|
| 416 | |
|---|
| 417 | _glBeginEndAdapter = &(_state->getGLBeginEndAdapter()); |
|---|
| 418 | _useGLBeginEndAdapter = false; |
|---|
| 419 | |
|---|
| 420 | #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE |
|---|
| 421 | Drawable::Extensions* extensions = Drawable::getExtensions(_state->getContextID(),true); |
|---|
| 422 | |
|---|
| 423 | #ifndef OSG_GLES1_AVAILABLE |
|---|
| 424 | _vertexDispatchers->assign<GLfloat>(Array::Vec2ArrayType, glVertex2fv, 2); |
|---|
| 425 | _vertexDispatchers->assign<GLfloat>(Array::Vec3ArrayType, glVertex3fv, 3); |
|---|
| 426 | _vertexDispatchers->assign<GLdouble>(Array::Vec2dArrayType, glVertex2dv, 2); |
|---|
| 427 | _vertexDispatchers->assign<GLdouble>(Array::Vec3dArrayType, glVertex3dv, 3); |
|---|
| 428 | _vertexDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::Vertex3fv, 3); |
|---|
| 429 | #endif |
|---|
| 430 | |
|---|
| 431 | _normalDispatchers->assign<GLbyte>(Array::Vec3bArrayType, glNormal3bv, 3); |
|---|
| 432 | _normalDispatchers->assign<GLshort>(Array::Vec3sArrayType, glNormal3sv, 3); |
|---|
| 433 | _normalDispatchers->assign<GLfloat>(Array::Vec3ArrayType, glNormal3fv, 3); |
|---|
| 434 | _normalDispatchers->assign<GLdouble>(Array::Vec3dArrayType, glNormal3dv, 3); |
|---|
| 435 | _normalDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::Normal3fv, 3); |
|---|
| 436 | |
|---|
| 437 | _colorDispatchers->assign<GLubyte>(Array::Vec4ubArrayType, glColor4ubv, 4); |
|---|
| 438 | _colorDispatchers->assign<GLfloat>(Array::Vec3ArrayType, glColor3fv, 3); |
|---|
| 439 | _colorDispatchers->assign<GLfloat>(Array::Vec4ArrayType, glColor4fv, 4); |
|---|
| 440 | _colorDispatchers->assign<GLdouble>(Array::Vec3dArrayType, glColor3dv, 3); |
|---|
| 441 | _colorDispatchers->assign<GLdouble>(Array::Vec4dArrayType, glColor4dv, 4); |
|---|
| 442 | _colorDispatchers->assignGLBeginEnd<GLubyte>(Array::Vec4ubArrayType, &GLBeginEndAdapter::Color4ubv, 4); |
|---|
| 443 | _colorDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec4ArrayType, &GLBeginEndAdapter::Color4fv, 4); |
|---|
| 444 | |
|---|
| 445 | _secondaryColorDispatchers->assign<GLfloat>(Array::Vec3ArrayType, extensions->_glSecondaryColor3fv, 3); |
|---|
| 446 | |
|---|
| 447 | _fogCoordDispatchers->assign<GLfloat>(Array::FloatArrayType, extensions->_glFogCoordfv, 1); |
|---|
| 448 | #endif |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | _activeDispatchList.resize(5); |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | AttributeDispatch* ArrayDispatchers::vertexDispatcher(Array* array, IndexArray* indices) |
|---|
| 455 | { |
|---|
| 456 | return _useVertexAttribAlias ? |
|---|
| 457 | vertexAttribDispatcher(_state->getVertexAlias()._location, array, indices) : |
|---|
| 458 | _vertexDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | AttributeDispatch* ArrayDispatchers::normalDispatcher(Array* array, IndexArray* indices) |
|---|
| 462 | { |
|---|
| 463 | return _useVertexAttribAlias ? |
|---|
| 464 | vertexAttribDispatcher(_state->getNormalAlias()._location, array, indices) : |
|---|
| 465 | _normalDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | AttributeDispatch* ArrayDispatchers::colorDispatcher(Array* array, IndexArray* indices) |
|---|
| 469 | { |
|---|
| 470 | return _useVertexAttribAlias ? |
|---|
| 471 | vertexAttribDispatcher(_state->getColorAlias()._location, array, indices) : |
|---|
| 472 | _colorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | AttributeDispatch* ArrayDispatchers::secondaryColorDispatcher(Array* array, IndexArray* indices) |
|---|
| 476 | { |
|---|
| 477 | return _useVertexAttribAlias ? |
|---|
| 478 | vertexAttribDispatcher(_state->getSecondaryColorAlias()._location, array, indices) : |
|---|
| 479 | _secondaryColorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | AttributeDispatch* ArrayDispatchers::fogCoordDispatcher(Array* array, IndexArray* indices) |
|---|
| 483 | { |
|---|
| 484 | return _useVertexAttribAlias ? |
|---|
| 485 | vertexAttribDispatcher(_state->getFogCoordAlias()._location, array, indices) : |
|---|
| 486 | _fogCoordDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices); |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | AttributeDispatch* ArrayDispatchers::texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices) |
|---|
| 490 | { |
|---|
| 491 | if (_useVertexAttribAlias) return vertexAttribDispatcher(_state->getTexCoordAliasList()[unit]._location, array, indices); |
|---|
| 492 | |
|---|
| 493 | if (unit>=_texCoordDispatchers.size()) assignTexCoordDispatchers(unit); |
|---|
| 494 | return _texCoordDispatchers[unit]->dispatcher(_useGLBeginEndAdapter, array, indices); |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | AttributeDispatch* ArrayDispatchers::vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices) |
|---|
| 498 | { |
|---|
| 499 | if (unit>=_vertexAttribDispatchers.size()) assignVertexAttribDispatchers(unit); |
|---|
| 500 | return _vertexAttribDispatchers[unit]->dispatcher(_useGLBeginEndAdapter, array, indices); |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit) |
|---|
| 504 | { |
|---|
| 505 | #if defined(OSG_GL_VERTEX_FUNCS_AVAILABLE) && !defined(OSG_GLES1_AVAILABLE) |
|---|
| 506 | Drawable::Extensions* extensions = Drawable::getExtensions(_state->getContextID(),true); |
|---|
| 507 | for(unsigned int i=_texCoordDispatchers.size(); i<=unit; ++i) |
|---|
| 508 | { |
|---|
| 509 | _texCoordDispatchers.push_back(new AttributeDispatchMap(_glBeginEndAdapter)); |
|---|
| 510 | AttributeDispatchMap& texCoordDispatcher = *_texCoordDispatchers[i]; |
|---|
| 511 | if (i==0) |
|---|
| 512 | { |
|---|
| 513 | texCoordDispatcher.assign<GLfloat>(Array::FloatArrayType, glTexCoord1fv, 1); |
|---|
| 514 | texCoordDispatcher.assign<GLfloat>(Array::Vec2ArrayType, glTexCoord2fv, 2); |
|---|
| 515 | texCoordDispatcher.assign<GLfloat>(Array::Vec3ArrayType, glTexCoord3fv, 3); |
|---|
| 516 | texCoordDispatcher.assign<GLfloat>(Array::Vec4ArrayType, glTexCoord4fv, 4); |
|---|
| 517 | texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::FloatArrayType, &GLBeginEndAdapter::TexCoord1fv, 3); |
|---|
| 518 | texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec2ArrayType, &GLBeginEndAdapter::TexCoord2fv, 3); |
|---|
| 519 | texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::TexCoord3fv, 3); |
|---|
| 520 | texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec4ArrayType, &GLBeginEndAdapter::TexCoord4fv, 4); |
|---|
| 521 | } |
|---|
| 522 | else |
|---|
| 523 | { |
|---|
| 524 | texCoordDispatcher.targetAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::FloatArrayType, extensions->_glMultiTexCoord1fv, 1); |
|---|
| 525 | texCoordDispatcher.targetAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec2ArrayType, extensions->_glMultiTexCoord2fv, 2); |
|---|
| 526 | texCoordDispatcher.targetAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec3ArrayType, extensions->_glMultiTexCoord3fv, 3); |
|---|
| 527 | texCoordDispatcher.targetAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec4ArrayType, extensions->_glMultiTexCoord4fv, 4); |
|---|
| 528 | texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::FloatArrayType, &GLBeginEndAdapter::MultiTexCoord1fv, 1); |
|---|
| 529 | texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec2ArrayType, &GLBeginEndAdapter::MultiTexCoord2fv, 2); |
|---|
| 530 | texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec3ArrayType, &GLBeginEndAdapter::MultiTexCoord3fv, 3); |
|---|
| 531 | texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec4ArrayType, &GLBeginEndAdapter::MultiTexCoord4fv, 4); |
|---|
| 532 | } |
|---|
| 533 | } |
|---|
| 534 | #endif |
|---|
| 535 | } |
|---|
| 536 | |
|---|
| 537 | void ArrayDispatchers::assignVertexAttribDispatchers(unsigned int unit) |
|---|
| 538 | { |
|---|
| 539 | Drawable::Extensions* extensions = Drawable::getExtensions(_state->getContextID(),true); |
|---|
| 540 | |
|---|
| 541 | for(unsigned int i=_vertexAttribDispatchers.size(); i<=unit; ++i) |
|---|
| 542 | { |
|---|
| 543 | _vertexAttribDispatchers.push_back(new AttributeDispatchMap(_glBeginEndAdapter)); |
|---|
| 544 | AttributeDispatchMap& texCoordDispatcher = *_vertexAttribDispatchers[i]; |
|---|
| 545 | texCoordDispatcher.targetAssign<GLuint, GLfloat>(i, Array::FloatArrayType, extensions->_glVertexAttrib1fv, 1); |
|---|
| 546 | texCoordDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec2ArrayType, extensions->_glVertexAttrib2fv, 2); |
|---|
| 547 | texCoordDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec3ArrayType, extensions->_glVertexAttrib3fv, 3); |
|---|
| 548 | texCoordDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec4ArrayType, extensions->_glVertexAttrib4fv, 4); |
|---|
| 549 | } |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | void ArrayDispatchers::reset() |
|---|
| 553 | { |
|---|
| 554 | if (!_initialized) init(); |
|---|
| 555 | |
|---|
| 556 | _useGLBeginEndAdapter = false; |
|---|
| 557 | |
|---|
| 558 | for(ActiveDispatchList::iterator itr = _activeDispatchList.begin(); |
|---|
| 559 | itr != _activeDispatchList.end(); |
|---|
| 560 | ++itr) |
|---|
| 561 | { |
|---|
| 562 | (*itr).clear(); |
|---|
| 563 | } |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | } |
|---|