Line data Source code
1 :
2 : /* Copyright (c) 2007-2014, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2010, Cedric Stalder <cedric.stalder@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #include "objectManager.h"
20 :
21 : #include "accum.h"
22 : #include "bitmapFont.h"
23 : #include "frameBufferObject.h"
24 : #include "pixelBufferObject.h"
25 : #include "texture.h"
26 :
27 : #include <eq/client/gl.h>
28 : #include <lunchbox/hash.h>
29 : #include <lunchbox/os.h>
30 : #include <lunchbox/referenced.h>
31 : #include <lunchbox/uploader.h>
32 : #include <string.h>
33 :
34 : //#define EQ_OM_TRACE_ALLOCATIONS
35 :
36 : namespace eq
37 : {
38 : namespace util
39 : {
40 : namespace
41 : {
42 : struct Object
43 : {
44 : unsigned id;
45 : unsigned num;
46 : };
47 :
48 : typedef stde::hash_map< const void*, Object > ObjectHash;
49 : typedef stde::hash_map< const void*, Texture* > TextureHash;
50 : typedef stde::hash_map< const void*, FrameBufferObject* > FBOHash;
51 : typedef stde::hash_map< const void*, PixelBufferObject* > PBOHash;
52 : typedef stde::hash_map< const void*, util::BitmapFont* > FontHash;
53 : typedef stde::hash_map< const void*, Accum* > AccumHash;
54 : typedef stde::hash_map< const void*, lunchbox::Uploader* > UploaderHash;
55 : #ifdef EQ_OM_TRACE_ALLOCATIONS
56 : typedef stde::hash_map< const void*, std::string > UploaderAllocs;
57 : #endif
58 : }
59 :
60 : namespace detail
61 : {
62 : class ObjectManager : public lunchbox::Referenced
63 : {
64 : public:
65 330 : ObjectManager( const GLEWContext* gl )
66 330 : {
67 330 : if( gl )
68 15 : memcpy( &glewContext, gl, sizeof( GLEWContext ));
69 : else
70 315 : lunchbox::setZero( &glewContext, sizeof( GLEWContext ));
71 330 : }
72 :
73 120 : virtual ~ObjectManager()
74 120 : {
75 : // Do not delete GL objects, we may no longer have a GL context.
76 60 : if( !lists.empty( ))
77 0 : LBWARN << lists.size()
78 0 : << " lists allocated in ObjectManager destructor"
79 0 : << std::endl;
80 60 : LBASSERT( lists.empty( ));
81 60 : lists.clear();
82 :
83 60 : if( !textures.empty( ))
84 0 : LBWARN << textures.size()
85 0 : << " textures allocated in ObjectManager destructor"
86 0 : << std::endl;
87 60 : LBASSERT( textures.empty( ));
88 60 : textures.clear();
89 :
90 60 : if( !buffers.empty( ))
91 0 : LBWARN << buffers.size()
92 0 : << " buffers allocated in ObjectManager destructor"
93 0 : << std::endl;
94 60 : LBASSERT( buffers.empty( ));
95 60 : buffers.clear();
96 :
97 60 : if( !programs.empty( ))
98 0 : LBWARN << programs.size()
99 0 : << " programs allocated in ObjectManager destructor"
100 0 : << std::endl;
101 60 : LBASSERT( programs.empty( ));
102 60 : programs.clear();
103 :
104 60 : if( !shaders.empty( ))
105 0 : LBWARN << shaders.size()
106 0 : << " shaders allocated in ObjectManager destructor"
107 0 : << std::endl;
108 60 : LBASSERT( shaders.empty( ));
109 60 : shaders.clear();
110 :
111 60 : if( !eqTextures.empty( ))
112 0 : LBWARN << eqTextures.size()
113 0 : << " eq::Texture allocated in ObjectManager destructor"
114 0 : << std::endl;
115 60 : LBASSERT( eqTextures.empty( ));
116 60 : eqTextures.clear();
117 :
118 60 : if( !eqFonts.empty( ))
119 0 : LBWARN << eqFonts.size()
120 0 : << " eq::BitmapFont allocated in ObjectManager destructor"
121 0 : << std::endl;
122 60 : LBASSERT( eqFonts.empty( ));
123 60 : eqFonts.clear();
124 :
125 60 : if( !eqFrameBufferObjects.empty( ))
126 0 : LBWARN << eqFrameBufferObjects.size()
127 0 : << " eq::FrameBufferObject's allocated in ObjectManager "
128 0 : << "destructor" << std::endl;
129 60 : LBASSERT( eqFrameBufferObjects.empty( ));
130 60 : eqFrameBufferObjects.clear();
131 :
132 60 : if( !eqUploaders.empty( ))
133 0 : LBWARN << eqUploaders.size()
134 0 : << " uploader allocated in ObjectManager destructor"
135 0 : << std::endl;
136 :
137 : #ifdef EQ_OM_TRACE_ALLOCATIONS
138 : LBASSERTINFO( eqUploaders.empty(), eqUploaderAllocs.begin()->second );
139 : #else
140 60 : LBASSERTINFO( eqUploaders.empty(), (void*)eqUploaders.begin()->second );
141 : #endif
142 60 : eqUploaders.clear();
143 120 : }
144 :
145 :
146 : GLEWContext glewContext;
147 : ObjectHash lists;
148 : ObjectHash textures;
149 : ObjectHash buffers;
150 : ObjectHash programs;
151 : ObjectHash shaders;
152 : ObjectHash uploaderDatas;
153 : AccumHash accums;
154 : TextureHash eqTextures;
155 : FBOHash eqFrameBufferObjects;
156 : PBOHash eqPixelBufferObjects;
157 : FontHash eqFonts;
158 : UploaderHash eqUploaders;
159 : #ifdef EQ_OM_TRACE_ALLOCATIONS
160 : UploaderAllocs eqUploaderAllocs;
161 : #endif
162 : };
163 : }
164 :
165 300 : ObjectManager::ObjectManager( const GLEWContext* const glewContext )
166 300 : : _impl( new detail::ObjectManager( glewContext ))
167 : {
168 300 : }
169 :
170 0 : ObjectManager::ObjectManager( const ObjectManager& shared )
171 0 : : _impl( shared._impl )
172 : {
173 0 : LBASSERT( _impl );
174 0 : LBASSERT( glewGetContext( ));
175 0 : }
176 :
177 30 : ObjectManager::~ObjectManager()
178 : {
179 30 : }
180 :
181 15 : ObjectManager& ObjectManager::operator = ( const ObjectManager& rhs )
182 : {
183 15 : if( this != &rhs )
184 15 : _impl = rhs._impl;
185 15 : LBASSERT( glewGetContext( ));
186 15 : return *this;
187 : }
188 :
189 30 : void ObjectManager::clear()
190 : {
191 30 : _impl = new detail::ObjectManager( 0 );
192 30 : }
193 :
194 34 : bool ObjectManager::isShared() const
195 : {
196 34 : return _impl->getRefCount() > 1;
197 : }
198 :
199 20 : const GLEWContext* ObjectManager::glewGetContext() const
200 : {
201 20 : return &_impl->glewContext;
202 : }
203 :
204 30 : void ObjectManager::deleteAll()
205 : {
206 90 : for( ObjectHash::const_iterator i = _impl->lists.begin();
207 60 : i != _impl->lists.end(); ++i )
208 : {
209 0 : const Object& object = i->second;
210 0 : LBVERB << "Delete list " << object.id << std::endl;
211 0 : glDeleteLists( object.id, object.num );
212 : }
213 30 : _impl->lists.clear();
214 :
215 90 : for( ObjectHash::const_iterator i = _impl->textures.begin();
216 60 : i != _impl->textures.end(); ++i )
217 : {
218 0 : const Object& object = i->second;
219 0 : LBVERB << "Delete texture " << object.id << std::endl;
220 0 : glDeleteTextures( 1, &object.id );
221 : }
222 30 : _impl->textures.clear();
223 :
224 90 : for( ObjectHash::const_iterator i = _impl->buffers.begin();
225 60 : i != _impl->buffers.end(); ++i )
226 : {
227 0 : const Object& object = i->second;
228 0 : LBVERB << "Delete buffer " << object.id << std::endl;
229 0 : glDeleteBuffers( 1, &object.id );
230 : }
231 30 : _impl->buffers.clear();
232 :
233 90 : for( ObjectHash::const_iterator i = _impl->programs.begin();
234 60 : i != _impl->programs.end(); ++i )
235 : {
236 0 : const Object& object = i->second;
237 0 : LBVERB << "Delete program " << object.id << std::endl;
238 0 : glDeleteProgram( object.id );
239 : }
240 30 : _impl->programs.clear();
241 :
242 90 : for( ObjectHash::const_iterator i = _impl->shaders.begin();
243 60 : i != _impl->shaders.end(); ++i )
244 : {
245 0 : const Object& object = i->second;
246 0 : LBVERB << "Delete shader " << object.id << std::endl;
247 0 : glDeleteShader( object.id );
248 : }
249 30 : _impl->shaders.clear();
250 :
251 90 : for( TextureHash::const_iterator i = _impl->eqTextures.begin();
252 60 : i != _impl->eqTextures.end(); ++i )
253 : {
254 0 : Texture* texture = i->second;
255 0 : LBVERB << "Delete eq::Texture " << i->first << " @" << (void*)texture
256 0 : << std::endl;
257 0 : texture->flush();
258 0 : delete texture;
259 : }
260 30 : _impl->eqTextures.clear();
261 :
262 90 : for( FontHash::const_iterator i = _impl->eqFonts.begin();
263 60 : i != _impl->eqFonts.end(); ++i )
264 : {
265 0 : util::BitmapFont* font = i->second;
266 0 : LBVERB << "Delete eq::Font " << i->first << " @" << (void*)font
267 0 : << std::endl;
268 0 : font->exit();
269 0 : delete font;
270 : }
271 30 : _impl->eqFonts.clear();
272 :
273 90 : for( FBOHash::const_iterator i =
274 30 : _impl->eqFrameBufferObjects.begin();
275 60 : i != _impl->eqFrameBufferObjects.end(); ++i )
276 : {
277 0 : FrameBufferObject* frameBufferObject = i->second;
278 0 : LBVERB << "Delete eq::FrameBufferObject " << i->first << " @"
279 0 : << (void*)frameBufferObject << std::endl;
280 0 : frameBufferObject->exit();
281 0 : delete frameBufferObject;
282 : }
283 30 : _impl->eqFrameBufferObjects.clear();
284 :
285 90 : for( UploaderHash::const_iterator i = _impl->eqUploaders.begin();
286 60 : i != _impl->eqUploaders.end(); ++i )
287 : {
288 0 : lunchbox::Uploader* uploader = i->second;
289 0 : LBVERB << "Delete uploader " << i->first << " @" << (void*)uploader
290 0 : << std::endl;
291 0 : uploader->clear();
292 0 : delete uploader;
293 : }
294 30 : _impl->eqUploaders.clear();
295 30 : }
296 :
297 : // display list functions
298 :
299 0 : GLuint ObjectManager::getList( const void* key ) const
300 : {
301 0 : ObjectHash::const_iterator i = _impl->lists.find( key );
302 0 : if( i == _impl->lists.end( ))
303 0 : return INVALID;
304 :
305 0 : const Object& object = i->second;
306 0 : return object.id;
307 : }
308 :
309 0 : GLuint ObjectManager::newList( const void* key, const GLsizei num )
310 : {
311 0 : if( _impl->lists.find( key ) != _impl->lists.end( ))
312 : {
313 0 : LBWARN << "Requested new list for existing key" << std::endl;
314 0 : return INVALID;
315 : }
316 :
317 0 : const GLuint id = glGenLists( num );
318 0 : if( !id )
319 : {
320 0 : LBWARN << "glGenLists failed: " << glGetError() << std::endl;
321 0 : return INVALID;
322 : }
323 :
324 0 : Object& object = _impl->lists[ key ];
325 0 : object.id = id;
326 0 : object.num = num;
327 :
328 0 : return id;
329 : }
330 :
331 0 : GLuint ObjectManager::obtainList( const void* key, const GLsizei num )
332 : {
333 0 : const GLuint id = getList( key );
334 0 : if( id != INVALID )
335 0 : return id;
336 0 : return newList( key, num );
337 : }
338 :
339 0 : void ObjectManager::deleteList( const void* key )
340 : {
341 0 : ObjectHash::iterator i = _impl->lists.find( key );
342 0 : if( i == _impl->lists.end( ))
343 0 : return;
344 :
345 0 : const Object& object = i->second;
346 0 : glDeleteLists( object.id, object.num );
347 0 : _impl->lists.erase( i );
348 : }
349 :
350 : // texture object functions
351 :
352 0 : GLuint ObjectManager::getTexture( const void* key ) const
353 : {
354 0 : ObjectHash::const_iterator i = _impl->textures.find( key );
355 0 : if( i == _impl->textures.end( ))
356 0 : return INVALID;
357 :
358 0 : const Object& object = i->second;
359 0 : return object.id;
360 : }
361 :
362 0 : GLuint ObjectManager::newTexture( const void* key )
363 : {
364 0 : if( _impl->textures.find( key ) != _impl->textures.end( ))
365 : {
366 0 : LBWARN << "Requested new texture for existing key" << std::endl;
367 0 : return INVALID;
368 : }
369 :
370 0 : GLuint id = INVALID;
371 0 : glGenTextures( 1, &id );
372 0 : if( id == INVALID )
373 : {
374 0 : LBWARN << "glGenTextures failed: " << glGetError() << std::endl;
375 0 : return INVALID;
376 : }
377 :
378 0 : Object& object = _impl->textures[ key ];
379 0 : object.id = id;
380 0 : return id;
381 : }
382 :
383 0 : GLuint ObjectManager::obtainTexture( const void* key )
384 : {
385 0 : const GLuint id = getTexture( key );
386 0 : if( id != INVALID )
387 0 : return id;
388 0 : return newTexture( key );
389 : }
390 :
391 0 : void ObjectManager::deleteTexture( const void* key )
392 : {
393 0 : ObjectHash::iterator i = _impl->textures.find( key );
394 0 : if( i == _impl->textures.end( ))
395 0 : return;
396 :
397 0 : const Object& object = i->second;
398 0 : glDeleteTextures( 1, &object.id );
399 0 : _impl->textures.erase( i );
400 : }
401 :
402 : // buffer object functions
403 :
404 0 : bool ObjectManager::supportsBuffers() const
405 : {
406 0 : return ( GLEW_VERSION_1_5 );
407 : }
408 :
409 0 : GLuint ObjectManager::getBuffer( const void* key ) const
410 : {
411 0 : ObjectHash::const_iterator i = _impl->buffers.find( key );
412 0 : if( i == _impl->buffers.end() )
413 0 : return INVALID;
414 :
415 0 : const Object& object = i->second;
416 0 : return object.id;
417 : }
418 :
419 0 : GLuint ObjectManager::newBuffer( const void* key )
420 : {
421 0 : if( !GLEW_VERSION_1_5 )
422 : {
423 0 : LBWARN << "glGenBuffers not available" << std::endl;
424 0 : return INVALID;
425 : }
426 :
427 0 : if( _impl->buffers.find( key ) != _impl->buffers.end() )
428 : {
429 0 : LBWARN << "Requested new buffer for existing key" << std::endl;
430 0 : return INVALID;
431 : }
432 :
433 0 : GLuint id = INVALID;
434 0 : glGenBuffers( 1, &id );
435 :
436 0 : if( id == INVALID )
437 : {
438 0 : LBWARN << "glGenBuffers failed: " << glGetError() << std::endl;
439 0 : return INVALID;
440 : }
441 :
442 0 : Object& object = _impl->buffers[ key ];
443 0 : object.id = id;
444 0 : return id;
445 : }
446 :
447 0 : GLuint ObjectManager::obtainBuffer( const void* key )
448 : {
449 0 : const GLuint id = getBuffer( key );
450 0 : if( id != INVALID )
451 0 : return id;
452 0 : return newBuffer( key );
453 : }
454 :
455 0 : void ObjectManager::deleteBuffer( const void* key )
456 : {
457 0 : ObjectHash::iterator i = _impl->buffers.find( key );
458 0 : if( i == _impl->buffers.end() )
459 0 : return;
460 :
461 0 : const Object& object = i->second;
462 0 : glDeleteBuffers( 1, &object.id );
463 0 : _impl->buffers.erase( i );
464 : }
465 :
466 : // program object functions
467 :
468 0 : bool ObjectManager::supportsPrograms() const
469 : {
470 0 : return ( GLEW_VERSION_2_0 );
471 : }
472 :
473 0 : GLuint ObjectManager::getProgram( const void* key ) const
474 : {
475 0 : ObjectHash::const_iterator i = _impl->programs.find( key );
476 0 : if( i == _impl->programs.end() )
477 0 : return INVALID;
478 :
479 0 : const Object& object = i->second;
480 0 : return object.id;
481 : }
482 :
483 0 : GLuint ObjectManager::newProgram( const void* key )
484 : {
485 0 : if( !GLEW_VERSION_2_0 )
486 : {
487 0 : LBWARN << "glCreateProgram not available" << std::endl;
488 0 : return INVALID;
489 : }
490 :
491 0 : if( _impl->programs.find( key ) != _impl->programs.end() )
492 : {
493 0 : LBWARN << "Requested new program for existing key" << std::endl;
494 0 : return INVALID;
495 : }
496 :
497 0 : const GLuint id = glCreateProgram();
498 0 : if( !id )
499 : {
500 0 : LBWARN << "glCreateProgram failed: " << glGetError() << std::endl;
501 0 : return INVALID;
502 : }
503 :
504 0 : Object& object = _impl->programs[ key ];
505 0 : object.id = id;
506 0 : return id;
507 : }
508 :
509 0 : GLuint ObjectManager::obtainProgram( const void* key )
510 : {
511 0 : const GLuint id = getProgram( key );
512 0 : if( id != INVALID )
513 0 : return id;
514 0 : return newProgram( key );
515 : }
516 :
517 0 : void ObjectManager::deleteProgram( const void* key )
518 : {
519 0 : ObjectHash::iterator i = _impl->programs.find( key );
520 0 : if( i == _impl->programs.end() )
521 0 : return;
522 :
523 0 : const Object& object = i->second;
524 0 : glDeleteProgram( object.id );
525 0 : _impl->programs.erase( i );
526 : }
527 :
528 : // shader object functions
529 :
530 0 : bool ObjectManager::supportsShaders() const
531 : {
532 0 : return ( GLEW_VERSION_2_0 );
533 : }
534 :
535 0 : GLuint ObjectManager::getShader( const void* key ) const
536 : {
537 0 : ObjectHash::const_iterator i = _impl->shaders.find( key );
538 0 : if( i == _impl->shaders.end() )
539 0 : return INVALID;
540 :
541 0 : const Object& object = i->second;
542 0 : return object.id;
543 : }
544 :
545 0 : GLuint ObjectManager::newShader( const void* key, const GLenum type )
546 : {
547 0 : if( !GLEW_VERSION_2_0 )
548 : {
549 0 : LBWARN << "glCreateShader not available" << std::endl;
550 0 : return INVALID;
551 : }
552 :
553 0 : if( _impl->shaders.find( key ) != _impl->shaders.end() )
554 : {
555 0 : LBWARN << "Requested new shader for existing key" << std::endl;
556 0 : return INVALID;
557 : }
558 :
559 0 : const GLuint id = glCreateShader( type );
560 0 : if( !id )
561 : {
562 0 : LBWARN << "glCreateShader failed: " << glGetError() << std::endl;
563 0 : return INVALID;
564 : }
565 :
566 :
567 0 : Object& object = _impl->shaders[ key ];
568 0 : object.id = id;
569 0 : return id;
570 : }
571 :
572 0 : GLuint ObjectManager::obtainShader( const void* key, const GLenum type )
573 : {
574 0 : const GLuint id = getShader( key );
575 0 : if( id != INVALID )
576 0 : return id;
577 0 : return newShader( key, type );
578 : }
579 :
580 0 : void ObjectManager::deleteShader( const void* key )
581 : {
582 0 : ObjectHash::iterator i = _impl->shaders.find( key );
583 0 : if( i == _impl->shaders.end() )
584 0 : return;
585 :
586 0 : const Object& object = i->second;
587 0 : glDeleteShader( object.id );
588 0 : _impl->shaders.erase( i );
589 : }
590 :
591 0 : Accum* ObjectManager::getEqAccum( const void* key ) const
592 : {
593 0 : AccumHash::const_iterator i = _impl->accums.find( key );
594 0 : if( i == _impl->accums.end( ))
595 0 : return 0;
596 :
597 0 : return i->second;
598 : }
599 :
600 0 : Accum* ObjectManager::newEqAccum( const void* key )
601 : {
602 0 : if( _impl->accums.find( key ) != _impl->accums.end( ))
603 : {
604 0 : LBWARN << "Requested new Accumulation for existing key" << std::endl;
605 0 : return 0;
606 : }
607 :
608 0 : Accum* accum = new Accum( &_impl->glewContext );
609 0 : _impl->accums[ key ] = accum;
610 0 : return accum;
611 : }
612 :
613 0 : Accum* ObjectManager::obtainEqAccum( const void* key )
614 : {
615 0 : Accum* accum = getEqAccum( key );
616 0 : if( accum )
617 0 : return accum;
618 0 : return newEqAccum( key );
619 : }
620 :
621 0 : void ObjectManager::deleteEqAccum( const void* key )
622 : {
623 0 : AccumHash::iterator i = _impl->accums.find( key );
624 0 : if( i == _impl->accums.end( ))
625 0 : return;
626 :
627 0 : Accum* accum = i->second;
628 0 : _impl->accums.erase( i );
629 :
630 0 : accum->exit();
631 0 : delete accum;
632 : }
633 :
634 : // eq::CompressorData object functions
635 2 : lunchbox::Uploader* ObjectManager::getEqUploader( const void* key ) const
636 : {
637 2 : UploaderHash::const_iterator i = _impl->eqUploaders.find( key );
638 2 : if( i == _impl->eqUploaders.end( ))
639 2 : return 0;
640 :
641 0 : return i->second;
642 : }
643 :
644 2 : lunchbox::Uploader* ObjectManager::newEqUploader( const void* key )
645 : {
646 2 : if( _impl->eqUploaders.find( key ) != _impl->eqUploaders.end( ))
647 : {
648 0 : LBWARN << "Requested new compressor for existing key" << std::endl;
649 0 : return 0;
650 : }
651 :
652 2 : lunchbox::Uploader* compressor = new lunchbox::Uploader;
653 2 : _impl->eqUploaders[ key ] = compressor;
654 : #ifdef EQ_OM_TRACE_ALLOCATIONS
655 : std::ostringstream out;
656 : out << lunchbox::backtrace;
657 : _impl->eqUploaderAllocs[ key ] = out.str();
658 : #endif
659 :
660 2 : return compressor;
661 : }
662 :
663 2 : lunchbox::Uploader* ObjectManager::obtainEqUploader( const void* key )
664 : {
665 2 : lunchbox::Uploader* compressor = getEqUploader( key );
666 2 : if( compressor )
667 0 : return compressor;
668 2 : return newEqUploader( key );
669 : }
670 :
671 16 : void ObjectManager::deleteEqUploader( const void* key )
672 : {
673 16 : UploaderHash::iterator i = _impl->eqUploaders.find( key );
674 16 : if( i == _impl->eqUploaders.end( ))
675 30 : return;
676 :
677 2 : lunchbox::Uploader* uploader = i->second;
678 2 : _impl->eqUploaders.erase( i );
679 : #ifdef EQ_OM_TRACE_ALLOCATIONS
680 : _impl->eqUploaderAllocs.erase( key );
681 : #endif
682 2 : uploader->clear();
683 2 : delete uploader;
684 : }
685 :
686 : // eq::Texture object functions
687 0 : bool ObjectManager::supportsEqTexture() const
688 : {
689 0 : return (GLEW_ARB_texture_rectangle);
690 : }
691 :
692 0 : Texture* ObjectManager::getEqTexture( const void* key ) const
693 : {
694 0 : TextureHash::const_iterator i = _impl->eqTextures.find( key );
695 0 : if( i == _impl->eqTextures.end( ))
696 0 : return 0;
697 :
698 0 : return i->second;
699 : }
700 :
701 0 : Texture* ObjectManager::newEqTexture( const void* key, const GLenum target )
702 : {
703 0 : if( _impl->eqTextures.find( key ) != _impl->eqTextures.end( ))
704 : {
705 0 : LBWARN << "Requested new eqTexture for existing key" << std::endl;
706 0 : return 0;
707 : }
708 :
709 0 : Texture* texture = new Texture( target, &_impl->glewContext );
710 0 : _impl->eqTextures[ key ] = texture;
711 0 : return texture;
712 : }
713 :
714 0 : Texture* ObjectManager::obtainEqTexture( const void* key, const GLenum target )
715 : {
716 0 : Texture* texture = getEqTexture( key );
717 0 : if( texture )
718 0 : return texture;
719 0 : return newEqTexture( key, target );
720 : }
721 :
722 16 : void ObjectManager::deleteEqTexture( const void* key )
723 : {
724 16 : TextureHash::iterator i = _impl->eqTextures.find( key );
725 16 : if( i == _impl->eqTextures.end( ))
726 32 : return;
727 :
728 0 : Texture* texture = i->second;
729 0 : _impl->eqTextures.erase( i );
730 :
731 0 : texture->flush();
732 0 : delete texture;
733 : }
734 :
735 : // eq::util::BitmapFont object functions
736 0 : util::BitmapFont* ObjectManager::getEqBitmapFont( const void* key ) const
737 : {
738 0 : FontHash::const_iterator i = _impl->eqFonts.find( key );
739 0 : if( i == _impl->eqFonts.end( ))
740 0 : return 0;
741 :
742 0 : return i->second;
743 : }
744 :
745 0 : util::BitmapFont* ObjectManager::newEqBitmapFont( const void* key )
746 : {
747 0 : if( _impl->eqFonts.find( key ) != _impl->eqFonts.end( ))
748 : {
749 0 : LBWARN << "Requested new eqFont for existing key" << std::endl;
750 0 : return 0;
751 : }
752 :
753 0 : util::BitmapFont* font = new util::BitmapFont( *this, key );
754 0 : _impl->eqFonts[ key ] = font;
755 0 : return font;
756 : }
757 :
758 0 : util::BitmapFont* ObjectManager::obtainEqBitmapFont( const void* key )
759 : {
760 0 : util::BitmapFont* font = getEqBitmapFont( key );
761 0 : if( font )
762 0 : return font;
763 0 : return newEqBitmapFont( key );
764 : }
765 :
766 60 : void ObjectManager::deleteEqBitmapFont( const void* key )
767 : {
768 60 : FontHash::iterator i = _impl->eqFonts.find( key );
769 60 : if( i == _impl->eqFonts.end( ))
770 120 : return;
771 :
772 0 : util::BitmapFont* font = i->second;
773 0 : _impl->eqFonts.erase( i );
774 :
775 0 : font->exit();
776 0 : delete font;
777 : }
778 :
779 : // eq::FrameBufferObject object functions
780 0 : bool ObjectManager::supportsEqFrameBufferObject() const
781 : {
782 0 : return (GLEW_EXT_framebuffer_object);
783 : }
784 :
785 0 : FrameBufferObject* ObjectManager::getEqFrameBufferObject( const void* key )
786 : const
787 : {
788 0 : FBOHash::const_iterator i = _impl->eqFrameBufferObjects.find(key);
789 0 : if( i == _impl->eqFrameBufferObjects.end( ))
790 0 : return 0;
791 :
792 0 : return i->second;
793 : }
794 :
795 0 : FrameBufferObject* ObjectManager::newEqFrameBufferObject( const void* key )
796 : {
797 0 : if( _impl->eqFrameBufferObjects.find( key ) !=
798 0 : _impl->eqFrameBufferObjects.end( ))
799 : {
800 0 : LBWARN << "Requested new eqFrameBufferObject for existing key"
801 0 : << std::endl;
802 0 : return 0;
803 : }
804 :
805 : FrameBufferObject* frameBufferObject =
806 0 : new FrameBufferObject( &_impl->glewContext );
807 0 : _impl->eqFrameBufferObjects[ key ] = frameBufferObject;
808 0 : return frameBufferObject;
809 : }
810 :
811 0 : FrameBufferObject* ObjectManager::obtainEqFrameBufferObject( const void* key )
812 : {
813 0 : FrameBufferObject* frameBufferObject = getEqFrameBufferObject( key );
814 0 : if( frameBufferObject )
815 0 : return frameBufferObject;
816 0 : return newEqFrameBufferObject( key );
817 : }
818 :
819 0 : void ObjectManager::deleteEqFrameBufferObject( const void* key )
820 : {
821 0 : FBOHash::iterator i = _impl->eqFrameBufferObjects.find(key);
822 0 : if( i == _impl->eqFrameBufferObjects.end( ))
823 0 : return;
824 :
825 0 : FrameBufferObject* frameBufferObject = i->second;
826 0 : _impl->eqFrameBufferObjects.erase( i );
827 :
828 0 : frameBufferObject->exit();
829 0 : delete frameBufferObject;
830 : }
831 :
832 : // eq::PixelBufferObject object functions
833 0 : bool ObjectManager::supportsEqPixelBufferObject() const
834 : {
835 0 : return (GLEW_ARB_pixel_buffer_object);
836 : }
837 :
838 0 : PixelBufferObject* ObjectManager::getEqPixelBufferObject( const void* key )
839 : const
840 : {
841 0 : PBOHash::const_iterator i = _impl->eqPixelBufferObjects.find(key);
842 0 : if( i == _impl->eqPixelBufferObjects.end( ))
843 0 : return 0;
844 :
845 0 : return i->second;
846 : }
847 :
848 0 : PixelBufferObject* ObjectManager::newEqPixelBufferObject( const void* key,
849 : const bool threadSafe )
850 : {
851 0 : if( _impl->eqPixelBufferObjects.find( key ) !=
852 0 : _impl->eqPixelBufferObjects.end( ))
853 : {
854 0 : LBWARN << "Requested new eqPixelBufferObject for existing key"
855 0 : << std::endl;
856 0 : return 0;
857 : }
858 :
859 : PixelBufferObject* pixelBufferObject =
860 0 : new PixelBufferObject( &_impl->glewContext, threadSafe );
861 0 : _impl->eqPixelBufferObjects[ key ] = pixelBufferObject;
862 0 : return pixelBufferObject;
863 : }
864 :
865 0 : PixelBufferObject* ObjectManager::obtainEqPixelBufferObject( const void* key,
866 : const bool threadSafe )
867 : {
868 0 : PixelBufferObject* pixelBufferObject = getEqPixelBufferObject( key );
869 0 : if( pixelBufferObject )
870 : {
871 0 : if( pixelBufferObject->isThreadSafe() != threadSafe )
872 : {
873 0 : LBERROR << "Wrong sharing option requested!" << std::endl;
874 0 : return 0;
875 : }
876 0 : return pixelBufferObject;
877 : }
878 0 : return newEqPixelBufferObject( key, threadSafe );
879 : }
880 :
881 0 : void ObjectManager::deleteEqPixelBufferObject( const void* key )
882 : {
883 0 : PBOHash::iterator i = _impl->eqPixelBufferObjects.find(key);
884 0 : if( i == _impl->eqPixelBufferObjects.end( ))
885 0 : return;
886 :
887 0 : PixelBufferObject* pixelBufferObject = i->second;
888 0 : _impl->eqPixelBufferObjects.erase( i );
889 :
890 0 : pixelBufferObject->destroy();
891 0 : delete pixelBufferObject;
892 : }
893 :
894 : }
895 36 : }
|