MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / DrawHistogram

Function DrawHistogram

Source/Main/engine.cpp:2420–2466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2418}
2419
2420static void DrawHistogram() {
2421 Shaders* shaders = Shaders::Instance();
2422 Textures* textures = Textures::Instance();
2423 Graphics* graphics = Graphics::Instance();
2424
2425 static int shader_id = -1;
2426 static VBOContainer vbo;
2427 if (shader_id == -1) {
2428 shader_id = shaders->returnProgram("histogram_draw");
2429 CHECK_GL_ERROR();
2430 std::vector<GLfloat> data;
2431 data.resize(kHistogramBuckets * 4);
2432 for (int i = 0, index = 0; i < kHistogramBuckets; ++i) {
2433 data[index + 0] = (float)i;
2434 data[index + 1] = 0.0f;
2435 data[index + 2] = (float)i;
2436 data[index + 3] = 1.0f;
2437 index += 4;
2438 }
2439 vbo.Fill(kVBOFloat | kVBOStatic, data.size() * sizeof(GLfloat), &data[0]);
2440 CHECK_GL_ERROR();
2441 }
2442
2443 GLState gl_state;
2444 gl_state.blend = true;
2445 gl_state.depth_test = false;
2446 gl_state.depth_write = false;
2447 gl_state.cull_face = false;
2448 graphics->setGLState(gl_state);
2449 shaders->setProgram(shader_id);
2450 int vert_attrib_id = shaders->returnShaderAttrib("lines", shader_id);
2451 int uniform_mvp_id = shaders->returnShaderVariable("mvp", shader_id);
2452 int uniform_buckets_id = shaders->returnShaderVariable("num_buckets", shader_id);
2453 glm::mat4 proj_mat;
2454 proj_mat = glm::ortho(0.0f, (float)graphics->viewport_dim[2], 0.0f, (float)graphics->viewport_dim[3]);
2455 glm::mat4 mvp_mat = proj_mat;
2456 shaders->SetUniformInt(uniform_buckets_id, kHistogramBuckets);
2457 shaders->SetUniformMat4(uniform_mvp_id, (const GLfloat*)&mvp_mat);
2458 textures->bindTexture(histogram_tex);
2459 graphics->EnableVertexAttribArray(vert_attrib_id);
2460 vbo.Bind();
2461 glVertexAttribPointer(vert_attrib_id, 2, GL_FLOAT, false, 2 * sizeof(GLfloat), 0);
2462 glLineWidth(1);
2463 graphics->DrawArrays(GL_LINES, 0, kHistogramBuckets * 2);
2464 graphics->ResetVertexAttribArrays();
2465 graphics->BindArrayVBO(0);
2466}
2467
2468static void DrawQuad(int shader_id) {
2469 PROFILER_GPU_ZONE(g_profiler_ctx, "Engine.cpp DrawQuad");

Callers 1

DrawMethod · 0.85

Calls 15

returnProgramMethod · 0.80
setGLStateMethod · 0.80
setProgramMethod · 0.80
returnShaderAttribMethod · 0.80
returnShaderVariableMethod · 0.80
SetUniformIntMethod · 0.80
SetUniformMat4Method · 0.80
bindTextureMethod · 0.80
DrawArraysMethod · 0.80
BindArrayVBOMethod · 0.80

Tested by

no test coverage detected