-
Notifications
You must be signed in to change notification settings - Fork 4
/
xxGraphicGLES3.cpp
134 lines (113 loc) · 3.9 KB
/
xxGraphicGLES3.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//==============================================================================
// xxGraphic : OpenGL ES 3.0 Source
//
// Copyright (c) 2019-2024 TAiGA
// https://github.com/metarutaiga/xxGraphic
//==============================================================================
#undef GL_ES_VERSION_2_0
#undef GL_ES_VERSION_3_0
#define GL_ES_VERSION_3_1 0
#define GL_ES_VERSION_3_2 0
#include "internal/xxGraphicInternalGL.h"
#include "xxGraphicGLES2.h"
#include "xxGraphicGLES3.h"
#if defined(xxANDROID)
# include "xxGraphicEGL.h"
#endif
#if defined(xxIOS) && !defined(xxMACCATALYST)
# include "xxGraphicEAGL.h"
#endif
#if defined(xxMACOS)
# include "xxGraphicCGL.h"
#endif
#if defined(xxWINDOWS)
# include "xxGraphicWGL.h"
#endif
//==============================================================================
// Instance
//==============================================================================
uint64_t xxCreateInstanceGLES3()
{
uint64_t instance = 0;
#if defined(xxANDROID)
instance = xxGraphicCreateEGL(300);
#endif
#if defined(xxMACOS)
instance = xxGraphicCreateCGL(300);
#endif
#if defined(xxIOS) && !defined(xxMACCATALYST)
instance = xxGraphicCreateEAGL(300);
#endif
#if defined(xxWINDOWS)
instance = xxGraphicCreateWGL(300);
#endif
if (instance == 0)
return 0;
xxRegisterFunction(GLES2);
xxCreateInstance = xxCreateInstanceGLES3;
xxGetInstanceName = xxGetInstanceNameGLES3;
xxCreateIndexBuffer = xxCreateIndexBufferGLES3;
xxCreateVertexBuffer = xxCreateVertexBufferGLES3;
xxMapBuffer = xxMapBufferGLES3;
xxUnmapBuffer = xxUnmapBufferGLES3;
return instance;
}
//==============================================================================
// Buffer
//==============================================================================
uint64_t xxCreateIndexBufferGLES3(uint64_t device, int size)
{
GLBUFFER* glBuffer = xxAlloc(GLBUFFER);
if (glBuffer == nullptr)
return 0;
GLuint buffer = 0;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, nullptr, GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBuffer->type = GL_ELEMENT_ARRAY_BUFFER;
glBuffer->buffer = buffer;
glBuffer->memory = nullptr;
glBuffer->size = size;
return reinterpret_cast<uint64_t>(glBuffer);
}
//------------------------------------------------------------------------------
uint64_t xxCreateVertexBufferGLES3(uint64_t device, int size, uint64_t vertexAttribute)
{
GLBUFFER* glBuffer = xxAlloc(GLBUFFER);
if (glBuffer == nullptr)
return 0;
GLuint buffer = 0;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBuffer->type = GL_ARRAY_BUFFER;
glBuffer->buffer = buffer;
glBuffer->memory = nullptr;
glBuffer->size = size;
return reinterpret_cast<uint64_t>(glBuffer);
}
//------------------------------------------------------------------------------
void* xxMapBufferGLES3(uint64_t device, uint64_t buffer)
{
GLBUFFER* glBuffer = reinterpret_cast<GLBUFFER*>(buffer);
if (glBuffer == nullptr)
return nullptr;
if (glBuffer->memory)
return glBuffer->memory;
glBindBuffer(glBuffer->type, glBuffer->buffer);
return glMapBufferRange(glBuffer->type, 0, glBuffer->size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
}
//------------------------------------------------------------------------------
void xxUnmapBufferGLES3(uint64_t device, uint64_t buffer)
{
GLBUFFER* glBuffer = reinterpret_cast<GLBUFFER*>(buffer);
if (glBuffer == nullptr)
return;
if (glBuffer->memory)
return;
glBindBuffer(glBuffer->type, glBuffer->buffer);
glUnmapBuffer(glBuffer->type);
}
//==============================================================================