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 struct {
72 unsigned short keepMapBacking : 1;
73 unsigned short writeBackMap : 1;
74 unsigned short isMapped : 1;
75 unsigned short isIndexBuffer : 1;
76 };
77 };
78
80 {
81 GLuint glName = 0;
82 GLenum indexType = GL_INVALID_ENUM;
83 GLsizei indexCount = 0;
84 GLsizei indexStride = 0;
85 };
86
88 {
89 struct SemanticSlot {
90 uint8_t semantic;
91 uint8_t slot;
92 };
93 struct TextureSlot {
94 size_t nameHash;
95 };
97 size_t nameHash;
98 };
99
100 GLuint programId;
101 uint8_t activeAttributes = 0;
102 uint8_t activeTextureUnits = 0;
103 SemanticSlot attributeSemantic[OpenGLES30::maxVertexAttributes];
104 GLint attributeLocation[OpenGLES30::maxVertexAttributes];
105 TextureSlot textureSlots[OpenGLES30::maxTexUnits];
106 UniformBlockBinding uniformBlockBindings[OpenGLES30::maxUniformBuffers];
107 };
108
110 {
111 struct {
112 BlendState::Blend colorSrc = BlendState::Blend::One;
113 BlendState::Blend colorDst = BlendState::Blend::Zero;
114 BlendState::Blend alphaSrc = BlendState::Blend::One;
115 BlendState::Blend alphaDst = BlendState::Blend::Zero;
116 } blend;
117 struct {
118 BlendState::BlendOperation color = BlendState::BlendOperation::Add;
119 BlendState::BlendOperation alpha = BlendState::BlendOperation::Add;
120 } operation;
121 uint8_t enabled : 1;
122 };
123}
124
125#if defined COGS_OPENGL20 || defined COGS_OPENGLES30
126extern const char* getErrorString(GLint errorCode);
127extern void logGLString(const char* name, GLenum key);
128extern void checkGLError(const char* operation);
129
130#ifdef COGS_WGL
131// Under WGL, we use GL_DEBUG_KHR for catching errors.
132#define CHECKED(x) x
133#else
134#ifdef _DEBUG
135#define CHECKED(x) x; checkGLError(#x);
136#else
137#define CHECKED(x) x
138#endif
139#endif
140#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:74
OpenGLES30::BufferTarget target
OpenGL bind target.
Definition: CommonGLES30.h:70
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:75
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:72
unsigned short writeBackMap
Set by map, if one, write back results to GL after unmap (i.e. map with write flags).
Definition: CommonGLES30.h:73
Vertex format structure used to describe a single vertex for the input assembler.
Definition: VertexFormat.h:60