-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVGL.cpp
45 lines (39 loc) · 1.23 KB
/
VGL.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
#include "VGL.hpp"
#include "VGLInternal.hpp"
#include "Rasterizer.hpp"
GLContext *gCurrentContext = nullptr;
GLContext *vglContextCreate(int w, int h) {
auto ctx = new GLContext();
vglContextResizeBuffers(ctx, w, h);
return ctx;
}
void vglContextDestroy(GLContext *ctx) {
if (gCurrentContext == ctx) {
vglContextMakeCurrent(nullptr);
}
delete ctx;
}
void vglContextMakeCurrent(GLContext *ctx) {
if (ctx) {
gCurrentContext = ctx;
gCurrentState = &ctx->state;
rsSetFramebuffer(ctx->bufferRect, ctx->colorBufferData.data(), ctx->depthBufferData.data());
}
else {
gCurrentContext = nullptr;
gCurrentState = nullptr;
rsSetFramebuffer(IntRect(0, 0, 0, 0), nullptr, nullptr);
}
}
void vglContextResizeBuffers(GLContext *ctx, int w, int h) {
auto size = ctx->bufferRect.getSize();
if (size.x != w || size.y != h) {
ctx->bufferRect.setSized(0, 0, w, h);
ctx->colorBufferData.resize(w*h);
ctx->depthBufferData.resize(w*h);
}
}
void vglContextGetColorBuffer(GLContext *ctx, void *&colorBuffer, int &pitch) {
colorBuffer = ctx->colorBufferData.data();
pitch = ctx->bufferRect.getSize().x*sizeof(ctx->colorBufferData[0]);
}