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 | { |
| 125 | mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS); |
| 126 | mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr, GL_TRUE); |
| 127 | mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr, GL_TRUE); |
| 128 | mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, nullptr, GL_FALSE); |
| 129 | mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, nullptr, GL_FALSE); |
| 130 | mFunctions->debugMessageCallback(&LogGLDebugMessage, nullptr); |
| 131 | } |
| 132 | #endif |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 133 | |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 134 | EGLint deviceType = |
| 135 | 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] | 136 | if (deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE) |
| 137 | { |
| 138 | mSkipDrawCalls = true; |
| 139 | } |
Geoff Lang | 56cf9af | 2015-02-17 10:16:49 -0500 | [diff] [blame] | 140 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 141 | |
| 142 | RendererGL::~RendererGL() |
Geoff Lang | 94463d5 | 2015-02-18 13:09:37 -0500 | [diff] [blame] | 143 | { |
Geoff Lang | 53b8aec | 2015-08-24 10:33:25 -0400 | [diff] [blame] | 144 | SafeDelete(mBlitter); |
Geoff Lang | bf8a72f | 2015-11-03 16:34:45 -0500 | [diff] [blame] | 145 | SafeDelete(mStateManager); |
Geoff Lang | 94463d5 | 2015-02-18 13:09:37 -0500 | [diff] [blame] | 146 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 147 | |
| 148 | gl::Error RendererGL::flush() |
| 149 | { |
Geoff Lang | 2c91914 | 2015-04-01 14:44:13 -0400 | [diff] [blame] | 150 | mFunctions->flush(); |
| 151 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | gl::Error RendererGL::finish() |
| 155 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 156 | #ifdef NDEBUG |
| 157 | if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mHasDebugOutput) |
| 158 | { |
| 159 | mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS); |
| 160 | } |
| 161 | #endif |
| 162 | |
Geoff Lang | 2c91914 | 2015-04-01 14:44:13 -0400 | [diff] [blame] | 163 | mFunctions->finish(); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 164 | |
| 165 | #ifdef NDEBUG |
| 166 | if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mHasDebugOutput) |
| 167 | { |
| 168 | mFunctions->disable(GL_DEBUG_OUTPUT_SYNCHRONOUS); |
| 169 | } |
| 170 | #endif |
| 171 | |
Geoff Lang | 2c91914 | 2015-04-01 14:44:13 -0400 | [diff] [blame] | 172 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 175 | gl::Error RendererGL::drawArrays(const gl::ContextState &data, |
| 176 | GLenum mode, |
| 177 | GLint first, |
| 178 | GLsizei count) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 179 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 180 | ANGLE_TRY(mStateManager->setDrawArraysState(data, first, count, 0)); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 181 | |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 182 | if (!mSkipDrawCalls) |
| 183 | { |
| 184 | mFunctions->drawArrays(mode, first, count); |
| 185 | } |
Geoff Lang | d6e5087 | 2015-02-24 12:42:26 -0500 | [diff] [blame] | 186 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 187 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 188 | } |
| 189 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 190 | gl::Error RendererGL::drawArraysInstanced(const gl::ContextState &data, |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 191 | GLenum mode, |
| 192 | GLint first, |
| 193 | GLsizei count, |
| 194 | GLsizei instanceCount) |
| 195 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 196 | ANGLE_TRY(mStateManager->setDrawArraysState(data, first, count, instanceCount)); |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 197 | |
| 198 | if (!mSkipDrawCalls) |
| 199 | { |
| 200 | mFunctions->drawArraysInstanced(mode, first, count, instanceCount); |
| 201 | } |
| 202 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 203 | return gl::NoError(); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 204 | } |
| 205 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 206 | gl::Error RendererGL::drawElements(const gl::ContextState &data, |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 207 | GLenum mode, |
| 208 | GLsizei count, |
| 209 | GLenum type, |
| 210 | const GLvoid *indices, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 211 | const gl::IndexRange &indexRange) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 212 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 213 | const GLvoid *drawIndexPtr = nullptr; |
| 214 | ANGLE_TRY(mStateManager->setDrawElementsState(data, count, type, indices, 0, &drawIndexPtr)); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 215 | |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 216 | if (!mSkipDrawCalls) |
| 217 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 218 | mFunctions->drawElements(mode, count, type, drawIndexPtr); |
Jamie Madill | 39fcf26 | 2015-06-08 14:39:07 -0400 | [diff] [blame] | 219 | } |
Geoff Lang | d6e5087 | 2015-02-24 12:42:26 -0500 | [diff] [blame] | 220 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 221 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 222 | } |
| 223 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 224 | gl::Error RendererGL::drawElementsInstanced(const gl::ContextState &data, |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 225 | GLenum mode, |
| 226 | GLsizei count, |
| 227 | GLenum type, |
| 228 | const GLvoid *indices, |
| 229 | GLsizei instances, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 230 | const gl::IndexRange &indexRange) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 231 | { |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 232 | const GLvoid *drawIndexPointer = nullptr; |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 233 | ANGLE_TRY(mStateManager->setDrawElementsState(data, count, type, indices, instances, |
| 234 | &drawIndexPointer)); |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 235 | |
| 236 | if (!mSkipDrawCalls) |
| 237 | { |
| 238 | mFunctions->drawElementsInstanced(mode, count, type, drawIndexPointer, instances); |
| 239 | } |
| 240 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 241 | return gl::NoError(); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 242 | } |
| 243 | |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 244 | gl::Error RendererGL::drawRangeElements(const gl::ContextState &data, |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 245 | GLenum mode, |
| 246 | GLuint start, |
| 247 | GLuint end, |
| 248 | GLsizei count, |
| 249 | GLenum type, |
| 250 | const GLvoid *indices, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 251 | const gl::IndexRange &indexRange) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 252 | { |
Geoff Lang | 4750223 | 2015-08-25 16:26:10 -0400 | [diff] [blame] | 253 | const GLvoid *drawIndexPointer = nullptr; |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 254 | ANGLE_TRY( |
| 255 | mStateManager->setDrawElementsState(data, count, type, indices, 0, &drawIndexPointer)); |
Geoff Lang | 4750223 | 2015-08-25 16:26:10 -0400 | [diff] [blame] | 256 | |
| 257 | if (!mSkipDrawCalls) |
| 258 | { |
| 259 | mFunctions->drawRangeElements(mode, start, end, count, type, drawIndexPointer); |
| 260 | } |
| 261 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 262 | return gl::Error(GL_NO_ERROR); |
| 263 | } |
| 264 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 265 | void RendererGL::stencilFillPath(const gl::ContextState &state, |
| 266 | const gl::Path *path, |
| 267 | GLenum fillMode, |
| 268 | GLuint mask) |
| 269 | { |
| 270 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 271 | |
| 272 | mFunctions->stencilFillPathNV(pathObj->getPathID(), fillMode, mask); |
| 273 | |
| 274 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 275 | } |
| 276 | |
| 277 | void RendererGL::stencilStrokePath(const gl::ContextState &state, |
| 278 | const gl::Path *path, |
| 279 | GLint reference, |
| 280 | GLuint mask) |
| 281 | { |
| 282 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 283 | |
| 284 | mFunctions->stencilStrokePathNV(pathObj->getPathID(), reference, mask); |
| 285 | |
| 286 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 287 | } |
| 288 | |
| 289 | void RendererGL::coverFillPath(const gl::ContextState &state, |
| 290 | const gl::Path *path, |
| 291 | GLenum coverMode) |
| 292 | { |
| 293 | |
| 294 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 295 | mFunctions->coverFillPathNV(pathObj->getPathID(), coverMode); |
| 296 | |
| 297 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 298 | } |
| 299 | |
| 300 | void RendererGL::coverStrokePath(const gl::ContextState &state, |
| 301 | const gl::Path *path, |
| 302 | GLenum coverMode) |
| 303 | { |
| 304 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 305 | mFunctions->coverStrokePathNV(pathObj->getPathID(), coverMode); |
| 306 | |
| 307 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 308 | } |
| 309 | |
| 310 | void RendererGL::stencilThenCoverFillPath(const gl::ContextState &state, |
| 311 | const gl::Path *path, |
| 312 | GLenum fillMode, |
| 313 | GLuint mask, |
| 314 | GLenum coverMode) |
| 315 | { |
| 316 | |
| 317 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 318 | mFunctions->stencilThenCoverFillPathNV(pathObj->getPathID(), fillMode, mask, coverMode); |
| 319 | |
| 320 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 321 | } |
| 322 | |
| 323 | void RendererGL::stencilThenCoverStrokePath(const gl::ContextState &state, |
| 324 | const gl::Path *path, |
| 325 | GLint reference, |
| 326 | GLuint mask, |
| 327 | GLenum coverMode) |
| 328 | { |
| 329 | |
| 330 | const auto *pathObj = GetImplAs<PathGL>(path); |
| 331 | mFunctions->stencilThenCoverStrokePathNV(pathObj->getPathID(), reference, mask, coverMode); |
| 332 | |
| 333 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 334 | } |
| 335 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame^] | 336 | void RendererGL::coverFillPathInstanced(const gl::ContextState &state, |
| 337 | const std::vector<gl::Path *> &paths, |
| 338 | GLenum coverMode, |
| 339 | GLenum transformType, |
| 340 | const GLfloat *transformValues) |
| 341 | { |
| 342 | const auto &pathObjs = GatherPaths(paths); |
| 343 | |
| 344 | mFunctions->coverFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, |
| 345 | &pathObjs[0], 0, coverMode, transformType, |
| 346 | transformValues); |
| 347 | |
| 348 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 349 | } |
| 350 | void RendererGL::coverStrokePathInstanced(const gl::ContextState &state, |
| 351 | const std::vector<gl::Path *> &paths, |
| 352 | GLenum coverMode, |
| 353 | GLenum transformType, |
| 354 | const GLfloat *transformValues) |
| 355 | { |
| 356 | const auto &pathObjs = GatherPaths(paths); |
| 357 | |
| 358 | mFunctions->coverStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, |
| 359 | &pathObjs[0], 0, coverMode, transformType, |
| 360 | transformValues); |
| 361 | |
| 362 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 363 | } |
| 364 | void RendererGL::stencilFillPathInstanced(const gl::ContextState &state, |
| 365 | const std::vector<gl::Path *> &paths, |
| 366 | GLenum fillMode, |
| 367 | GLuint mask, |
| 368 | GLenum transformType, |
| 369 | const GLfloat *transformValues) |
| 370 | { |
| 371 | const auto &pathObjs = GatherPaths(paths); |
| 372 | |
| 373 | mFunctions->stencilFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, |
| 374 | &pathObjs[0], 0, fillMode, mask, transformType, |
| 375 | transformValues); |
| 376 | |
| 377 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 378 | } |
| 379 | void RendererGL::stencilStrokePathInstanced(const gl::ContextState &state, |
| 380 | const std::vector<gl::Path *> &paths, |
| 381 | GLint reference, |
| 382 | GLuint mask, |
| 383 | GLenum transformType, |
| 384 | const GLfloat *transformValues) |
| 385 | { |
| 386 | const auto &pathObjs = GatherPaths(paths); |
| 387 | |
| 388 | mFunctions->stencilStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, |
| 389 | &pathObjs[0], 0, reference, mask, transformType, |
| 390 | transformValues); |
| 391 | |
| 392 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 393 | } |
| 394 | |
| 395 | void RendererGL::stencilThenCoverFillPathInstanced(const gl::ContextState &state, |
| 396 | const std::vector<gl::Path *> &paths, |
| 397 | GLenum coverMode, |
| 398 | GLenum fillMode, |
| 399 | GLuint mask, |
| 400 | GLenum transformType, |
| 401 | const GLfloat *transformValues) |
| 402 | { |
| 403 | const auto &pathObjs = GatherPaths(paths); |
| 404 | |
| 405 | mFunctions->stencilThenCoverFillPathInstancedNV( |
| 406 | static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, fillMode, mask, |
| 407 | coverMode, transformType, transformValues); |
| 408 | |
| 409 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 410 | } |
| 411 | void RendererGL::stencilThenCoverStrokePathInstanced(const gl::ContextState &state, |
| 412 | const std::vector<gl::Path *> &paths, |
| 413 | GLenum coverMode, |
| 414 | GLint reference, |
| 415 | GLuint mask, |
| 416 | GLenum transformType, |
| 417 | const GLfloat *transformValues) |
| 418 | { |
| 419 | const auto &pathObjs = GatherPaths(paths); |
| 420 | |
| 421 | mFunctions->stencilThenCoverStrokePathInstancedNV( |
| 422 | static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, reference, mask, |
| 423 | coverMode, transformType, transformValues); |
| 424 | |
| 425 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 426 | } |
| 427 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 428 | ContextImpl *RendererGL::createContext(const gl::ContextState &state) |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 429 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 430 | return new ContextGL(state, this); |
Geoff Lang | 0af0b81 | 2015-09-23 13:56:25 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 433 | void RendererGL::insertEventMarker(GLsizei length, const char *marker) |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 434 | { |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 435 | mFunctions->debugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, |
| 436 | GL_DEBUG_SEVERITY_NOTIFICATION, length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 439 | void RendererGL::pushGroupMarker(GLsizei length, const char *marker) |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 440 | { |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 441 | mFunctions->pushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | void RendererGL::popGroupMarker() |
| 445 | { |
Geoff Lang | f6ade2e | 2015-09-29 11:21:43 -0400 | [diff] [blame] | 446 | mFunctions->popDebugGroup(); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 449 | void RendererGL::notifyDeviceLost() |
| 450 | { |
| 451 | UNIMPLEMENTED(); |
| 452 | } |
| 453 | |
| 454 | bool RendererGL::isDeviceLost() const |
| 455 | { |
| 456 | UNIMPLEMENTED(); |
| 457 | return bool(); |
| 458 | } |
| 459 | |
| 460 | bool RendererGL::testDeviceLost() |
| 461 | { |
| 462 | UNIMPLEMENTED(); |
| 463 | return bool(); |
| 464 | } |
| 465 | |
| 466 | bool RendererGL::testDeviceResettable() |
| 467 | { |
| 468 | UNIMPLEMENTED(); |
| 469 | return bool(); |
| 470 | } |
| 471 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 472 | std::string RendererGL::getVendorString() const |
| 473 | { |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 474 | return std::string(reinterpret_cast<const char*>(mFunctions->getString(GL_VENDOR))); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | std::string RendererGL::getRendererDescription() const |
| 478 | { |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 479 | std::string nativeVendorString(reinterpret_cast<const char*>(mFunctions->getString(GL_VENDOR))); |
| 480 | std::string nativeRendererString(reinterpret_cast<const char*>(mFunctions->getString(GL_RENDERER))); |
| 481 | |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 482 | std::ostringstream rendererString; |
| 483 | rendererString << nativeVendorString << " " << nativeRendererString << " OpenGL"; |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 484 | if (mFunctions->standard == STANDARD_GL_ES) |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 485 | { |
| 486 | rendererString << " ES"; |
| 487 | } |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 488 | rendererString << " " << mFunctions->version.major << "." << mFunctions->version.minor; |
Geoff Lang | 8b0f0b3 | 2015-07-20 15:59:28 -0400 | [diff] [blame] | 489 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
| 490 | { |
| 491 | // Some drivers (NVIDIA) use a profile mask of 0 when in compatibility profile. |
| 492 | if ((mFunctions->profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0 || |
| 493 | (mFunctions->isAtLeastGL(gl::Version(3, 2)) && mFunctions->profile == 0)) |
| 494 | { |
| 495 | rendererString << " compatibility"; |
| 496 | } |
| 497 | else if ((mFunctions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0) |
| 498 | { |
| 499 | rendererString << " core"; |
| 500 | } |
| 501 | } |
Geoff Lang | e42753b | 2015-04-08 13:46:33 -0400 | [diff] [blame] | 502 | |
| 503 | return rendererString.str(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 504 | } |
| 505 | |
Geoff Lang | 862c0ba | 2015-05-25 15:31:16 -0400 | [diff] [blame] | 506 | const gl::Version &RendererGL::getMaxSupportedESVersion() const |
| 507 | { |
| 508 | // Force generation of caps |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 509 | getNativeCaps(); |
Geoff Lang | 862c0ba | 2015-05-25 15:31:16 -0400 | [diff] [blame] | 510 | |
| 511 | return mMaxSupportedESVersion; |
| 512 | } |
| 513 | |
Austin Kinross | 02df796 | 2015-07-01 10:03:42 -0700 | [diff] [blame] | 514 | void RendererGL::generateCaps(gl::Caps *outCaps, gl::TextureCapsMap* outTextureCaps, |
| 515 | gl::Extensions *outExtensions, |
| 516 | gl::Limitations * /* outLimitations */) const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 517 | { |
Geoff Lang | 862c0ba | 2015-05-25 15:31:16 -0400 | [diff] [blame] | 518 | nativegl_gl::GenerateCaps(mFunctions, outCaps, outTextureCaps, outExtensions, &mMaxSupportedESVersion); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 519 | } |
| 520 | |
Ian Ewell | 53f59f4 | 2016-01-28 17:36:55 -0500 | [diff] [blame] | 521 | GLint RendererGL::getGPUDisjoint() |
| 522 | { |
| 523 | // TODO(ewell): On GLES backends we should find a way to reliably query disjoint events |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | GLint64 RendererGL::getTimestamp() |
| 528 | { |
| 529 | GLint64 result = 0; |
| 530 | mFunctions->getInteger64v(GL_TIMESTAMP, &result); |
| 531 | return result; |
| 532 | } |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 533 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 534 | void RendererGL::ensureCapsInitialized() const |
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 | if (!mCapsInitialized) |
| 537 | { |
| 538 | generateCaps(&mNativeCaps, &mNativeTextureCaps, &mNativeExtensions, &mNativeLimitations); |
| 539 | mCapsInitialized = true; |
| 540 | } |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 541 | } |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 542 | |
| 543 | const gl::Caps &RendererGL::getNativeCaps() const |
| 544 | { |
| 545 | ensureCapsInitialized(); |
| 546 | return mNativeCaps; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 547 | } |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 548 | |
| 549 | const gl::TextureCapsMap &RendererGL::getNativeTextureCaps() const |
| 550 | { |
| 551 | ensureCapsInitialized(); |
| 552 | return mNativeTextureCaps; |
| 553 | } |
| 554 | |
| 555 | const gl::Extensions &RendererGL::getNativeExtensions() const |
| 556 | { |
| 557 | ensureCapsInitialized(); |
| 558 | return mNativeExtensions; |
| 559 | } |
| 560 | |
| 561 | const gl::Limitations &RendererGL::getNativeLimitations() const |
| 562 | { |
| 563 | ensureCapsInitialized(); |
| 564 | return mNativeLimitations; |
| 565 | } |
| 566 | |
| 567 | } // namespace rx |