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

Method init

gles3jni/app/src/main/cpp/RendererES3.cpp:86–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86bool RendererES3::init() {
87 mProgram = createProgram(VERTEX_SHADER, FRAGMENT_SHADER);
88 if (!mProgram) return false;
89
90 glGenBuffers(VB_COUNT, mVB);
91 glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_INSTANCE]);
92 glBufferData(GL_ARRAY_BUFFER, sizeof(QUAD), &QUAD[0], GL_STATIC_DRAW);
93 glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_SCALEROT]);
94 glBufferData(GL_ARRAY_BUFFER, MAX_INSTANCES * 4 * sizeof(float), NULL,
95 GL_DYNAMIC_DRAW);
96 glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_OFFSET]);
97 glBufferData(GL_ARRAY_BUFFER, MAX_INSTANCES * 2 * sizeof(float), NULL,
98 GL_STATIC_DRAW);
99
100 glGenVertexArrays(1, &mVBState);
101 glBindVertexArray(mVBState);
102
103 glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_INSTANCE]);
104 glVertexAttribPointer(POS_ATTRIB, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
105 (const GLvoid*)offsetof(Vertex, pos));
106 glVertexAttribPointer(COLOR_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_TRUE,
107 sizeof(Vertex), (const GLvoid*)offsetof(Vertex, rgba));
108 glEnableVertexAttribArray(POS_ATTRIB);
109 glEnableVertexAttribArray(COLOR_ATTRIB);
110
111 glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_SCALEROT]);
112 glVertexAttribPointer(SCALEROT_ATTRIB, 4, GL_FLOAT, GL_FALSE,
113 4 * sizeof(float), 0);
114 glEnableVertexAttribArray(SCALEROT_ATTRIB);
115 glVertexAttribDivisor(SCALEROT_ATTRIB, 1);
116
117 glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_OFFSET]);
118 glVertexAttribPointer(OFFSET_ATTRIB, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),
119 0);
120 glEnableVertexAttribArray(OFFSET_ATTRIB);
121 glVertexAttribDivisor(OFFSET_ATTRIB, 1);
122
123 ALOGV("Using OpenGL ES 3.0 renderer");
124 return true;
125}
126
127RendererES3::~RendererES3() {
128 /* The destructor may be called after the context has already been

Callers 1

createES3RendererFunction · 0.45

Calls 1

createProgramFunction · 0.70

Tested by

no test coverage detected