Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textured-teapot: remove dead code #1055

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions teapots/textured-teapot/src/main/cpp/TeapotRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,8 @@ void TeapotRenderer::Init() {
glFrontFace(GL_CCW);

// Load shader
GLint type = GetTextureType();
if (type == GL_TEXTURE_CUBE_MAP) {
LoadShaders(&shader_param_, "Shaders/Cubemap.vsh", "Shaders/Cubemap.fsh");
} else if (type == GL_TEXTURE_2D) {
LoadShaders(&shader_param_, "Shaders/2DTexture.vsh",
"Shaders/2DTexture.fsh");
} else {
LoadShaders(&shader_param_, "Shaders/VS_ShaderPlain.vsh",
"Shaders/ShaderPlain.fsh");
}
LoadShaders(&shader_param_, "Shaders/Cubemap.vsh", "Shaders/Cubemap.fsh");

// Create Index buffer
num_indices_ = sizeof(teapotIndices) / sizeof(teapotIndices[0]);
glGenBuffers(1, &ibo_);
Expand Down
1 change: 0 additions & 1 deletion teapots/textured-teapot/src/main/cpp/TeapotRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class TeapotRenderer {
TeapotRenderer();
virtual ~TeapotRenderer();
virtual void Init(AAssetManager* amgr) = 0;
virtual GLint GetTextureType(void) = 0;
virtual void Render();
void Update(float dTime);
bool Bind(ndk_helper::TapCamera* camera);
Expand Down
14 changes: 2 additions & 12 deletions teapots/textured-teapot/src/main/cpp/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,12 @@ Texture::~Texture() {}
/**
* Create Texture Object
* @param texFiles holds the texture file name(s) under APK's assets
* @param type should be one (GL_TEXTURE_2D / GL_TEXTURE_CUBE_MAP)
* @param assetManager is used to open texture files inside assets
* @return is the newly created Texture Object
*/
Texture* Texture::Create(GLuint type, std::vector<std::string>& texFiles,
Texture* Texture::Create(std::vector<std::string>& texFiles,
AAssetManager* assetManager) {
if (type == GL_TEXTURE_2D) {
return dynamic_cast<Texture*>(new Texture2d(texFiles[0], assetManager));
} else if (type == GL_TEXTURE_CUBE_MAP) {
return dynamic_cast<Texture*>(new TextureCubemap(texFiles, assetManager));
}

LOGE("Unknow texture type %x to created", type);
LOGE("Supported Texture Types: %s", supportedTextureTypes.c_str());
assert(false);
return nullptr;
return new TextureCubemap(texFiles, assetManager);
}

void Texture::Delete(Texture* obj) {
Expand Down
3 changes: 1 addition & 2 deletions teapots/textured-teapot/src/main/cpp/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ class Texture {
public:
/**
* Create a texture object
* @param type should be GL_TEXTURE_2D / GL_TEXTURE_CUBE_MAP
* @param texFiles holds image file names under APK/assets.
* 2d texture uses the very first image texFiles[0]
* cube map needs 6 (direction of +x, -x, +y, -y, +z, -z)
* @param assetManager Java side assetManager object
* @return newly created texture object, or nullptr in case of errors
*/
static Texture* Create(GLuint type, std::vector<std::string>& texFiles,
static Texture* Create(std::vector<std::string>& texFiles,
AAssetManager* assetManager);
static void Delete(Texture* obj);

Expand Down
63 changes: 1 addition & 62 deletions teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#define TILED_TEXTURE 0

extern float teapotTexCoords[];
constexpr int32_t kCoordElementCount = (TILED_TEXTURE ? 3 : 2);

/**
* Constructor: all work is done inside Init() function.
Expand All @@ -44,21 +43,6 @@ TexturedTeapotRender::TexturedTeapotRender() {}
*/
TexturedTeapotRender::~TexturedTeapotRender() { Unload(); };

/**
* Report type of teapot we are rendering. This is the only place
* to decide what kind of teapot to render.
*
* @return
* GL_TEXTURE_CUBE_MAP if you want to render cubemaped teapot
* GL_TEXTURE_2D if just to render a 2D textured teapot
* GL_INVALID_VALUE no texture for teapot
*/
GLint TexturedTeapotRender::GetTextureType(void) {
return GL_TEXTURE_CUBE_MAP;
// GL_TEXTURE_2D;
// GL_INVALID_VALUE;
}

/**
* Init: Initialize the GL with needed data. We add on the things
* needed for textures
Expand All @@ -70,47 +54,6 @@ void TexturedTeapotRender::Init(AAssetManager* assetMgr) {
// initialize the basic things from TeapotRenderer, no change
TeapotRenderer::Init();

GLint type = GetTextureType();
if (type == GL_INVALID_VALUE) {
// Plain teapot no texture
return;
}

// load texture coordinator for 2D texture. Cubemap texture uses world space
// normal to sample cubemap.
if (type == GL_TEXTURE_2D) {
// do Texture related initializations...
glGenBuffers(1, &texVbo_);
assert(texVbo_ != GL_INVALID_VALUE);

/*
* Loading Texture coord directly from data declared in model file
* teapot.inl
* which is 3 floats/vertex.
*/
glBindBuffer(GL_ARRAY_BUFFER, texVbo_);

#if (TILED_TEXTURE)
glBufferData(GL_ARRAY_BUFFER,
kCoordElementCount * sizeof(float) * num_vertices_,
teapotTexCoords, GL_STATIC_DRAW);
#else
std::vector<float> coords;
for (int32_t idx = 0; idx < num_vertices_; idx++) {
coords.push_back(teapotTexCoords[3 * idx] / 2);
coords.push_back(teapotTexCoords[3 * idx + 1] / 2);
}
glBufferData(GL_ARRAY_BUFFER,
kCoordElementCount * sizeof(float) * num_vertices_,
coords.data(), GL_STATIC_DRAW);
#endif
glVertexAttribPointer(ATTRIB_UV, 2, GL_FLOAT, GL_FALSE,
kCoordElementCount * sizeof(float), BUFFER_OFFSET(0));
glEnableVertexAttribArray(ATTRIB_UV);

glBindBuffer(GL_ARRAY_BUFFER, 0);
}

// Need flip Y, so as top/bottom image
std::vector<std::string> textures{
std::string("Textures/right.tga"), // GL_TEXTURE_CUBE_MAP_POSITIVE_X
Expand All @@ -121,11 +64,7 @@ void TexturedTeapotRender::Init(AAssetManager* assetMgr) {
std::string("Textures/back.tga") // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};

if (type == GL_TEXTURE_2D) {
textures[0] = std::string("Textures/front.tga");
}

texObj_ = Texture::Create(type, textures, assetMgr);
texObj_ = Texture::Create(textures, assetMgr);
assert(texObj_);

std::vector<std::string> samplers;
Expand Down
7 changes: 0 additions & 7 deletions teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ class TexturedTeapotRender : public TeapotRenderer {
public:
TexturedTeapotRender();
virtual ~TexturedTeapotRender();
// This is to decide which teapot type to render:
// plain teapot
// 2D textured teapot
// Cubemap textured teapot
// the rest of the code looks this function to decide
// what to render.
virtual GLint GetTextureType(void);
virtual void Init(AAssetManager* amgr);
virtual void Render();
virtual void Unload();
Expand Down
Loading