-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDraw.cpp
More file actions
56 lines (48 loc) · 1.6 KB
/
Draw.cpp
File metadata and controls
56 lines (48 loc) · 1.6 KB
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
51
52
53
54
55
56
#include "Draw.h"
#include "glad.h"
#include <iostream>
static GLenum DrawModeToGLEnum(DrawMode input) {
if (input == DrawMode::Points) {
return GL_POINTS;
}
else if (input == DrawMode::LineStrip) {
return GL_LINE_STRIP;
}
else if (input == DrawMode::LineLoop) {
return GL_LINE_LOOP;
}
else if (input == DrawMode::Lines) {
return GL_LINES;
}
else if (input == DrawMode::Triangles) {
return GL_TRIANGLES;
}
else if (input == DrawMode::TriangleStrip) {
return GL_TRIANGLE_STRIP;
}
else if (input == DrawMode::TriangleFan) {
return GL_TRIANGLE_FAN;
}
std::cout << "DrawModeToGLEnum unreachable code hit\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);
}