Cogs.Core
CommonGLES30.h
1#pragma once
2
3#include "../BaseGL/GLFuncPointers.h"
4
5#ifdef __APPLE__
6#include <OpenGLES/ES2/gl.h>
7#endif
8
9#ifdef __native_client__
10#define nullptr NULL
11#endif
12
13#include <cassert>
14#include <atomic>
15
16#include "../Common.h"
17#include "../Base/ResourceMap.h"
18#include "../VertexFormat.h"
19#include "../Flags.h"
20
21#include <OsoMemoryProfiler/CogsMemoryProfile.h>
22
23#include "../BlendState.h"
24
25#include "Foundation/Logging/Logger.h"
26#include "Foundation/Memory/MemoryBuffer.h"
27
28namespace Cogs
29{
30 namespace OpenGLES30 {
31
32 // Typical WebGL limits
33 constexpr size_t maxTexUnits = 32;
34 constexpr size_t maxVertexAttributes = 32;
35 constexpr size_t maxUniformBuffers = 32;
36
37 enum struct BufferTarget : uint8_t
38 {
39 ArrayBuffer = 0,
40 ElementArrayBuffer,
41 UniformBuffer,
42 PixelPackBuffer,
43 CopyReadBuffer,
44 CopyWriteBuffer,
45 TransformFeedbackBuffer,
46 Count
47 };
48
49 const char* framebuffersStatusString(GLenum status);
50 }
51
53 {
54 const VertexFormat* formats[8] = {};
55 size_t numFormats = 0;
56 };
57
59 {
60 BufferGLES30() : mappedData(MemBlockType::MMapBackingStore) {}
61
63 union
64 {
65 GLenum indexType;
67 };
68 uint32_t size;
69 GLuint bufferId;
70 OpenGLES30::BufferTarget target;
71 uint32_t bindFlags = 0;
72 struct {
73 unsigned short keepMapBacking : 1;
74 unsigned short writeBackMap : 1;
75 unsigned short isMapped : 1;
76 unsigned short isIndexBuffer : 1;
77 };
78 };
79
81 {
82 GLuint glName = 0;
83 GLenum indexType = GL_INVALID_ENUM;
84 GLsizei indexCount = 0;
85 GLsizei indexStride = 0;
86 };
87
89 {
90 struct SemanticSlot {
91 uint8_t semantic;
92 uint8_t slot;
93 };
94 struct TextureSlot {
95 size_t nameHash;
96 };
98 size_t nameHash;
99 };
100
101 GLuint programId;
102 uint8_t activeAttributes = 0;
103 uint8_t activeTextureUnits = 0;
104 SemanticSlot attributeSemantic[OpenGLES30::maxVertexAttributes];
105 GLint attributeLocation[OpenGLES30::maxVertexAttributes];
106 TextureSlot textureSlots[OpenGLES30::maxTexUnits];
107 UniformBlockBinding uniformBlockBindings[OpenGLES30::maxUniformBuffers];
108
110 uint32_t readyAtFrame = 0;
111 };
112
114 {
115 struct {
116 BlendState::Blend colorSrc = BlendState::Blend::One;
117 BlendState::Blend colorDst = BlendState::Blend::Zero;
118 BlendState::Blend alphaSrc = BlendState::Blend::One;
119 BlendState::Blend alphaDst = BlendState::Blend::Zero;
120 } blend;
121 struct {
122 BlendState::BlendOperation color = BlendState::BlendOperation::Add;
123 BlendState::BlendOperation alpha = BlendState::BlendOperation::Add;
124 } operation;
125 uint8_t enabled : 1;
126 };
127}
128
129#if defined COGS_OPENGL20 || defined COGS_OPENGLES30
130extern const char* getErrorString(GLint errorCode);
131extern void logGLString(const char* name, GLenum key);
132extern void checkGLError(const char* operation);
133
134#ifdef COGS_WGL
135// Under WGL, we use GL_DEBUG_KHR for catching errors.
136#define CHECKED(x) x
137#else
138#ifdef _DEBUG
139#define CHECKED(x) x; checkGLError(#x);
140#else
141#define CHECKED(x) x
142#endif
143#endif
144#endif
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
@ OpenGLES30
Graphics device using the OpenGLES 3.0 API.
Blend
Options for blend functions.
Definition: BlendState.h:14
GLuint bufferId
OpenGL buffer name.
Definition: CommonGLES30.h:69
unsigned short isMapped
Buffer is currently mapped.
Definition: CommonGLES30.h:75
OpenGLES30::BufferTarget target
OpenGL bind target.
Definition: CommonGLES30.h:70
uint32_t bindFlags
Original Cogs::BindFlags bitmask used to create the buffer.
Definition: CommonGLES30.h:71
uint32_t size
Buffer size..
Definition: CommonGLES30.h:68
Memory::MemoryBuffer mappedData
Memory map backing store.
Definition: CommonGLES30.h:62
GLenum indexType
OpenGL index type if buffer is an index buffer.
Definition: CommonGLES30.h:65
unsigned short isIndexBuffer
Buffer is an index buffer.
Definition: CommonGLES30.h:76
const VertexFormat * vertexFormat
Vertex format if buffer is a vertex buffer.
Definition: CommonGLES30.h:66
unsigned short keepMapBacking
Do not release memory mapping backing store after unmap, set to 1 for repeatedly mapped buffers.
Definition: CommonGLES30.h:73
unsigned short writeBackMap
Set by map, if one, write back results to GL after unmap (i.e. map with write flags).
Definition: CommonGLES30.h:74
uint32_t readyAtFrame
Frame number at which the effect becomes ready, used to simulate asynchronous loading....
Definition: CommonGLES30.h:110
Vertex format structure used to describe a single vertex for the input assembler.
Definition: VertexFormat.h:60