GteGL4TextureCubeArray.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
9 #include <LowLevel/GteLogger.h>
11 using namespace gte;
12 
14 {
16 }
17 
19  :
21 {
22  // Create a texture structure.
25 
26  // Allocate (immutable) texture storage for all levels.
27  auto const width = texture->GetDimension(0);
28  auto const height = texture->GetDimension(1);
29  auto const numItems = texture->GetNumItems();
30  auto const numCubes = texture->GetNumCubes();
32 
33  // The default is 4-byte alignment. This allows byte alignment when data
34  // from user buffers into textures and vice versa.
37 
38  // Set the range of levels.
41 
42  // Initialize with data?
43  if (texture->GetData())
44  {
45  // Initialize with first mipmap level and then generate mipmaps.
47  {
48  for (unsigned int cube = 0; cube < numCubes; ++cube)
49  {
50  for (unsigned int face = 0; face < texture->CubeFaceCount; ++face)
51  {
52  auto data = texture->GetDataFor(cube, face, 0);
53  if (data)
54  {
55  auto item = texture->GetItemIndexFor(cube, face);
56  LoadTextureLevel(item, 0, data);
57  }
58  }
59  }
61  }
62  // Initialize with each mipmap level.
63  else
64  {
65  for (unsigned int cube = 0; cube < numCubes; ++cube)
66  {
67  for (unsigned int face = 0; face < texture->CubeFaceCount; ++face)
68  {
69  for (int level = 0; level < mNumLevels; ++level)
70  {
71  auto data = texture->GetDataFor(cube, face, level);
72  if (data)
73  {
74  auto item = texture->GetItemIndexFor(cube, face);
75  LoadTextureLevel(item, level, data);
76  }
77  }
78  }
79  }
80  }
81  }
82 
83  // Cannot leave this texture bound.
85 
86  // Create a staging texture if requested.
87  CreateStaging();
88 }
89 
90 std::shared_ptr<GEObject> GL4TextureCubeArray::Create(void*, GraphicsObject const* object)
91 {
92  if (object->GetType() == GT_TEXTURE_CUBE_ARRAY)
93  {
94  return std::make_shared<GL4TextureCubeArray>(
95  static_cast<TextureCubeArray const*>(object));
96  }
97 
98  LogError("Invalid object type.");
99  return nullptr;
100 }
101 
103 {
104  auto texture = GetTexture();
105 
106  return texture && texture->HasMipmaps() && texture->WantAutogenerateMipmaps();
107 }
108 
109 void GL4TextureCubeArray::LoadTextureLevel(unsigned int item, unsigned int level, void const* data)
110 {
111  auto texture = GetTexture();
112  if (texture && level < texture->GetNumLevels())
113  {
114  auto const width = texture->GetDimensionFor(level, 0);
115  auto const height = texture->GetDimensionFor(level, 1);
116 
117  // Determine cube and face indexes from the item index.
118  auto const cube = texture->GetCubeIndexFor(item);
119  auto const face = texture->GetFaceIndexFor(item);
120 
121  // Each face in the TextureCubeArray has a unique GL target.
122  GLenum targetFace = msCubeFaceTarget[face];
123 
124  // For TextureCubeArray, use the 3D calls where the cube index is the third dimension.
125  // Only updating one cube-face for the specified level.
126  glTexSubImage3D(targetFace, level, 0, 0, cube, width, height, 1,
128  }
129 }
void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
Definition: GteOpenGL.cpp:253
GLint GLsizei width
Definition: glcorearb.h:98
virtual bool CanAutoGenerateMipmaps() const override
GLuint mExternalType
Definition: GteGL4Texture.h:39
GLint level
Definition: glcorearb.h:103
unsigned int GetNumCubes() const
static const unsigned int CubeFaceCount
void APIENTRY glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
Definition: GteOpenGL.cpp:7639
char const * GetDataFor(unsigned int cube, unsigned int face, unsigned int level) const
GraphicsObjectType GetType() const
void APIENTRY glDeleteTextures(GLsizei n, const GLuint *textures)
Definition: GteOpenGL.cpp:980
static GLenum const msCubeFaceTarget[6]
void APIENTRY glPixelStorei(GLenum pname, GLint param)
Definition: GteOpenGL.cpp:539
#define GL_PACK_ALIGNMENT
Definition: glcorearb.h:299
static std::shared_ptr< GEObject > Create(void *unused, GraphicsObject const *object)
void APIENTRY glBindTexture(GLenum target, GLuint texture)
Definition: GteOpenGL.cpp:967
#define GL_TEXTURE_BASE_LEVEL
Definition: glcorearb.h:463
#define GL_TEXTURE_MAX_LEVEL
Definition: glcorearb.h:464
unsigned int GLenum
Definition: glcorearb.h:83
#define GL_UNPACK_ALIGNMENT
Definition: glcorearb.h:293
void APIENTRY glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels)
Definition: GteOpenGL.cpp:1078
GLuint mInternalFormat
Definition: GteGL4Texture.h:37
#define LogError(message)
Definition: GteLogger.h:92
GT_TEXTURE_CUBE_ARRAY
GLboolean * data
Definition: glcorearb.h:126
GLuint texture
Definition: glcorearb.h:410
void APIENTRY glGenTextures(GLsizei n, GLuint *textures)
Definition: GteOpenGL.cpp:993
char const * GetData() const
Definition: GteResource.h:151
#define GL_TEXTURE_CUBE_MAP_ARRAY
Definition: glcorearb.h:1712
GLint GLsizei GLsizei height
Definition: glcorearb.h:98
unsigned int GetNumItems() const
Definition: GteTexture.h:95
unsigned int GetDimension(int i) const
Definition: GteTexture.h:110
virtual void LoadTextureLevel(unsigned int item, unsigned int level, void const *data) override
unsigned int GetItemIndexFor(unsigned int cube, unsigned int face) const
GL4TextureCubeArray(TextureCubeArray const *texture)
GLuint mExternalFormat
Definition: GteGL4Texture.h:38
TextureCubeArray * GetTexture() const
GLuint object
Definition: glext.h:6426
virtual bool GenerateMipmaps()
#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
Definition: glcorearb.h:1713
GLenum GLuint GLint GLenum face
Definition: glext.h:3311


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00