Skip to content

Commit 3930e39

Browse files
committed
Remove all the unused texture code.
The app only ever draws cubemapped (environment reflection) textures. Remove all the 2D texture code and un-virtual the class.
1 parent aef87ae commit 3930e39

File tree

3 files changed

+33
-182
lines changed

3 files changed

+33
-182
lines changed

teapots/textured-teapot/src/main/cpp/Texture.cpp

Lines changed: 16 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -26,91 +26,18 @@
2626
#define MODULE_NAME "Teapot::Texture"
2727
#include "android_debug.h"
2828

29-
/**
30-
* Cubemap and Texture2d implementations for Class Texture.
31-
*/
32-
class TextureCubemap : public Texture {
33-
protected:
34-
GLuint texId_ = GL_INVALID_VALUE;
35-
bool activated_ = false;
36-
37-
public:
38-
virtual ~TextureCubemap();
39-
TextureCubemap(std::vector<std::string>& texFiles,
40-
AAssetManager* assetManager);
41-
virtual bool GetActiveSamplerInfo(std::vector<std::string>& names,
42-
std::vector<GLint>& units);
43-
virtual bool Activate(void);
44-
virtual GLuint GetTexType();
45-
virtual GLuint GetTexId();
46-
};
47-
48-
class Texture2d : public Texture {
49-
protected:
50-
GLuint texId_ = GL_INVALID_VALUE;
51-
bool activated_ = false;
52-
53-
public:
54-
virtual ~Texture2d();
55-
// Implement just one texture
56-
Texture2d(std::string& texFiles, AAssetManager* assetManager);
57-
virtual bool GetActiveSamplerInfo(std::vector<std::string>& names,
58-
std::vector<GLint>& units);
59-
virtual bool Activate(void);
60-
virtual GLuint GetTexType();
61-
virtual GLuint GetTexId();
62-
};
63-
64-
/**
65-
* Capability debug string
66-
*/
67-
static const std::string supportedTextureTypes =
68-
"GL_TEXTURE_2D(0x0DE1) GL_TEXTURE_CUBE_MAP(0x8513)";
69-
7029
/**
7130
* Interface implementations
7231
*/
73-
Texture::Texture() {}
74-
Texture::~Texture() {}
75-
/**
76-
* Create Texture Object
77-
* @param texFiles holds the texture file name(s) under APK's assets
78-
* @param assetManager is used to open texture files inside assets
79-
* @return is the newly created Texture Object
80-
*/
81-
Texture* Texture::Create(std::vector<std::string>& texFiles,
82-
AAssetManager* assetManager) {
83-
return new TextureCubemap(texFiles, assetManager);
84-
}
85-
86-
/**
87-
* TextureCubemap implementations
88-
*/
89-
bool TextureCubemap::Activate(void) {
90-
assert(texId_ != GL_INVALID_VALUE);
91-
92-
glBindTexture(texId_, GL_TEXTURE0);
93-
glActiveTexture(GL_TEXTURE0 + 0);
94-
activated_ = true;
95-
return true;
96-
}
97-
98-
GLuint TextureCubemap::GetTexType() { return GL_TEXTURE_CUBE_MAP; }
99-
100-
GLuint TextureCubemap::GetTexId() {
101-
assert(texId_ != GL_INVALID_VALUE);
102-
return texId_;
103-
}
104-
105-
TextureCubemap::TextureCubemap(std::vector<std::string>& files,
106-
AAssetManager* mgr) {
32+
Texture::Texture(std::vector<std::string>& asset_paths,
33+
AAssetManager* asset_manager) {
10734
// For Cubemap, we use world normal to sample the textures
10835
// so no texture vbo necessary
10936

11037
int32_t imgWidth, imgHeight, channelCount;
11138
std::vector<uint8_t> fileBits;
11239

113-
if (!mgr || files.size() != 6) {
40+
if (!asset_manager || asset_paths.size() != 6) {
11441
assert(false);
11542
return;
11643
}
@@ -125,9 +52,9 @@ TextureCubemap::TextureCubemap(std::vector<std::string>& files,
12552

12653
for (GLuint i = 0; i < 6; i++) {
12754
fileBits.clear();
128-
AssetReadFile(mgr, files[i], fileBits);
55+
AssetReadFile(asset_manager, asset_paths[i], fileBits);
12956

130-
// tga/bmp files are saved as vertical mirror images ( at least more than
57+
// tga/bmp asset_paths are saved as vertical mirror images ( at least more than
13158
// half ).
13259
stbi_set_flip_vertically_on_load(1);
13360

@@ -147,110 +74,35 @@ TextureCubemap::TextureCubemap(std::vector<std::string>& files,
14774
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
14875

14976
glActiveTexture(GL_TEXTURE0);
150-
activated_ = true;
15177
}
15278

153-
/**
154-
* Dtor
155-
* clean-up function
156-
*/
157-
TextureCubemap::~TextureCubemap() {
79+
Texture::~Texture() {
15880
if (texId_ != GL_INVALID_VALUE) {
15981
glDeleteTextures(1, &texId_);
16082
texId_ = GL_INVALID_VALUE;
161-
activated_ = false;
16283
}
16384
}
16485

16586
/**
166-
Return used sampler names and units
167-
so application could configure shader's sampler uniform(s).
168-
Cubemap just used one sampler at unit 0 with "samplerObj" as its name.
87+
* TextureCubemap implementations
16988
*/
170-
bool TextureCubemap::GetActiveSamplerInfo(std::vector<std::string>& names,
171-
std::vector<GLint>& units) {
172-
names.clear();
173-
names.push_back(std::string("samplerObj"));
174-
units.clear();
175-
units.push_back(0);
89+
bool Texture::Activate(void) {
90+
assert(texId_ != GL_INVALID_VALUE);
17691

92+
glBindTexture(texId_, GL_TEXTURE0);
93+
glActiveTexture(GL_TEXTURE0 + 0);
17794
return true;
17895
}
17996

18097
/**
181-
* Texture2D implementation
182-
*/
183-
Texture2d::Texture2d(std::string& fileName, AAssetManager* assetManager) {
184-
if (!assetManager) {
185-
LOGE("AssetManager to Texture2D() could not be null!!!");
186-
assert(false);
187-
return;
188-
}
189-
190-
int32_t imgWidth, imgHeight, channelCount;
191-
std::string texName(fileName);
192-
std::vector<uint8_t> fileBits;
193-
194-
glGenTextures(1, &texId_);
195-
glBindTexture(GL_TEXTURE_2D, texId_);
196-
197-
if (texId_ == GL_INVALID_VALUE) {
198-
assert(false);
199-
return;
200-
}
201-
202-
AssetReadFile(assetManager, texName, fileBits);
203-
204-
// tga/bmp files are saved as vertical mirror images ( at least more than half
205-
// ).
206-
stbi_set_flip_vertically_on_load(1);
207-
208-
uint8_t* imageBits =
209-
stbi_load_from_memory(fileBits.data(), fileBits.size(), &imgWidth,
210-
&imgHeight, &channelCount, 4);
211-
glTexImage2D(GL_TEXTURE_2D, 0, // mip level
212-
GL_RGBA, imgWidth, imgHeight,
213-
0, // border color
214-
GL_RGBA, GL_UNSIGNED_BYTE, imageBits);
215-
216-
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
217-
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
218-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
219-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
220-
221-
glActiveTexture(GL_TEXTURE0);
222-
223-
stbi_image_free(imageBits);
224-
}
225-
226-
Texture2d::~Texture2d() {
227-
if (texId_ != GL_INVALID_VALUE) {
228-
glDeleteTextures(1, &texId_);
229-
texId_ = GL_INVALID_VALUE;
230-
}
231-
activated_ = false;
232-
}
233-
234-
/**
235-
* Same as the Cubemap::GetActiveSamplerInfo()
98+
Return used sampler names and units
99+
so application could configure shader's sampler uniform(s).
100+
Cubemap just used one sampler at unit 0 with "samplerObj" as its name.
236101
*/
237-
bool Texture2d::GetActiveSamplerInfo(std::vector<std::string>& names,
238-
std::vector<GLint>& units) {
102+
void Texture::GetActiveSamplerInfo(std::vector<std::string>& names,
103+
std::vector<GLint>& units) {
239104
names.clear();
240105
names.push_back(std::string("samplerObj"));
241106
units.clear();
242107
units.push_back(0);
243-
244-
return true;
245-
}
246-
247-
bool Texture2d::Activate(void) {
248-
glBindTexture(texId_, GL_TEXTURE0);
249-
glActiveTexture(GL_TEXTURE0 + 0);
250-
activated_ = true;
251-
return true;
252108
}
253-
254-
GLuint Texture2d::GetTexType() { return GL_TEXTURE_2D; }
255-
256-
GLuint Texture2d::GetTexId() { return texId_; }

teapots/textured-teapot/src/main/cpp/Texture.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef TEAPOTS_TEXTURE_H
18-
#define TEAPOTS_TEXTURE_H
17+
#pragma once
1918

2019
#include <EGL/egl.h>
2120
#include <GLES/gl.h>
@@ -37,24 +36,24 @@
3736
*/
3837
class Texture {
3938
public:
40-
Texture();
41-
virtual ~Texture();
42-
4339
/**
44-
* Create a texture object
45-
* @param texFiles holds image file names under APK/assets.
46-
* 2d texture uses the very first image texFiles[0]
40+
* Create a texture object
41+
*
42+
* @param asset_paths holds image file names under APK/assets.
4743
* cube map needs 6 (direction of +x, -x, +y, -y, +z, -z)
48-
* @param assetManager Java side assetManager object
44+
* @param asset_manager Java side asset_manager object
4945
* @return newly created texture object, or nullptr in case of errors
5046
*/
51-
static Texture* Create(std::vector<std::string>& texFiles,
52-
AAssetManager* assetManager);
47+
Texture(std::vector<std::string>& asset_paths, AAssetManager* asset_manager);
48+
Texture(const Texture&) = delete;
49+
~Texture();
50+
51+
Texture& operator=(const Texture&) = delete;
52+
53+
void GetActiveSamplerInfo(std::vector<std::string>& names,
54+
std::vector<GLint>& units);
55+
bool Activate(void);
5356

54-
virtual bool GetActiveSamplerInfo(std::vector<std::string>& names,
55-
std::vector<GLint>& units) = 0;
56-
virtual bool Activate(void) = 0;
57-
virtual GLuint GetTexType() = 0;
58-
virtual GLuint GetTexId() = 0;
57+
private:
58+
GLuint texId_;
5959
};
60-
#endif // TEAPOTS_TEXTURE_H

teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void TexturedTeapotRender::Init(AAssetManager* assetMgr) {
6464
std::string("Textures/back.tga") // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
6565
};
6666

67-
texObj_ = Texture::Create(textures, assetMgr);
67+
texObj_ = new Texture(textures, assetMgr);
6868
assert(texObj_);
6969

7070
std::vector<std::string> samplers;

0 commit comments

Comments
 (0)