in PlayAssetDelivery/NativeSample/Teapot/src/main/cpp/TexturedTeapotRender.cpp [71:137]
void TexturedTeapotRender::Init(android_app *app) {
// initialize the basic things from TeapotRenderer, no change
TeapotRenderer::Init();
app_ = app;
// 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);
int index = textureIndex;
bool isUnderApk = true;
if (renderPack.compare("on_demand_pack") == 0) {
index += 3;
isUnderApk = false;
} else if (renderPack.compare("fast_follow_pack") == 0) {
index += 6;
isUnderApk = false;
}
renderTextures[0] = renderTextures[index];
textureIndex++;
if (textureIndex > maxIndex) {
textureIndex = 1;
}
renderInfo = "Texture::" + renderPack + "/" + renderTextures[0];
texObj_ =
Texture::Create(renderTextures[0], app_->activity->assetManager, renderPack, isUnderApk);
assert(texObj_);
std::vector<std::string> samplers;
std::vector<GLint> units;
texObj_->GetActiveSamplerInfo(samplers, units);
for (size_t idx = 0; idx < samplers.size(); idx++) {
GLint sampler = glGetUniformLocation(shader_param_.program_,
samplers[idx].c_str());
glUniform1i(sampler, units[idx]);
}
texObj_->Activate();
}