Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // RendererGL.cpp: Implements the class methods for RendererGL. |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/RendererGL.h" |
| 10 | |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 11 | #include <EGL/eglext.h> |
| 12 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 13 | #include "common/debug.h" |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 14 | #include "libANGLE/AttributeMap.h" |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 15 | #include "libANGLE/ContextState.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 16 | #include "libANGLE/Path.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 17 | #include "libANGLE/Surface.h" |
Geoff Lang | 53b8aec | 2015-08-24 10:33:25 -0400 | [diff] [blame] | 18 | #include "libANGLE/renderer/gl/BlitGL.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 19 | #include "libANGLE/renderer/gl/BufferGL.h" |
| 20 | #include "libANGLE/renderer/gl/CompilerGL.h" |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 21 | #include "libANGLE/renderer/gl/ContextGL.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 22 | #include "libANGLE/renderer/gl/FenceNVGL.h" |
| 23 | #include "libANGLE/renderer/gl/FenceSyncGL.h" |
| 24 | #include "libANGLE/renderer/gl/FramebufferGL.h" |
Geoff Lang | 56cf9af | 2015-02-17 10:16:49 -0500 | [diff] [blame] | 25 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 26 | #include "libANGLE/renderer/gl/PathGL.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 27 | #include "libANGLE/renderer/gl/ProgramGL.h" |
| 28 | #include "libANGLE/renderer/gl/QueryGL.h" |
| 29 | #include "libANGLE/renderer/gl/RenderbufferGL.h" |
Geoff Lang | 0af0b81 | 2015-09-23 13:56:25 -0400 | [diff] [blame] | 30 | #include "libANGLE/renderer/gl/SamplerGL.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 31 | #include "libANGLE/renderer/gl/ShaderGL.h" |
Geoff Lang | 94463d5 | 2015-02-18 13:09:37 -0500 | [diff] [blame] | 32 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 33 | #include "libANGLE/renderer/gl/SurfaceGL.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 34 | #include "libANGLE/renderer/gl/TextureGL.h" |
| 35 | #include "libANGLE/renderer/gl/TransformFeedbackGL.h" |
| 36 | #include "libANGLE/renderer/gl/VertexArrayGL.h" |
Geoff Lang | ddc7446 | 2015-02-25 11:48:09 -0500 | [diff] [blame] | 37 | #include "libANGLE/renderer/gl/renderergl_utils.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 38 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 39 | namespace |
| 40 | { |
| 41 | |
| 42 | std::vector<GLuint> GatherPaths(const std::vector<gl::Path *> &paths) |
| 43 | { |
| 44 | std::vector<GLuint> ret; |
| 45 | ret.reserve(paths.size()); |
| 46 | |
| 47 | for (const auto *p : paths) |
| 48 | { |
| 49 | const auto *pathObj = rx::GetImplAs<rx::PathGL>(p); |
| 50 | ret.push_back(pathObj->getPathID()); |
| 51 | } |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | } // namespace |
| 56 | |
Geoff Lang | b80360f | 2015-05-04 15:01:31 -0400 | [diff] [blame] | 57 | #ifndef NDEBUG |
| 58 | static void INTERNAL_GL_APIENTRY LogGLDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, |
| 59 | const GLchar *message, const void *userParam) |
| 60 | { |
| 61 | std::string sourceText; |
| 62 | switch (source) |
| 63 | { |
| 64 | case GL_DEBUG_SOURCE_API: sourceText = "OpenGL"; break; |
| 65 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: sourceText = "Windows"; break; |
| 66 | case GL_DEBUG_SOURCE_SHADER_COMPILER: sourceText = "Shader Compiler"; break; |
| 67 | case GL_DEBUG_SOURCE_THIRD_PARTY: sourceText = "Third Party"; break; |
| 68 | case GL_DEBUG_SOURCE_APPLICATION: sourceText = "Application"; break; |
| 69 | case GL_DEBUG_SOURCE_OTHER: sourceText = "Other"; break; |
| 70 | default: sourceText = "UNKNOWN"; break; |
| 71 | } |
| 72 | |
| 73 | std::string typeText; |
| 74 | switch (type) |
| 75 | { |
| 76 | case GL_DEBUG_TYPE_ERROR: typeText = "Error"; break; |
| 77 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: typeText = "Deprecated behavior"; break; |
| 78 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: typeText = "Undefined behavior"; break; |
| 79 | case GL_DEBUG_TYPE_PORTABILITY: typeText = "Portability"; break; |
| 80 | case GL_DEBUG_TYPE_PERFORMANCE: typeText = "Performance"; break; |
| 81 | case GL_DEBUG_TYPE_OTHER: typeText = "Other"; break; |
| 82 | case GL_DEBUG_TYPE_MARKER: typeText = "Marker"; break; |
| 83 | default: typeText = "UNKNOWN"; break; |
| 84 | } |
| 85 | |
| 86 | std::string severityText; |
| 87 | switch (severity) |
| 88 | { |
| 89 | case GL_DEBUG_SEVERITY_HIGH: severityText = "High"; break; |
| 90 | case GL_DEBUG_SEVERITY_MEDIUM: severityText = "Medium"; break; |
| 91 | case GL_DEBUG_SEVERITY_LOW: severityText = "Low"; break; |
| 92 | case GL_DEBUG_SEVERITY_NOTIFICATION: severityText = "Notification"; break; |
| 93 | default: severityText = "UNKNOWN"; break; |
| 94 | } |
| 95 | |
| 96 | ERR("\n\tSource: %s\n\tType: %s\n\tID: %d\n\tSeverity: %s\n\tMessage: %s", sourceText.c_str(), typeText.c_str(), id, |
| 97 | severityText.c_str(), message); |
| 98 | } |
| 99 | #endif |
| 100 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 101 | namespace rx |
| 102 | { |
| 103 | |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 104 | RendererGL::RendererGL(const FunctionsGL *functions, const egl::AttributeMap &attribMap) |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 105 | : mMaxSupportedESVersion(0, 0), |
Geoff Lang | 94463d5 | 2015-02-18 13:09:37 -0500 | [diff] [blame] | 106 | mFunctions(functions), |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 107 | mStateManager(nullptr), |
Geoff Lang | 53b8aec | 2015-08-24 10:33:25 -0400 | [diff] [blame] | 108 | mBlitter(nullptr), |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 109 | mHasDebugOutput(false), |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 110 | mSkipDrawCalls(false), |
| 111 | mCapsInitialized(false) |
Geoff Lang | 56cf9af | 2015-02-17 10:16:49 -0500 | [diff] [blame] | 112 | { |
| 113 | ASSERT(mFunctions); |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 114 | mStateManager = new StateManagerGL(mFunctions, getNativeCaps()); |
Geoff Lang | cab7e1d | 2015-07-27 11:20:41 -0400 | [diff] [blame] | 115 | nativegl_gl::GenerateWorkarounds(mFunctions, &mWorkarounds); |
Geoff Lang | 53b8aec | 2015-08-24 10:33:25 -0400 | [diff] [blame] | 116 | mBlitter = new BlitGL(functions, mWorkarounds, mStateManager); |
Geoff Lang | b80360f | 2015-05-04 15:01:31 -0400 | [diff] [blame] | 117 | |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 118 | mHasDebugOutput = mFunctions->isAtLeastGL(gl::Version(4, 3)) || |
| 119 | mFunctions->hasGLExtension("GL_KHR_debug") || |
| 120 | mFunctions->isAtLeastGLES(gl::Version(3, 2)) || |
| 121 | mFunctions->hasGLESExtension("GL_KHR_debug"); |
Geoff Lang | b80360f | 2015-05-04 15:01:31 -0400 | [diff] [blame] | 122 | #ifndef NDEBUG |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 123 | if (mHasDebugOutput) |
Geoff Lang | b80360f | 2015-05-04 15:01:31 -0400 | [diff] [blame] | 124 | { |
Corentin Wallez | 930fefc | 2016-09-14 15:54:18 -0400 | [diff] [blame^] | 125 | mFunctions->enable(GL_DEBUG_OUTPUT); |
Geoff Lang | b80360f | 2015-05-04 15:01:31 -0400 | [diff] [blame] | 126 | mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS); |
| 127 | mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr, GL_TRUE); |
| 128 | mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr, GL_TRUE); |
| 129 | mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, nullptr, GL_FALSE); |
| 130 | mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, nullptr, GL_FALSE); |
| 131 | mFunctions->debugMessageCallback(&LogGLDebugMessage, nullptr); |
| 132 | } |
| 133 | #endif |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 134 | |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 135 | EGLint deviceType = |
| 136 | static_cast<EGLint>(attribMap.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_NONE)); |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 137 | if (deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE) |
| 138 | { |
| 139 | mSkipDrawCalls = true; |
| 140 | } |
Corentin Wallez | 8314465 | 2016-08-31 17:03:30 -0400 | [diff] [blame] | 141 | |
| 142 | if (mWorkarounds.initializeCurrentVertexAttributes) |
| 143 | { |
| 144 | GLint maxVertexAttribs = 0; |
| 145 | mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); |
| 146 | |
| 147 | for (GLint i = 0; i < maxVertexAttribs; ++i) |
| 148 | { |
| 149 | mFunctions->vertexAttrib4f(i, 0.0f, 0.0f, 0.0f, 1.0f); |
| 150 | } |
| 151 | } |
Geoff Lang | 56cf9af | 2015-02-17 10:16:49 -0500 | [diff] [blame] | 152 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 153 | |
| 154 | RendererGL::~RendererGL() |
Geoff Lang | 94463d5 | 2015-02-18 13:09:37 -0500 | [diff] [blame] | 155 | { |
Geoff Lang | 53b8aec | 2015-08-24 10:33:25 -0400 | [diff] [blame] | 156 | SafeDelete(mBlitter); |
Geoff Lang | bf8a72f | 2015-11-03 16:34:45 -0500 | [diff] [blame] | 157 | SafeDelete(mStateManager); |
Geoff Lang | 94463d5 | 2015-02-18 13:09:37 -0500 | [diff] [blame] | 158 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 159 | |
| 160 | gl::Error RendererGL::flush() |
| 161 | { |
Geoff Lang | 2c91914 | 2015-04-01 14:44:13 -0400 | [diff] [blame] | 162 | mFunctions->flush(); |
| 163 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | gl::Error RendererGL::finish() |
| 167 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 168 | #ifdef NDEBUG |
| 169 | if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mHasDebugOutput) |
| 170 | { |
| 171 | mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS); |
| 172 | } |
| 173 | #endif |
| 174 | |
Geoff Lang | 2c91914 | 2015-04-01 14:44:13 -0400 | [diff] [blame] | 175 | mFunctions->finish(); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 176 | |
| 177 | #ifdef NDEBUG |
| 178 | if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mHasDebugOutput) |
| 179 | { |
| 180 | mFunctions->disable(GL_DEBUG_OUTPUT_SYNCHRONOUS); |
| 181 | } |
| 182 | #endif |
| 183 | |
Geoff Lang | 2c91914 | 2015-04-01 14:44:13 -0400 | [diff] [blame] | 184 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 185 | } |
| 186 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 187 | gl::Error RendererGL::drawArrays(const gl::ContextState &data, |
| 188 | GLenum mode, |
| 189 | GLint first, |
| 190 | GLsizei count) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 191 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 192 | ANGLE_TRY(mStateManager->setDrawArraysState(data, first, count, 0)); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 193 | |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 194 | if (!mSkipDrawCalls) |
| 195 | { |
| 196 | mFunctions->drawArrays(mode, first, count); |
| 197 | } |
Geoff Lang | d6e5087 | 2015-02-24 12:42:26 -0500 | [diff] [blame] | 198 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 199 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 200 | } |
| 201 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 202 | gl::Error RendererGL::drawArraysInstanced(const gl::ContextState &data, |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 203 | GLenum mode, |
| 204 | GLint first, |
| 205 | GLsizei count, |
| 206 | GLsizei instanceCount) |
| 207 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 208 | ANGLE_TRY(mStateManager->setDrawArraysState(data, first, count, instanceCount)); |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 209 | |
| 210 | if (!mSkipDrawCalls) |
| 211 | { |
| 212 | mFunctions->drawArraysInstanced(mode, first, count, instanceCount); |
| 213 | } |
| 214 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 215 | return gl::NoError(); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 216 | } |
| 217 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 218 | gl::Error RendererGL::drawElements(const gl::ContextState &data, |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 219 | GLenum mode, |
| 220 | GLsizei count, |
| 221 | GLenum type, |
| 222 | const GLvoid *indices, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 223 | const gl::IndexRange &indexRange) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 224 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 225 | const GLvoid *drawIndexPtr = nullptr; |
| 226 | ANGLE_TRY(mStateManager->setDrawElementsState(data, count, type, indices, 0, &drawIndexPtr)); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 227 | |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 228 | if (!mSkipDrawCalls) |
| 229 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 230 | mFunctions->drawElements(mode, count, type, drawIndexPtr); |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 231 | } |
Geoff Lang | d6e5087 | 2015-02-24 12:42:26 -0500 | [diff] [blame] | 232 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 233 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 234 | } |
| 235 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 236 | gl::Error RendererGL::drawElementsInstanced(const gl::ContextState &data, |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 237 | GLenum mode, |
| 238 | GLsizei count, |
| 239 | GLenum type, |
| 240 | const GLvoid *indices, |
| 241 | GLsizei instances, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 242 | const gl::IndexRange &indexRange) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 243 | { |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 244 | const GLvoid *drawIndexPointer = nullptr; |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 245 | ANGLE_TRY(mStateManager->setDrawElementsState(data, count, type, indices, instances, |
| 246 | &drawIndexPointer)); |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 247 | |
| 248 | if (!mSkipDrawCalls) |
| 249 | { |
| 250 | mFunctions->drawElementsInstanced(mode, count, type, drawIndexPointer, instances); |
| 251 | } |
| 252 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 253 | return gl::NoError(); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 256 | gl::Error RendererGL::drawRangeElements(const gl::ContextState &data, |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 257 | GLenum mode, |
| 258 | GLuint start, |
| 259 | GLuint end, |
| 260 | GLsizei count, |
| 261 | GLenum type, |
| 262 | const GLvoid *indices, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 263 | const gl::IndexRange &indexRange) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 264 | { |
Geoff Lang | 4750223 | 2015-08-25 16:26:10 -0400 | [diff] [blame] | 265 | const GLvoid *drawIndexPointer = nullptr; |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 266 | ANGLE_TRY( |
| 267 | mStateManager->setDrawElementsState(data, count, type, indices, 0, &drawIndexPointer)); |
Geoff Lang | 4750223 | 2015-08-25 16:26:10 -0400 | [diff] [blame] | 268 | |
| 269 | if (!mSkipDrawCalls) |
| 270 | { |
| 271 | mFunctions->drawRangeElements(mode, start, end, count, type, drawIndexPointer); |
| 272 | } |
| 273 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 274 | return gl::Error(GL_NO_ERROR); |
| 275 | } |
| 276 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 277 | void RendererGL::stencilFillPath(const gl::ContextState &state, |
| 278 | const gl::Path *path, |
| 279 | GLenum fillMode, |
| 280 | GLuint mask) |
| 281 | { |
| 282 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 283 | |
| 284 | mFunctions->stencilFillPathNV(pathObj->getPathID(), fillMode, mask); |
| 285 | |
| 286 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 287 | } |
| 288 | |
| 289 | void RendererGL::stencilStrokePath(const gl::ContextState &state, |
| 290 | const gl::Path *path, |
| 291 | GLint reference, |
| 292 | GLuint mask) |
| 293 | { |
| 294 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 295 | |
| 296 | mFunctions->stencilStrokePathNV(pathObj->getPathID(), reference, mask); |
| 297 | |
| 298 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 299 | } |
| 300 | |
| 301 | void RendererGL::coverFillPath(const gl::ContextState &state, |
| 302 | const gl::Path *path, |
| 303 | GLenum coverMode) |
| 304 | { |
| 305 | |
| 306 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 307 | mFunctions->coverFillPathNV(pathObj->getPathID(), coverMode); |
| 308 | |
| 309 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 310 | } |
| 311 | |
| 312 | void RendererGL::coverStrokePath(const gl::ContextState &state, |
| 313 | const gl::Path *path, |
| 314 | GLenum coverMode) |
| 315 | { |
| 316 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 317 | mFunctions->coverStrokePathNV(pathObj->getPathID(), coverMode); |
| 318 | |
| 319 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 320 | } |
| 321 | |
| 322 | void RendererGL::stencilThenCoverFillPath(const gl::ContextState &state, |
| 323 | const gl::Path *path, |
| 324 | GLenum fillMode, |
| 325 | GLuint mask, |
| 326 | GLenum coverMode) |
| 327 | { |
| 328 | |
| 329 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 330 | mFunctions->stencilThenCoverFillPathNV(pathObj->getPathID(), fillMode, mask, coverMode); |
| 331 | |
| 332 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 333 | } |
| 334 | |
| 335 | void RendererGL::stencilThenCoverStrokePath(const gl::ContextState &state, |
| 336 | const gl::Path *path, |
| 337 | GLint reference, |
| 338 | GLuint mask, |
| 339 | GLenum coverMode) |
| 340 | { |
| 341 | |
| 342 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 343 | mFunctions->stencilThenCoverStrokePathNV(pathObj->getPathID(), reference, mask, coverMode); |
| 344 | |
| 345 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 346 | } |
| 347 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 348 | void RendererGL::coverFillPathInstanced(const gl::ContextState &state, |
| 349 | const std::vector<gl::Path *> &paths, |
| 350 | GLenum coverMode, |
| 351 | GLenum transformType, |
| 352 | const GLfloat *transformValues) |
| 353 | { |
| 354 | const auto &pathObjs = GatherPaths(paths); |
| 355 | |
| 356 | mFunctions->coverFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, |
| 357 | &pathObjs[0], 0, coverMode, transformType, |
| 358 | transformValues); |
| 359 | |
| 360 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 361 | } |
| 362 | void RendererGL::coverStrokePathInstanced(const gl::ContextState &state, |
| 363 | const std::vector<gl::Path *> &paths, |
| 364 | GLenum coverMode, |
| 365 | GLenum transformType, |
| 366 | const GLfloat *transformValues) |
| 367 | { |
| 368 | const auto &pathObjs = GatherPaths(paths); |
| 369 | |
| 370 | mFunctions->coverStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, |
| 371 | &pathObjs[0], 0, coverMode, transformType, |
| 372 | transformValues); |
| 373 | |
| 374 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 375 | } |
| 376 | void RendererGL::stencilFillPathInstanced(const gl::ContextState &state, |
| 377 | const std::vector<gl::Path *> &paths, |
| 378 | GLenum fillMode, |
| 379 | GLuint mask, |
| 380 | GLenum transformType, |
| 381 | const GLfloat *transformValues) |
| 382 | { |
| 383 | const auto &pathObjs = GatherPaths(paths); |
| 384 | |
| 385 | mFunctions->stencilFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, |
| 386 | &pathObjs[0], 0, fillMode, mask, transformType, |
| 387 | transformValues); |
| 388 | |
| 389 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 390 | } |
| 391 | void RendererGL::stencilStrokePathInstanced(const gl::ContextState &state, |
| 392 | const std::vector<gl::Path *> &paths, |
| 393 | GLint reference, |
| 394 | GLuint mask, |
| 395 | GLenum transformType, |
| 396 | const GLfloat *transformValues) |
| 397 | { |
| 398 | const auto &pathObjs = GatherPaths(paths); |
| 399 | |
| 400 | mFunctions->stencilStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, |
| 401 | &pathObjs[0], 0, reference, mask, transformType, |
| 402 | transformValues); |
| 403 | |
| 404 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 405 | } |
| 406 | |
| 407 | void RendererGL::stencilThenCoverFillPathInstanced(const gl::ContextState &state, |
| 408 | const std::vector<gl::Path *> &paths, |
| 409 | GLenum coverMode, |
| 410 | GLenum fillMode, |
| 411 | GLuint mask, |
| 412 | GLenum transformType, |
| 413 | const GLfloat *transformValues) |
| 414 | { |
| 415 | const auto &pathObjs = GatherPaths(paths); |
| 416 | |
| 417 | mFunctions->stencilThenCoverFillPathInstancedNV( |
| 418 | static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, fillMode, mask, |
| 419 | coverMode, transformType, transformValues); |
| 420 | |
| 421 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 422 | } |
| 423 | void RendererGL::stencilThenCoverStrokePathInstanced(const gl::ContextState &state, |
| 424 | const std::vector<gl::Path *> &paths, |
| 425 | GLenum coverMode, |
| 426 | GLint reference, |
| 427 | GLuint mask, |
| 428 | GLenum transformType, |
| 429 | const GLfloat *transformValues) |
| 430 | { |
| 431 | const auto &pathObjs = GatherPaths(paths); |
| 432 | |
| 433 | mFunctions->stencilThenCoverStrokePathInstancedNV( |
| 434 | static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, reference, mask, |
| 435 | coverMode, transformType, transformValues); |
| 436 | |
| 437 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 438 | } |
| 439 | |
Corentin Wallez | b920e36 | 2016-08-03 18:19:41 -0400 | [diff] [blame] | 440 | GLenum RendererGL::getResetStatus() |
| 441 | { |
| 442 | return mFunctions->getGraphicsResetStatus(); |
| 443 | } |
| 444 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 445 | ContextImpl *RendererGL::createContext(const gl::ContextState &state) |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 446 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 447 | return new ContextGL(state, this); |
Geoff Lang | 0af0b81 | 2015-09-23 13:56:25 -0400 | [diff] [blame] | 448 | } |
| 449 | |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 450 | void RendererGL::insertEventMarker(GLsizei length, const char *marker) |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 451 | { |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 452 | mFunctions->debugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, |
| 453 | GL_DEBUG_SEVERITY_NOTIFICATION, length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 456 | void RendererGL::pushGroupMarker(GLsizei length, const char *marker) |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 457 | { |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 458 | mFunctions->pushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void RendererGL::popGroupMarker() |
| 462 | { |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 463 | mFunctions->popDebugGroup(); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 466 | std::string RendererGL::getVendorString() const |
| 467 | { |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 468 | return std::string(reinterpret_cast<const char*>(mFunctions->getString(GL_VENDOR))); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | std::string RendererGL::getRendererDescription() const |
| 472 | { |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 473 | std::string nativeVendorString(reinterpret_cast<const char*>(mFunctions->getString(GL_VENDOR))); |
| 474 | std::string nativeRendererString(reinterpret_cast<const char*>(mFunctions->getString(GL_RENDERER))); |
| 475 | |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 476 | std::ostringstream rendererString; |
| 477 | rendererString << nativeVendorString << " " << nativeRendererString << " OpenGL"; |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 478 | if (mFunctions->standard == STANDARD_GL_ES) |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 479 | { |
| 480 | rendererString << " ES"; |
| 481 | } |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 482 | rendererString << " " << mFunctions->version.major << "." << mFunctions->version.minor; |
Geoff Lang | 8b0f0b3 | 2015-07-20 15:59:28 -0400 | [diff] [blame] | 483 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
| 484 | { |
| 485 | // Some drivers (NVIDIA) use a profile mask of 0 when in compatibility profile. |
| 486 | if ((mFunctions->profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0 || |
| 487 | (mFunctions->isAtLeastGL(gl::Version(3, 2)) && mFunctions->profile == 0)) |
| 488 | { |
| 489 | rendererString << " compatibility"; |
| 490 | } |
| 491 | else if ((mFunctions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0) |
| 492 | { |
| 493 | rendererString << " core"; |
| 494 | } |
| 495 | } |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 496 | |
| 497 | return rendererString.str(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 498 | } |
| 499 | |
Geoff Lang | 862c0ba | 2015-05-25 15:31:16 -0400 | [diff] [blame] | 500 | const gl::Version &RendererGL::getMaxSupportedESVersion() const |
| 501 | { |
| 502 | // Force generation of caps |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 503 | getNativeCaps(); |
Geoff Lang | 862c0ba | 2015-05-25 15:31:16 -0400 | [diff] [blame] | 504 | |
| 505 | return mMaxSupportedESVersion; |
| 506 | } |
| 507 | |
Austin Kinross | 02df796 | 2015-07-01 10:03:42 -0700 | [diff] [blame] | 508 | void RendererGL::generateCaps(gl::Caps *outCaps, gl::TextureCapsMap* outTextureCaps, |
| 509 | gl::Extensions *outExtensions, |
| 510 | gl::Limitations * /* outLimitations */) const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 511 | { |
Geoff Lang | 862c0ba | 2015-05-25 15:31:16 -0400 | [diff] [blame] | 512 | nativegl_gl::GenerateCaps(mFunctions, outCaps, outTextureCaps, outExtensions, &mMaxSupportedESVersion); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Ian Ewell | 53f59f4 | 2016-01-28 17:36:55 -0500 | [diff] [blame] | 515 | GLint RendererGL::getGPUDisjoint() |
| 516 | { |
| 517 | // TODO(ewell): On GLES backends we should find a way to reliably query disjoint events |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | GLint64 RendererGL::getTimestamp() |
| 522 | { |
| 523 | GLint64 result = 0; |
| 524 | mFunctions->getInteger64v(GL_TIMESTAMP, &result); |
| 525 | return result; |
| 526 | } |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 527 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 528 | void RendererGL::ensureCapsInitialized() const |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 529 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 530 | if (!mCapsInitialized) |
| 531 | { |
| 532 | generateCaps(&mNativeCaps, &mNativeTextureCaps, &mNativeExtensions, &mNativeLimitations); |
| 533 | mCapsInitialized = true; |
| 534 | } |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 535 | } |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 536 | |
| 537 | const gl::Caps &RendererGL::getNativeCaps() const |
| 538 | { |
| 539 | ensureCapsInitialized(); |
| 540 | return mNativeCaps; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 541 | } |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 542 | |
| 543 | const gl::TextureCapsMap &RendererGL::getNativeTextureCaps() const |
| 544 | { |
| 545 | ensureCapsInitialized(); |
| 546 | return mNativeTextureCaps; |
| 547 | } |
| 548 | |
| 549 | const gl::Extensions &RendererGL::getNativeExtensions() const |
| 550 | { |
| 551 | ensureCapsInitialized(); |
| 552 | return mNativeExtensions; |
| 553 | } |
| 554 | |
| 555 | const gl::Limitations &RendererGL::getNativeLimitations() const |
| 556 | { |
| 557 | ensureCapsInitialized(); |
| 558 | return mNativeLimitations; |
| 559 | } |
| 560 | |
| 561 | } // namespace rx |