Skip to content

Instantly share code, notes, and snippets.

class DrawCall {
public:
DrawCall(Model* model, Mesh* mesh, GLenum mode)
: model_{model}, mesh_{mesh}, mode_{mode}
void draw()
{
if (!model->indices.empty()) {
glBindVertexArray(mesh->vao);
void line(int x0, int y0, int x1, int y1) {
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
for(;;){
setPixel(x0,y0);
if (x0==x1 && y0==y1) break;
e2 = err;
void LoadRes(
World *world,
std::string characterdir
) {
// Hair,Body.
constexpr std::size_t hairmesh_idx = 0, bodymesh_idx = 1;
world->meshes = std::make_unique<std::vector<MeshDesc>>(2);
ReadIndHairFile(characterdir + "/hair.ind", &world->meshes->at(hairmesh_idx), 10);
ReadObjFile(characterdir + "/body.obj", &world->meshes->at(bodymesh_idx), characterdir + "/bodytex.png");
glCreateTextures(GL_TEXTURE_2D, 1, &headptr_tex_);
glTextureStorage2D(headptr_tex_, 1, GL_R32UI, window_width, window_height);
glBindImageTexture(0, headptr_tex_, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI);
// glsl
layout(binding=0, r32ui) uniform uimage2D headptrs;
...
for (uint kthnode = imageLoad(headptrs, ivec2(gl_FragCoord.xy)).r;
kthnode != 0xffffffff;
kthnode = nodes[kthnode]) {