diff --git a/teapots/textured-teapot/src/main/cpp/TeapotRenderer.cpp b/teapots/textured-teapot/src/main/cpp/TeapotRenderer.cpp index 6844e1c5d..596be30ea 100644 --- a/teapots/textured-teapot/src/main/cpp/TeapotRenderer.cpp +++ b/teapots/textured-teapot/src/main/cpp/TeapotRenderer.cpp @@ -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_); diff --git a/teapots/textured-teapot/src/main/cpp/TeapotRenderer.h b/teapots/textured-teapot/src/main/cpp/TeapotRenderer.h index 893f92aa9..ef22c85e1 100644 --- a/teapots/textured-teapot/src/main/cpp/TeapotRenderer.h +++ b/teapots/textured-teapot/src/main/cpp/TeapotRenderer.h @@ -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); diff --git a/teapots/textured-teapot/src/main/cpp/Texture.cpp b/teapots/textured-teapot/src/main/cpp/Texture.cpp index e3f940250..63d179041 100644 --- a/teapots/textured-teapot/src/main/cpp/Texture.cpp +++ b/teapots/textured-teapot/src/main/cpp/Texture.cpp @@ -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& texFiles, +Texture* Texture::Create(std::vector& texFiles, AAssetManager* assetManager) { - if (type == GL_TEXTURE_2D) { - return dynamic_cast(new Texture2d(texFiles[0], assetManager)); - } else if (type == GL_TEXTURE_CUBE_MAP) { - return dynamic_cast(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) { diff --git a/teapots/textured-teapot/src/main/cpp/Texture.h b/teapots/textured-teapot/src/main/cpp/Texture.h index a20b22912..298a9d715 100644 --- a/teapots/textured-teapot/src/main/cpp/Texture.h +++ b/teapots/textured-teapot/src/main/cpp/Texture.h @@ -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& texFiles, + static Texture* Create(std::vector& texFiles, AAssetManager* assetManager); static void Delete(Texture* obj); diff --git a/teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.cpp b/teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.cpp index 7d42f79d3..8f8ef1420 100644 --- a/teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.cpp +++ b/teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.cpp @@ -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. @@ -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 @@ -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 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 textures{ std::string("Textures/right.tga"), // GL_TEXTURE_CUBE_MAP_POSITIVE_X @@ -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 samplers; diff --git a/teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.h b/teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.h index e76c15288..693fc7337 100644 --- a/teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.h +++ b/teapots/textured-teapot/src/main/cpp/TexturedTeapotRender.h @@ -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();