MCPcopy Create free account
hub / github.com/android/ndk-samples / Init

Method Init

teapots/image-decoder/src/main/cpp/ImageDecoderRender.cpp:65–137  ·  view source on GitHub ↗

* Init: Initialize the GL with needed data. We add on the things * needed for textures * - load image data into generated glBuffers * - configure samplerObj in fragment shader * @param assetMgr android assetManager from java side */

Source from the content-addressed store, hash-verified

63 * @param assetMgr android assetManager from java side
64 */
65void ImageDecoderRender::Init(AAssetManager* assetMgr) {
66 // initialize the basic things from TeapotRenderer, no change
67 TeapotRenderer::Init();
68
69 GLint type = GetTextureType();
70 if (type == GL_INVALID_VALUE) {
71 // Plain teapot no texture
72 return;
73 }
74
75 // load texture coordinator for 2D texture. Cubemap texture uses world space
76 // normal to sample cubemap.
77 if (type == GL_TEXTURE_2D) {
78 // do Texture related initializations...
79 glGenBuffers(1, &texVbo_);
80 assert(texVbo_ != GL_INVALID_VALUE);
81
82 /*
83 * Loading Texture coord directly from data declared in model file
84 * teapot.inl
85 * which is 3 floats/vertex.
86 */
87 glBindBuffer(GL_ARRAY_BUFFER, texVbo_);
88
89#if (TILED_TEXTURE)
90 glBufferData(GL_ARRAY_BUFFER,
91 kCoordElementCount * sizeof(float) * num_vertices_,
92 teapotTexCoords, GL_STATIC_DRAW);
93#else
94 std::vector<float> coords;
95 for (int32_t idx = 0; idx < num_vertices_; idx++) {
96 coords.push_back(teapotTexCoords[3 * idx] / 2);
97 coords.push_back(teapotTexCoords[3 * idx + 1] / 2);
98 }
99 glBufferData(GL_ARRAY_BUFFER,
100 kCoordElementCount * sizeof(float) * num_vertices_,
101 coords.data(), GL_STATIC_DRAW);
102#endif
103 glVertexAttribPointer(ATTRIB_UV, 2, GL_FLOAT, GL_FALSE,
104 kCoordElementCount * sizeof(float), nullptr);
105 glEnableVertexAttribArray(ATTRIB_UV);
106
107 glBindBuffer(GL_ARRAY_BUFFER, 0);
108 }
109
110 // Need flip Y, so as top/bottom image
111 std::vector<std::string> textures{
112 std::string("Textures/right.png"), // GL_TEXTURE_CUBE_MAP_POSITIVE_X
113 std::string("Textures/left.png"), // GL_TEXTURE_CUBE_MAP_NEGATIVE_X
114 std::string("Textures/top.png"), // GL_TEXTURE_CUBE_MAP_POSITIVE_Y
115 std::string("Textures/bottom.png"), // GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
116 std::string("Textures/front.png"), // GL_TEXTURE_CUBE_MAP_POSITIVE_Z
117 std::string("Textures/back.png") // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
118 };
119
120 if (type == GL_TEXTURE_2D) {
121 textures[0] = std::string("Textures/front.png");
122 }

Callers

nothing calls this directly

Calls 4

dataMethod · 0.80
InitFunction · 0.50
GetActiveSamplerInfoMethod · 0.45
ActivateMethod · 0.45

Tested by

no test coverage detected