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

Function DrawPatchModel

Source/Objects/terrainobject.cpp:64–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62extern bool g_debug_runtime_disable_terrain_object_pre_draw_camera;
63
64static void DrawPatchModel(Model& model, Graphics* graphics, Shaders* shaders, int shader, bool use_tesselation) {
65 PROFILER_GPU_ZONE(g_profiler_ctx, "DrawPatchModel");
66 if (!model.vbo_loaded) {
67 PROFILER_ZONE(g_profiler_ctx, "createVBO");
68 model.createVBO();
69 }
70 model.VBO_faces.Bind();
71 int attrib_ids[4];
72 for (int i = 0; i < 4; ++i) {
73 const char* attrib_str;
74 int num_el;
75 VBOContainer* vbo;
76 switch (i) {
77 case 0:
78 attrib_str = "vertex_attrib";
79 num_el = 3;
80 vbo = &model.VBO_vertices;
81 break;
82 case 1:
83 attrib_str = "tangent_attrib";
84 num_el = 3;
85 vbo = &model.VBO_tangents;
86 break;
87 case 2:
88 attrib_str = "tex_coord_attrib";
89 num_el = 2;
90 vbo = &model.VBO_tex_coords;
91 break;
92 case 3:
93 attrib_str = "detail_tex_coord";
94 num_el = 2;
95 vbo = &model.VBO_tex_coords2;
96 break;
97 default:
98 __builtin_unreachable();
99 break;
100 }
101 CHECK_GL_ERROR();
102 vbo->Bind();
103 CHECK_GL_ERROR();
104 attrib_ids[i] = shaders->returnShaderAttrib(attrib_str, shader);
105 if (attrib_ids[i] != -1) {
106 CHECK_GL_ERROR();
107 graphics->EnableVertexAttribArray(attrib_ids[i]);
108 CHECK_GL_ERROR();
109 glVertexAttribPointer(attrib_ids[i], num_el, GL_FLOAT, false, num_el * sizeof(GLfloat), 0);
110 CHECK_GL_ERROR();
111 }
112 }
113 CHECK_GL_ERROR();
114 graphics->DrawElements(use_tesselation ? GL_PATCHES : GL_TRIANGLES, (unsigned int)model.faces.size(), GL_UNSIGNED_INT, 0);
115 CHECK_GL_ERROR();
116 graphics->ResetVertexAttribArrays();
117 CHECK_GL_ERROR();
118 graphics->BindArrayVBO(0);
119 graphics->BindElementVBO(0);
120}
121

Callers 1

DrawTerrainMethod · 0.85

Calls 9

createVBOMethod · 0.80
returnShaderAttribMethod · 0.80
BindArrayVBOMethod · 0.80
BindElementVBOMethod · 0.80
BindMethod · 0.45
DrawElementsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected