NoJobEngine
2.0.7
Toggle main menu visibility
Loading...
Searching...
No Matches
OpenGLRendererAPI.cpp
Go to the documentation of this file.
1
#include "
Engine/Platform/OpenGL/OpenGLRendererAPI.h
"
2
#include "
Engine/Renderer/VertexArray.h
"
3
#include "
Engine/Renderer/Buffer.h
"
4
#include <glad/gl.h>
5
6
namespace
NoJob
7
{
8
void
OpenGLRendererAPI::Init
()
9
{
10
glEnable(GL_DEPTH_TEST);
11
}
12
13
void
OpenGLRendererAPI::SetViewport
(
14
std::uint32_t x,
15
std::uint32_t y,
16
std::uint32_t width,
17
std::uint32_t height)
18
{
19
glViewport(
20
static_cast<
GLint
>
(x),
21
static_cast<
GLint
>
(y),
22
static_cast<
GLsizei
>
(width),
23
static_cast<
GLsizei
>
(height));
24
}
25
26
void
OpenGLRendererAPI::SetClearColor
(
27
float
r,
float
g,
float
b,
float
a)
28
{
29
glClearColor(r, g, b, a);
30
}
31
32
void
OpenGLRendererAPI::Clear
()
33
{
34
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
35
}
36
37
void
OpenGLRendererAPI::DrawIndexed
(
38
const
VertexArray
& vertexArray)
39
{
40
const
auto
& indexBuffer = vertexArray.
GetIndexBuffer
();
41
if
(!indexBuffer)
42
return
;
43
44
vertexArray.
Bind
();
45
46
glDrawElements(
47
GL_TRIANGLES,
48
static_cast<
GLsizei
>
(indexBuffer->GetCount()),
49
GL_UNSIGNED_INT,
50
nullptr
);
51
}
52
void
OpenGLRendererAPI::DrawIndexedRange
(
53
const
VertexArray
& vertexArray,
54
std::uint32_t indexCount,
55
std::uint32_t indexOffset)
56
{
57
if
(indexCount==0)
return
;
58
vertexArray.
Bind
();
59
glDrawElements(GL_TRIANGLES,
60
static_cast<
GLsizei
>
(indexCount),GL_UNSIGNED_INT,
61
reinterpret_cast<
const
void
*
>
(
62
static_cast<
std::uintptr_t
>
(indexOffset*
sizeof
(std::uint32_t))));
63
}
64
65
void
OpenGLRendererAPI::DrawLines
(
66
const
VertexArray
& vertexArray,
67
std::uint32_t vertexCount)
68
{
69
if
(vertexCount < 2)
70
{
71
return
;
72
}
73
74
vertexArray.
Bind
();
75
76
glDrawArrays(
77
GL_LINES,
78
0,
79
static_cast<
GLsizei
>
(vertexCount));
80
}
81
82
}
Buffer.h
Buffer declarations for the Rendering subsystem.
OpenGLRendererAPI.h
OpenGLRendererAPI declarations for the OpenGL Backend subsystem.
VertexArray.h
VertexArray declarations for the Rendering subsystem.
NoJob::OpenGLRendererAPI::DrawIndexedRange
void DrawIndexedRange(const VertexArray &vertexArray, std::uint32_t indexCount, std::uint32_t indexOffset) override
Definition
OpenGLRendererAPI.cpp:52
NoJob::OpenGLRendererAPI::SetClearColor
void SetClearColor(float r, float g, float b, float a) override
Definition
OpenGLRendererAPI.cpp:26
NoJob::OpenGLRendererAPI::Clear
void Clear() override
Definition
OpenGLRendererAPI.cpp:32
NoJob::OpenGLRendererAPI::DrawIndexed
void DrawIndexed(const VertexArray &vertexArray) override
Definition
OpenGLRendererAPI.cpp:37
NoJob::OpenGLRendererAPI::DrawLines
void DrawLines(const VertexArray &vertexArray, std::uint32_t vertexCount) override
Definition
OpenGLRendererAPI.cpp:65
NoJob::OpenGLRendererAPI::SetViewport
void SetViewport(std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height) override
Definition
OpenGLRendererAPI.cpp:13
NoJob::OpenGLRendererAPI::Init
void Init() override
Definition
OpenGLRendererAPI.cpp:8
NoJob::VertexArray
Definition
VertexArray.h:18
NoJob::VertexArray::Bind
virtual void Bind() const =0
NoJob::VertexArray::GetIndexBuffer
virtual const std::shared_ptr< IndexBuffer > & GetIndexBuffer() const =0
NoJob
Definition
BTActionNode.h:13
Engine
Platform
OpenGL
OpenGLRendererAPI.cpp
Generated by
1.18.0