-
Notifications
You must be signed in to change notification settings - Fork 4
/
xxGraphicGLES32.cpp
106 lines (91 loc) · 3.64 KB
/
xxGraphicGLES32.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
//==============================================================================
// xxGraphic : OpenGL ES 3.2 Source
//
// Copyright (c) 2019-2024 TAiGA
// https://github.com/metarutaiga/xxGraphic
//==============================================================================
#undef GL_ES_VERSION_2_0
#undef GL_ES_VERSION_3_0
#undef GL_ES_VERSION_3_1
#undef GL_ES_VERSION_3_2
#include "internal/xxGraphicInternalGL.h"
#include "xxGraphicGLES2.h"
#include "xxGraphicGLES3.h"
#include "xxGraphicGLES31.h"
#include "xxGraphicGLES32.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 xxCreateInstanceGLES32()
{
uint64_t instance = 0;
#if defined(xxANDROID)
instance = xxGraphicCreateEGL(320);
#endif
#if defined(xxMACOS)
instance = xxGraphicCreateCGL(320);
#endif
#if defined(xxIOS) && !defined(xxMACCATALYST)
instance = xxGraphicCreateEAGL(320);
#endif
#if defined(xxWINDOWS)
instance = xxGraphicCreateWGL(320);
#endif
if (instance == 0)
return 0;
xxRegisterFunction(GLES2);
xxCreateInstance = xxCreateInstanceGLES32;
xxGetInstanceName = xxGetInstanceNameGLES32;
xxCreateIndexBuffer = xxCreateIndexBufferGLES3;
xxCreateVertexBuffer = xxCreateVertexBufferGLES3;
xxMapBuffer = xxMapBufferGLES3;
xxUnmapBuffer = xxUnmapBufferGLES3;
xxSetVertexBuffers = xxSetVertexBuffersGLES32;
xxDraw = xxDrawGLES32;
xxDrawIndexed = xxDrawIndexedGLES32;
return instance;
}
//==============================================================================
// Command
//==============================================================================
void xxSetVertexBuffersGLES32(uint64_t commandEncoder, int count, const uint64_t* buffers, uint64_t vertexAttribute)
{
GLVERTEXATTRIBUTE* glVertexAttribute = reinterpret_cast<GLVERTEXATTRIBUTE*>(vertexAttribute);
GLVERTEXATTRIBUTE::Attribute* attributes = glVertexAttribute->attributes;
int currentStream = -1;
for (int i = 0; i < glVertexAttribute->count; ++i)
{
GLVERTEXATTRIBUTE::Attribute& attribute = attributes[i];
if (currentStream != attribute.stream)
{
currentStream = attribute.stream;
GLBUFFER* glBuffer = reinterpret_cast<GLBUFFER*>(buffers[attribute.stream]);
glBindBuffer(GL_ARRAY_BUFFER, glBuffer->buffer);
}
glVertexAttribPointer(attribute.index, attribute.size, attribute.type, attribute.normalized, attribute.stride, attribute.pointer);
}
}
//------------------------------------------------------------------------------
void xxDrawGLES32(uint64_t commandEncoder, int vertexCount, int instanceCount, int firstVertex, int firstInstance)
{
glDrawArraysInstanced(GL_TRIANGLES, firstVertex, vertexCount, instanceCount);
}
//------------------------------------------------------------------------------
void xxDrawIndexedGLES32(uint64_t commandEncoder, uint64_t indexBuffer, int indexCount, int instanceCount, int firstIndex, int vertexOffset, int firstInstance)
{
GLenum indexType = (INDEX_BUFFER_WIDTH == 2) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
glDrawElementsInstancedBaseVertex(GL_TRIANGLES, indexCount, indexType, (char*)nullptr + firstIndex * INDEX_BUFFER_WIDTH, instanceCount, vertexOffset);
}
//==============================================================================