VR-Forces Developer's Guide
 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) 2018 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 : 3;
31  unsigned int compressed : 1;
32  unsigned int max : 4;
33  unsigned int wrap_s : 4;
34  unsigned int wrap_t : 4;
35  };
36  };
37 
38  // \Returns true if the entire texture collection should be flushed.
39  bool flush()
40  {
41  TextureList replacementList;
42 
43  TextureList::iterator i = myTextures.begin();
44  TextureList::iterator e = myTextures.end();
45  for (; i != e; ++i)
46  {
47  if (i->second->referenceCount() > 1)
48  {
49  replacementList.push_back(*i);
50  }
51  }
52  if (replacementList.size() != myTextures.size())
53  {
54  myTextures.swap(replacementList);
55  }
56  return myTextures.size() == 0;
57  }
58 
59  void releaseGLObjects(osg::State * state)
60  {
61  TextureList::iterator i = myTextures.begin();
62  TextureList::iterator e = myTextures.end();
63  for (; i != e; ++i)
64  {
65  i->second->releaseGLObjects(state);
66  }
67  }
68 
69  bool findTexture(unsigned int minFilter, unsigned int magFilter,
70  unsigned int wrapS, unsigned wrapT, bool compressed, osg::ref_ptr<osg::Texture>& texture)
71  {
72  KeyType k;
73 
74  k.min = ((minFilter ^ 0x2600) & 0x3) + ((minFilter ^ 0x2600) >> 7);
75  k.max = ((magFilter ^ 0x2600) & 0x3) + ((magFilter ^ 0x2600) >> 7);
76  k.wrap_s = (wrapS & 0x0F) | ((wrapS & 0x10) >> 3);
77  k.wrap_t = (wrapT & 0x0F) | ((wrapT & 0x10) >> 3);
78  k.compressed = compressed;
79 
80  TextureList::iterator i = myTextures.begin();
81  TextureList::iterator e = myTextures.end();
82  for (; i != e; ++i)
83  {
84  if (i->first.key == k.key)
85  {
86  texture = i->second;
87  return true;
88  }
89  }
90  return false;
91  }
92 
93  void addTexture(osg::Texture* texture, bool compressed)
94  {
95  KeyTexturePair pair;
96 
97  pair.first.min = ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) & 0x3) +
98  ((texture->getFilter(osg::Texture::MIN_FILTER) ^ 0x2600) >> 7);
99 
100  pair.first.max = ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) & 0x3) +
101  ((texture->getFilter(osg::Texture::MAG_FILTER) ^ 0x2600) >> 7);
102 
103  pair.first.wrap_s = (texture->getWrap(osg::Texture::WRAP_S) & 0x0F) |
104  ((texture->getWrap(osg::Texture::WRAP_S) & 0x10) >> 3);
105 
106  pair.first.wrap_t = (texture->getWrap(osg::Texture::WRAP_T) & 0x0F) |
107  ((texture->getWrap(osg::Texture::WRAP_T) & 0x10) >> 3);
108 
109  pair.first.compressed = compressed;
110 
111  pair.second = texture;
112  myTextures.push_back(pair);
113  }
114 
115  typedef std::pair<KeyType, osg::ref_ptr<osg::Texture> > KeyTexturePair;
116  typedef std::vector<KeyTexturePair> TextureList;
118  };
119 }
void releaseGLObjects(osg::State *state)
Definition: DtTextureCollection.h:59
unsigned int min
Definition: DtTextureCollection.h:30
Definition: DtIndirectTexturePrototype.h:29
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
unsigned int compressed
Definition: DtTextureCollection.h:31
unsigned int wrap_t
Definition: DtTextureCollection.h:34
bool findTexture(unsigned int minFilter, unsigned int magFilter, unsigned int wrapS, unsigned wrapT, bool compressed, osg::ref_ptr< osg::Texture > &texture)
Definition: DtTextureCollection.h:69
Definition: DtTextureCollection.h:25
Helper class to be used in conjunction with DtOsgReferencedCollection Was uncessarily in DtOsgFileCac...
Definition: DtTextureCollection.h:22
std::pair< KeyType, osg::ref_ptr< osg::Texture > > KeyTexturePair
Definition: DtTextureCollection.h:115
unsigned int wrap_s
Definition: DtTextureCollection.h:33
bool flush()
Definition: DtTextureCollection.h:39
unsigned int max
Definition: DtTextureCollection.h:32
void addTexture(osg::Texture *texture, bool compressed)
Definition: DtTextureCollection.h:93
TextureList myTextures
Definition: DtTextureCollection.h:117
Definition: DtIndirectTexturePrototype.h:29
Contains DLL export macros.
std::vector< KeyTexturePair > TextureList
Definition: DtTextureCollection.h:116
unsigned short key
Definition: DtTextureCollection.h:27
Definition: DtIndirectTexturePrototype.h:24
Definition: DtIndirectTexturePrototype.h:24

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)