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