VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtTextureCollection.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2017 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
8 
9 #pragma once
10 
11 #include <vrvOsg/vrvOsg.h>
12 
13 #include <osg/Referenced>
14 #include <osg/Texture>
15 
16 #include <vector>
17 
18 namespace makVrv
19 {
22  class DT_DLL_VRVOSG DtTextureCollection : public osg::Referenced
23  {
24  public:
25  union KeyType
26  {
27  unsigned short key;
28  struct
29  {
30  unsigned int min : 4;
31  unsigned int max : 4;
32  unsigned int wrap_s : 4;
33  unsigned int wrap_t : 4;
34  };
35  };
36 
37  // \Returns true if the entire texture collection should be flushed.
38  bool flush()
39  {
40  TextureList replacementList;
41 
42  TextureList::iterator i = myTextures.begin();
43  TextureList::iterator e = myTextures.end();
44  for (; i != e; ++i)
45  {
46  if (i->second->referenceCount() > 1)
47  {
48  replacementList.push_back(*i);
49  }
50  }
51  if (replacementList.size() != myTextures.size())
52  {
53  myTextures.swap(replacementList);
54  }
55  return myTextures.size() == 0;
56  }
57 
58  void releaseGLObjects(osg::State * state)
59  {
60  TextureList::iterator i = myTextures.begin();
61  TextureList::iterator e = myTextures.end();
62  for (; i != e; ++i)
63  {
64  i->second->releaseGLObjects(state);
65  }
66  }
67 
68  bool findTexture(unsigned int minFilter, unsigned int magFilter,
69  unsigned int wrapS, unsigned wrapT, osg::ref_ptr<osg::Texture>& texture)
70  {
71  KeyType k;
72  k.min = ((minFilter ^ 0x2600) & 0x3) + ((minFilter ^ 0x2600) >> 7);
73  k.max = ((magFilter ^ 0x2600) & 0x3) + ((magFilter ^ 0x2600) >> 7);
74  k.wrap_s = (wrapS & 0x0F) | ((wrapS & 0x10) >> 3);
75  k.wrap_t = (wrapT & 0x0F) | ((wrapT & 0x10) >> 3);
76 
77  TextureList::iterator i = myTextures.begin();
78  TextureList::iterator e = myTextures.end();
79  for (; i != e; ++i)
80  {
81  if (i->first.key == k.key)
82  {
83  texture = i->second;
84  return true;
85  }
86  }
87  return false;
88  }
89 
90  void addTexture(osg::Texture* texture)
91  {
92  KeyTexturePair pair;
93 
94  pair.first.min = ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) & 0x3) +
95  ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) >> 7);
96 
97  pair.first.max = ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) & 0x3) +
98  ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) >> 7);
99 
100  pair.first.wrap_s = (texture->getWrap(osg::Texture::WRAP_S) & 0x0F) |
101  ((texture->getWrap(osg::Texture::WRAP_S) & 0x10) >> 3);
102 
103  pair.first.wrap_t = (texture->getWrap(osg::Texture::WRAP_T) & 0x0F) |
104  ((texture->getWrap(osg::Texture::WRAP_T) & 0x10) >> 3);
105  pair.second = texture;
106  myTextures.push_back(pair);
107  }
108 
109  typedef std::pair<KeyType, osg::ref_ptr<osg::Texture> > KeyTexturePair;
110  typedef std::vector<KeyTexturePair> TextureList;
112  };
113 }

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)