-
Notifications
You must be signed in to change notification settings - Fork 0
/
Draw.cpp
50 lines (43 loc) · 1.61 KB
/
Draw.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "Draw.h"
#include "./include/glad.h"
#include <iostream>
static GLenum DrawModeToGLEnum(DrawMode input) {
switch (input) {
case DrawMode::Points: return GL_POINTS;
break;
case DrawMode::LineStrip: return GL_LINE_STRIP;
break;
case DrawMode::LineLoop: return GL_LINE_LOOP;
break;
case DrawMode::Lines: return GL_LINES;
break;
case DrawMode::Triangles: return GL_TRIANGLES;
break;
case DrawMode::TriangleStrip: return GL_TRIANGLE_STRIP;
break;
case DrawMode::TriangleFan: return GL_TRIANGLE_FAN;
break;
}
std::cout << "DrawModeToGLEnum unreachable code hint \n";
return 0;
}
void Draw(IndexBuffer& inIndexBuffer, DrawMode mode) {
unsigned int handle = inIndexBuffer.GetHandle();
unsigned int numIndices = inIndexBuffer.Count();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle);
glDrawElements(DrawModeToGLEnum(mode), numIndices, GL_UNSIGNED_INT, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void Draw(unsigned int vertexCount, DrawMode mode) {
glDrawArrays(DrawModeToGLEnum(mode), 0, vertexCount);
}
void DrawInstanced(IndexBuffer& inIndexBuffer, DrawMode mode, unsigned int instanceCount) {
unsigned int handle = inIndexBuffer.GetHandle();
unsigned int numIndices = inIndexBuffer.Count();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle);
glDrawElementsInstanced(DrawModeToGLEnum(mode), numIndices, GL_UNSIGNED_INT, 0, instanceCount);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void DrawInstanced(unsigned int vertexCount, DrawMode mode, unsigned int numInstances) {
glDrawArraysInstanced(DrawModeToGLEnum(mode), 0, vertexCount, numInstances);
}