Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cubemaptexture.cc
Go to the documentation of this file.
1 
18 #include "ion/gfx/cubemaptexture.h"
19 
20 #include "ion/base/enumhelper.h"
21 #include "ion/base/static_assert.h"
22 #include "ion/portgfx/glheaders.h"
23 
24 namespace ion {
25 namespace gfx {
26 
28  : TextureBase(kCubeMapTexture),
32  faces_(&facenx_),
33  facenx_(this, kNegativeXSubImageChanged, kNegativeXMipmapChanged),
34  faceny_(this, kNegativeYSubImageChanged, kNegativeYMipmapChanged),
35  facenz_(this, kNegativeZSubImageChanged, kNegativeZMipmapChanged),
36  facepx_(this, kPositiveXSubImageChanged, kPositiveXMipmapChanged),
37  facepy_(this, kPositiveYSubImageChanged, kPositiveYMipmapChanged),
38  facepz_(this, kPositiveZSubImageChanged, kPositiveZMipmapChanged) {
39  DCHECK_EQ(&facenx_, &faces_[0]);
40  DCHECK_EQ(&faceny_, &faces_[1]);
41  DCHECK_EQ(&facenz_, &faces_[2]);
42  DCHECK_EQ(&facepx_, &faces_[3]);
43  DCHECK_EQ(&facepy_, &faces_[4]);
44  DCHECK_EQ(&facepz_, &faces_[5]);
45 }
46 
48  for (size_t j = 0; j < 6; ++j) {
49  const Face& face = faces_[j];
50  for (size_t i = 0; i < kMipmapSlotCount; ++i) {
51  if (Image* image = face.GetImage(i).Get())
52  image->RemoveReceiver(this);
53  }
54  }
55 }
56 
57 void CubeMapTexture::OnNotify(const base::Notifier* notifier) {
58  if (GetResourceCount()) {
59  if (notifier == GetSampler().Get()) {
61  } else {
62  for (size_t j = 0; j < 6; ++j) {
63  const Face& face = faces_[j];
64  int mipmap_changed_bit = static_cast<int>(
65  kNegativeXMipmapChanged + j * kMipmapSlotCount);
66  for (size_t i = 0; i < kMipmapSlotCount; ++i) {
67  if (notifier == face.GetImage(i).Get())
68  OnChanged(static_cast<int>(mipmap_changed_bit + i));
69  }
70  }
71  }
72  }
73 }
74 
75 } // namespace gfx
76 
77 namespace base {
78 
79 using gfx::CubeMapTexture;
80 
82 template <> ION_API
83 const EnumHelper::EnumData<CubeMapTexture::CubeFace> EnumHelper::GetEnumData() {
84  static const GLenum kValues[] = {
85  GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
86  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, GL_TEXTURE_CUBE_MAP_POSITIVE_X,
87  GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
88  };
89  static const char* kStrings[] = {
90  "Negative X", "Negative Y", "Negative Z",
91  "Positive X", "Positive Y", "Positive Z"
92  };
93  ION_STATIC_ASSERT(ARRAYSIZE(kValues) == ARRAYSIZE(kStrings),
94  "EnumHelper size mismatch");
95  return EnumData<CubeMapTexture::CubeFace>(
97  ARRAYSIZE(kValues)),
98  kStrings);
99 }
100 
101 } // namespace base
102 } // namespace ion
const SamplerPtr & GetSampler() const
Definition: texture.h:92
A Notifier both sends notifications to and receives notifications from other Notifiers.
Definition: notifier.h:35
~CubeMapTexture() override
The destructor is protected because all base::Referent classes must have protected or private destruc...
void OnChanged(int bit) const
Forwards OnChanged to all resources.
An Image represents 2D image data that can be used in a texture supplied to a shader.
Definition: image.h:35
This template class can be used to map between two kinds of indices when the following assumptions ap...
Definition: indexmap.h:40
const Grid & image
The original monochrome image data, as doubles (0 - 1).
Definition: sdfutils.cc:90
#define DCHECK_EQ(val1, val2)
Definition: logging.h:332
This is an internal base class for all texture types.
Definition: texture.h:41
CubeMapTexture()
This is because we cannot yet use C++11 initializer lists.
int GetResourceCount() const
Returns the number of resources that this holder holds.
#define ION_STATIC_ASSERT(expr, message)
Copyright 2016 Google Inc.
Definition: static_assert.h:35