blob: 03befebbfa0dea8ea36ad61b64a75355cbe01efc [file] [log] [blame]
Geoff Langf9a6f082015-01-22 13:32:49 -05001//
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 Madill39fcf262015-06-08 14:39:07 -040011#include <EGL/eglext.h>
12
Geoff Langf9a6f082015-01-22 13:32:49 -050013#include "common/debug.h"
Jamie Madill39fcf262015-06-08 14:39:07 -040014#include "libANGLE/AttributeMap.h"
Martin Radev8f276e22017-05-30 12:05:52 +030015#include "libANGLE/Context.h"
Jamie Madill9082b982016-04-27 15:21:51 -040016#include "libANGLE/ContextState.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "libANGLE/Path.h"
Geoff Lang4ad17092015-03-10 16:47:44 -040018#include "libANGLE/Surface.h"
Geoff Lang53b8aec2015-08-24 10:33:25 -040019#include "libANGLE/renderer/gl/BlitGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050020#include "libANGLE/renderer/gl/BufferGL.h"
Martin Radev5e424fa2017-08-09 16:25:36 +030021#include "libANGLE/renderer/gl/ClearMultiviewGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050022#include "libANGLE/renderer/gl/CompilerGL.h"
Jamie Madill437fa652016-05-03 15:13:24 -040023#include "libANGLE/renderer/gl/ContextGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050024#include "libANGLE/renderer/gl/FenceNVGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050025#include "libANGLE/renderer/gl/FramebufferGL.h"
Geoff Lang56cf9af2015-02-17 10:16:49 -050026#include "libANGLE/renderer/gl/FunctionsGL.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/renderer/gl/PathGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050028#include "libANGLE/renderer/gl/ProgramGL.h"
29#include "libANGLE/renderer/gl/QueryGL.h"
30#include "libANGLE/renderer/gl/RenderbufferGL.h"
Geoff Lang0af0b812015-09-23 13:56:25 -040031#include "libANGLE/renderer/gl/SamplerGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050032#include "libANGLE/renderer/gl/ShaderGL.h"
Geoff Lang94463d52015-02-18 13:09:37 -050033#include "libANGLE/renderer/gl/StateManagerGL.h"
Geoff Lang4ad17092015-03-10 16:47:44 -040034#include "libANGLE/renderer/gl/SurfaceGL.h"
Jamie Madill70b5bb02017-08-28 13:32:37 -040035#include "libANGLE/renderer/gl/SyncGL.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050036#include "libANGLE/renderer/gl/TextureGL.h"
37#include "libANGLE/renderer/gl/TransformFeedbackGL.h"
38#include "libANGLE/renderer/gl/VertexArrayGL.h"
Geoff Langddc74462015-02-25 11:48:09 -050039#include "libANGLE/renderer/gl/renderergl_utils.h"
Jamie Madill222c5172017-07-19 16:15:42 -040040#include "libANGLE/renderer/renderer_utils.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050041
Sami Väisänend59ca052016-06-21 16:10:00 +030042namespace
43{
44
45std::vector<GLuint> GatherPaths(const std::vector<gl::Path *> &paths)
46{
47 std::vector<GLuint> ret;
48 ret.reserve(paths.size());
49
50 for (const auto *p : paths)
51 {
52 const auto *pathObj = rx::GetImplAs<rx::PathGL>(p);
53 ret.push_back(pathObj->getPathID());
54 }
55 return ret;
56}
57
58} // namespace
59
Jamie Madill231c7f52017-04-26 13:45:37 -040060static void INTERNAL_GL_APIENTRY LogGLDebugMessage(GLenum source,
61 GLenum type,
62 GLuint id,
63 GLenum severity,
64 GLsizei length,
65 const GLchar *message,
66 const void *userParam)
Geoff Langb80360f2015-05-04 15:01:31 -040067{
68 std::string sourceText;
69 switch (source)
70 {
Jamie Madill231c7f52017-04-26 13:45:37 -040071 case GL_DEBUG_SOURCE_API:
72 sourceText = "OpenGL";
73 break;
74 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
75 sourceText = "Windows";
76 break;
77 case GL_DEBUG_SOURCE_SHADER_COMPILER:
78 sourceText = "Shader Compiler";
79 break;
80 case GL_DEBUG_SOURCE_THIRD_PARTY:
81 sourceText = "Third Party";
82 break;
83 case GL_DEBUG_SOURCE_APPLICATION:
84 sourceText = "Application";
85 break;
86 case GL_DEBUG_SOURCE_OTHER:
87 sourceText = "Other";
88 break;
89 default:
90 sourceText = "UNKNOWN";
91 break;
Geoff Langb80360f2015-05-04 15:01:31 -040092 }
93
94 std::string typeText;
95 switch (type)
96 {
Jamie Madill231c7f52017-04-26 13:45:37 -040097 case GL_DEBUG_TYPE_ERROR:
98 typeText = "Error";
99 break;
100 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
101 typeText = "Deprecated behavior";
102 break;
103 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
104 typeText = "Undefined behavior";
105 break;
106 case GL_DEBUG_TYPE_PORTABILITY:
107 typeText = "Portability";
108 break;
109 case GL_DEBUG_TYPE_PERFORMANCE:
110 typeText = "Performance";
111 break;
112 case GL_DEBUG_TYPE_OTHER:
113 typeText = "Other";
114 break;
115 case GL_DEBUG_TYPE_MARKER:
116 typeText = "Marker";
117 break;
118 default:
119 typeText = "UNKNOWN";
120 break;
Geoff Langb80360f2015-05-04 15:01:31 -0400121 }
122
123 std::string severityText;
124 switch (severity)
125 {
Jamie Madill231c7f52017-04-26 13:45:37 -0400126 case GL_DEBUG_SEVERITY_HIGH:
127 severityText = "High";
128 break;
129 case GL_DEBUG_SEVERITY_MEDIUM:
130 severityText = "Medium";
131 break;
132 case GL_DEBUG_SEVERITY_LOW:
133 severityText = "Low";
134 break;
135 case GL_DEBUG_SEVERITY_NOTIFICATION:
136 severityText = "Notification";
137 break;
138 default:
139 severityText = "UNKNOWN";
140 break;
Geoff Langb80360f2015-05-04 15:01:31 -0400141 }
142
Yuly Novikovbcb3f9b2017-01-27 22:45:18 -0500143 if (type == GL_DEBUG_TYPE_ERROR)
144 {
145 ERR() << std::endl
146 << "\tSource: " << sourceText << std::endl
147 << "\tType: " << typeText << std::endl
148 << "\tID: " << gl::Error(id) << std::endl
149 << "\tSeverity: " << severityText << std::endl
150 << "\tMessage: " << message;
151 }
152 else
153 {
154 // TODO(ynovikov): filter into WARN and INFO if INFO is ever implemented
155 WARN() << std::endl
156 << "\tSource: " << sourceText << std::endl
157 << "\tType: " << typeText << std::endl
158 << "\tID: " << gl::Error(id) << std::endl
159 << "\tSeverity: " << severityText << std::endl
160 << "\tMessage: " << message;
161 }
Geoff Langb80360f2015-05-04 15:01:31 -0400162}
Geoff Langb80360f2015-05-04 15:01:31 -0400163
Geoff Langf9a6f082015-01-22 13:32:49 -0500164namespace rx
165{
166
Jamie Madill39fcf262015-06-08 14:39:07 -0400167RendererGL::RendererGL(const FunctionsGL *functions, const egl::AttributeMap &attribMap)
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400168 : mMaxSupportedESVersion(0, 0),
Geoff Lang94463d52015-02-18 13:09:37 -0500169 mFunctions(functions),
Jamie Madill39fcf262015-06-08 14:39:07 -0400170 mStateManager(nullptr),
Geoff Lang53b8aec2015-08-24 10:33:25 -0400171 mBlitter(nullptr),
Martin Radev5e424fa2017-08-09 16:25:36 +0300172 mMultiviewClearer(nullptr),
Jamie Madill222c5172017-07-19 16:15:42 -0400173 mUseDebugOutput(false),
Martin Radev318f9aa2017-05-17 17:47:28 +0300174 mCapsInitialized(false),
175 mMultiviewImplementationType(MultiviewImplementationTypeGL::UNSPECIFIED)
Geoff Lang56cf9af2015-02-17 10:16:49 -0500176{
177 ASSERT(mFunctions);
Geoff Langcab7e1d2015-07-27 11:20:41 -0400178 nativegl_gl::GenerateWorkarounds(mFunctions, &mWorkarounds);
Jamie Madill493f9572018-05-24 19:52:15 -0400179 mStateManager = new StateManagerGL(mFunctions, getNativeCaps(), getNativeExtensions());
180 mBlitter = new BlitGL(functions, mWorkarounds, mStateManager);
Martin Radev5e424fa2017-08-09 16:25:36 +0300181 mMultiviewClearer = new ClearMultiviewGL(functions, mStateManager);
Geoff Langb80360f2015-05-04 15:01:31 -0400182
Jamie Madill222c5172017-07-19 16:15:42 -0400183 bool hasDebugOutput = mFunctions->isAtLeastGL(gl::Version(4, 3)) ||
184 mFunctions->hasGLExtension("GL_KHR_debug") ||
185 mFunctions->isAtLeastGLES(gl::Version(3, 2)) ||
186 mFunctions->hasGLESExtension("GL_KHR_debug");
187
188 mUseDebugOutput = hasDebugOutput && ShouldUseDebugLayers(attribMap);
189
190 if (mUseDebugOutput)
Geoff Langb80360f2015-05-04 15:01:31 -0400191 {
Corentin Wallez930fefc2016-09-14 15:54:18 -0400192 mFunctions->enable(GL_DEBUG_OUTPUT);
Geoff Langb80360f2015-05-04 15:01:31 -0400193 mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
Jamie Madill231c7f52017-04-26 13:45:37 -0400194 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0,
195 nullptr, GL_TRUE);
196 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0,
197 nullptr, GL_TRUE);
198 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0,
199 nullptr, GL_FALSE);
200 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION,
201 0, nullptr, GL_FALSE);
Geoff Langb80360f2015-05-04 15:01:31 -0400202 mFunctions->debugMessageCallback(&LogGLDebugMessage, nullptr);
203 }
Jamie Madill39fcf262015-06-08 14:39:07 -0400204
Corentin Wallez83144652016-08-31 17:03:30 -0400205 if (mWorkarounds.initializeCurrentVertexAttributes)
206 {
207 GLint maxVertexAttribs = 0;
208 mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
209
210 for (GLint i = 0; i < maxVertexAttribs; ++i)
211 {
212 mFunctions->vertexAttrib4f(i, 0.0f, 0.0f, 0.0f, 1.0f);
213 }
214 }
Geoff Lang56cf9af2015-02-17 10:16:49 -0500215}
Geoff Langf9a6f082015-01-22 13:32:49 -0500216
217RendererGL::~RendererGL()
Geoff Lang94463d52015-02-18 13:09:37 -0500218{
Geoff Lang53b8aec2015-08-24 10:33:25 -0400219 SafeDelete(mBlitter);
Martin Radev5e424fa2017-08-09 16:25:36 +0300220 SafeDelete(mMultiviewClearer);
Geoff Langbf8a72f2015-11-03 16:34:45 -0500221 SafeDelete(mStateManager);
Geoff Lang94463d52015-02-18 13:09:37 -0500222}
Geoff Langf9a6f082015-01-22 13:32:49 -0500223
224gl::Error RendererGL::flush()
225{
Geoff Lang2c919142015-04-01 14:44:13 -0400226 mFunctions->flush();
He Yunchaoacd18982017-01-04 10:46:42 +0800227 return gl::NoError();
Geoff Langf9a6f082015-01-22 13:32:49 -0500228}
229
230gl::Error RendererGL::finish()
231{
Jamie Madill222c5172017-07-19 16:15:42 -0400232 if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mUseDebugOutput)
Geoff Langf0aa8422015-09-29 15:08:34 -0400233 {
234 mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
235 }
Geoff Langf0aa8422015-09-29 15:08:34 -0400236
Geoff Lang2c919142015-04-01 14:44:13 -0400237 mFunctions->finish();
Geoff Langf0aa8422015-09-29 15:08:34 -0400238
Jamie Madill222c5172017-07-19 16:15:42 -0400239 if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mUseDebugOutput)
Geoff Langf0aa8422015-09-29 15:08:34 -0400240 {
241 mFunctions->disable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
242 }
Geoff Langf0aa8422015-09-29 15:08:34 -0400243
He Yunchaoacd18982017-01-04 10:46:42 +0800244 return gl::NoError();
Geoff Langf9a6f082015-01-22 13:32:49 -0500245}
246
Jamie Madill4928b7c2017-06-20 12:57:39 -0400247gl::Error RendererGL::drawArrays(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400248 gl::PrimitiveMode mode,
Jamie Madill9082b982016-04-27 15:21:51 -0400249 GLint first,
250 GLsizei count)
Geoff Langf9a6f082015-01-22 13:32:49 -0500251{
Martin Radev8f276e22017-05-30 12:05:52 +0300252 const gl::Program *program = context->getGLState().getProgram();
253 const bool usesMultiview = program->usesMultiview();
254 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400255
Martin Radev8f276e22017-05-30 12:05:52 +0300256 ANGLE_TRY(mStateManager->setDrawArraysState(context, first, count, instanceCount));
Jamie Madill6d94f062017-10-21 22:19:40 -0400257 if (!usesMultiview)
Jamie Madill39fcf262015-06-08 14:39:07 -0400258 {
Jamie Madill493f9572018-05-24 19:52:15 -0400259 mFunctions->drawArrays(ToGLenum(mode), first, count);
Jamie Madill6d94f062017-10-21 22:19:40 -0400260 }
261 else
262 {
Jamie Madill493f9572018-05-24 19:52:15 -0400263 mFunctions->drawArraysInstanced(ToGLenum(mode), first, count, instanceCount);
Jamie Madill39fcf262015-06-08 14:39:07 -0400264 }
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400265 return gl::NoError();
Geoff Langf9a6f082015-01-22 13:32:49 -0500266}
267
Jamie Madill4928b7c2017-06-20 12:57:39 -0400268gl::Error RendererGL::drawArraysInstanced(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400269 gl::PrimitiveMode mode,
Geoff Langf6db0982015-08-25 13:04:00 -0400270 GLint first,
271 GLsizei count,
272 GLsizei instanceCount)
273{
Martin Radev8f276e22017-05-30 12:05:52 +0300274 GLsizei adjustedInstanceCount = instanceCount;
275 const gl::Program *program = context->getGLState().getProgram();
276 if (program->usesMultiview())
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400277 {
Martin Radev8f276e22017-05-30 12:05:52 +0300278 adjustedInstanceCount *= program->getNumViews();
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400279 }
280
Martin Radev8f276e22017-05-30 12:05:52 +0300281 ANGLE_TRY(mStateManager->setDrawArraysState(context, first, count, adjustedInstanceCount));
Jamie Madill493f9572018-05-24 19:52:15 -0400282 mFunctions->drawArraysInstanced(ToGLenum(mode), first, count, adjustedInstanceCount);
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400283 return gl::NoError();
Geoff Langf6db0982015-08-25 13:04:00 -0400284}
285
Jamie Madill4928b7c2017-06-20 12:57:39 -0400286gl::Error RendererGL::drawElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400287 gl::PrimitiveMode mode,
Geoff Langf6db0982015-08-25 13:04:00 -0400288 GLsizei count,
289 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800290 const void *indices)
Geoff Langf9a6f082015-01-22 13:32:49 -0500291{
Martin Radev8f276e22017-05-30 12:05:52 +0300292 const gl::Program *program = context->getGLState().getProgram();
293 const bool usesMultiview = program->usesMultiview();
294 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Jamie Madill493f9572018-05-24 19:52:15 -0400295 const void *drawIndexPtr = nullptr;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400296
Martin Radev8f276e22017-05-30 12:05:52 +0300297 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, instanceCount,
298 &drawIndexPtr));
Jamie Madill6d94f062017-10-21 22:19:40 -0400299 if (!usesMultiview)
Jamie Madill39fcf262015-06-08 14:39:07 -0400300 {
Jamie Madill493f9572018-05-24 19:52:15 -0400301 mFunctions->drawElements(ToGLenum(mode), count, type, drawIndexPtr);
Jamie Madill6d94f062017-10-21 22:19:40 -0400302 }
303 else
304 {
Jamie Madill493f9572018-05-24 19:52:15 -0400305 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPtr, instanceCount);
Jamie Madill39fcf262015-06-08 14:39:07 -0400306 }
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400307 return gl::NoError();
Geoff Langf9a6f082015-01-22 13:32:49 -0500308}
309
Jamie Madill4928b7c2017-06-20 12:57:39 -0400310gl::Error RendererGL::drawElementsInstanced(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400311 gl::PrimitiveMode mode,
Geoff Langf6db0982015-08-25 13:04:00 -0400312 GLsizei count,
313 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -0400314 const void *indices,
Qin Jiajia1da00652017-06-20 17:16:25 +0800315 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -0400316{
Martin Radev8f276e22017-05-30 12:05:52 +0300317 GLsizei adjustedInstanceCount = instances;
318 const gl::Program *program = context->getGLState().getProgram();
319 if (program->usesMultiview())
320 {
321 adjustedInstanceCount *= program->getNumViews();
322 }
Jamie Madill876429b2017-04-20 15:46:24 -0400323 const void *drawIndexPointer = nullptr;
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400324
Martin Radev8f276e22017-05-30 12:05:52 +0300325 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices,
326 adjustedInstanceCount, &drawIndexPointer));
Jamie Madill493f9572018-05-24 19:52:15 -0400327 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
328 adjustedInstanceCount);
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400329 return gl::NoError();
Geoff Langf6db0982015-08-25 13:04:00 -0400330}
331
Jamie Madill4928b7c2017-06-20 12:57:39 -0400332gl::Error RendererGL::drawRangeElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400333 gl::PrimitiveMode mode,
Geoff Langf6db0982015-08-25 13:04:00 -0400334 GLuint start,
335 GLuint end,
336 GLsizei count,
337 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800338 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -0400339{
Martin Radev8f276e22017-05-30 12:05:52 +0300340 const gl::Program *program = context->getGLState().getProgram();
341 const bool usesMultiview = program->usesMultiview();
342 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Jamie Madill876429b2017-04-20 15:46:24 -0400343 const void *drawIndexPointer = nullptr;
Geoff Lang47502232015-08-25 16:26:10 -0400344
Martin Radev8f276e22017-05-30 12:05:52 +0300345 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, instanceCount,
346 &drawIndexPointer));
Jamie Madill6d94f062017-10-21 22:19:40 -0400347 if (!usesMultiview)
Geoff Lang47502232015-08-25 16:26:10 -0400348 {
Jamie Madill493f9572018-05-24 19:52:15 -0400349 mFunctions->drawRangeElements(ToGLenum(mode), start, end, count, type, drawIndexPointer);
Jamie Madill6d94f062017-10-21 22:19:40 -0400350 }
351 else
352 {
Jamie Madill493f9572018-05-24 19:52:15 -0400353 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
354 instanceCount);
Geoff Lang47502232015-08-25 16:26:10 -0400355 }
He Yunchaoacd18982017-01-04 10:46:42 +0800356 return gl::NoError();
Geoff Langf6db0982015-08-25 13:04:00 -0400357}
358
Jamie Madill4928b7c2017-06-20 12:57:39 -0400359gl::Error RendererGL::drawArraysIndirect(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400360 gl::PrimitiveMode mode,
Jamie Madill876429b2017-04-20 15:46:24 -0400361 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800362{
Jiajia Qin47474142017-12-29 13:41:00 +0800363 ANGLE_TRY(mStateManager->setDrawIndirectState(context));
Jamie Madill493f9572018-05-24 19:52:15 -0400364 mFunctions->drawArraysIndirect(ToGLenum(mode), indirect);
Jiajia Qind9671222016-11-29 16:30:31 +0800365 return gl::NoError();
366}
367
Jamie Madill4928b7c2017-06-20 12:57:39 -0400368gl::Error RendererGL::drawElementsIndirect(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400369 gl::PrimitiveMode mode,
Jiajia Qind9671222016-11-29 16:30:31 +0800370 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -0400371 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800372{
Jiajia Qin47474142017-12-29 13:41:00 +0800373 ANGLE_TRY(mStateManager->setDrawIndirectState(context));
Jamie Madill493f9572018-05-24 19:52:15 -0400374 mFunctions->drawElementsIndirect(ToGLenum(mode), type, indirect);
Jiajia Qind9671222016-11-29 16:30:31 +0800375 return gl::NoError();
376}
377
Sami Väisänene45e53b2016-05-25 10:36:04 +0300378void RendererGL::stencilFillPath(const gl::ContextState &state,
379 const gl::Path *path,
380 GLenum fillMode,
381 GLuint mask)
382{
383 const auto *pathObj = GetImplAs<PathGL>(path);
384
385 mFunctions->stencilFillPathNV(pathObj->getPathID(), fillMode, mask);
386
387 ASSERT(mFunctions->getError() == GL_NO_ERROR);
388}
389
390void RendererGL::stencilStrokePath(const gl::ContextState &state,
391 const gl::Path *path,
392 GLint reference,
393 GLuint mask)
394{
395 const auto *pathObj = GetImplAs<PathGL>(path);
396
397 mFunctions->stencilStrokePathNV(pathObj->getPathID(), reference, mask);
398
399 ASSERT(mFunctions->getError() == GL_NO_ERROR);
400}
401
402void RendererGL::coverFillPath(const gl::ContextState &state,
403 const gl::Path *path,
404 GLenum coverMode)
405{
406
407 const auto *pathObj = GetImplAs<PathGL>(path);
408 mFunctions->coverFillPathNV(pathObj->getPathID(), coverMode);
409
410 ASSERT(mFunctions->getError() == GL_NO_ERROR);
411}
412
413void RendererGL::coverStrokePath(const gl::ContextState &state,
414 const gl::Path *path,
415 GLenum coverMode)
416{
417 const auto *pathObj = GetImplAs<PathGL>(path);
418 mFunctions->coverStrokePathNV(pathObj->getPathID(), coverMode);
419
420 ASSERT(mFunctions->getError() == GL_NO_ERROR);
421}
422
423void RendererGL::stencilThenCoverFillPath(const gl::ContextState &state,
424 const gl::Path *path,
425 GLenum fillMode,
426 GLuint mask,
427 GLenum coverMode)
428{
429
430 const auto *pathObj = GetImplAs<PathGL>(path);
431 mFunctions->stencilThenCoverFillPathNV(pathObj->getPathID(), fillMode, mask, coverMode);
432
433 ASSERT(mFunctions->getError() == GL_NO_ERROR);
434}
435
436void RendererGL::stencilThenCoverStrokePath(const gl::ContextState &state,
437 const gl::Path *path,
438 GLint reference,
439 GLuint mask,
440 GLenum coverMode)
441{
442
443 const auto *pathObj = GetImplAs<PathGL>(path);
444 mFunctions->stencilThenCoverStrokePathNV(pathObj->getPathID(), reference, mask, coverMode);
445
446 ASSERT(mFunctions->getError() == GL_NO_ERROR);
447}
448
Sami Väisänend59ca052016-06-21 16:10:00 +0300449void RendererGL::coverFillPathInstanced(const gl::ContextState &state,
450 const std::vector<gl::Path *> &paths,
451 GLenum coverMode,
452 GLenum transformType,
453 const GLfloat *transformValues)
454{
455 const auto &pathObjs = GatherPaths(paths);
456
457 mFunctions->coverFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
458 &pathObjs[0], 0, coverMode, transformType,
459 transformValues);
460
461 ASSERT(mFunctions->getError() == GL_NO_ERROR);
462}
463void RendererGL::coverStrokePathInstanced(const gl::ContextState &state,
464 const std::vector<gl::Path *> &paths,
465 GLenum coverMode,
466 GLenum transformType,
467 const GLfloat *transformValues)
468{
469 const auto &pathObjs = GatherPaths(paths);
470
471 mFunctions->coverStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
472 &pathObjs[0], 0, coverMode, transformType,
473 transformValues);
474
475 ASSERT(mFunctions->getError() == GL_NO_ERROR);
476}
477void RendererGL::stencilFillPathInstanced(const gl::ContextState &state,
478 const std::vector<gl::Path *> &paths,
479 GLenum fillMode,
480 GLuint mask,
481 GLenum transformType,
482 const GLfloat *transformValues)
483{
484 const auto &pathObjs = GatherPaths(paths);
485
486 mFunctions->stencilFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
487 &pathObjs[0], 0, fillMode, mask, transformType,
488 transformValues);
489
490 ASSERT(mFunctions->getError() == GL_NO_ERROR);
491}
492void RendererGL::stencilStrokePathInstanced(const gl::ContextState &state,
493 const std::vector<gl::Path *> &paths,
494 GLint reference,
495 GLuint mask,
496 GLenum transformType,
497 const GLfloat *transformValues)
498{
499 const auto &pathObjs = GatherPaths(paths);
500
501 mFunctions->stencilStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
502 &pathObjs[0], 0, reference, mask, transformType,
503 transformValues);
504
505 ASSERT(mFunctions->getError() == GL_NO_ERROR);
506}
507
508void RendererGL::stencilThenCoverFillPathInstanced(const gl::ContextState &state,
509 const std::vector<gl::Path *> &paths,
510 GLenum coverMode,
511 GLenum fillMode,
512 GLuint mask,
513 GLenum transformType,
514 const GLfloat *transformValues)
515{
516 const auto &pathObjs = GatherPaths(paths);
517
518 mFunctions->stencilThenCoverFillPathInstancedNV(
519 static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, fillMode, mask,
520 coverMode, transformType, transformValues);
521
522 ASSERT(mFunctions->getError() == GL_NO_ERROR);
523}
524void RendererGL::stencilThenCoverStrokePathInstanced(const gl::ContextState &state,
525 const std::vector<gl::Path *> &paths,
526 GLenum coverMode,
527 GLint reference,
528 GLuint mask,
529 GLenum transformType,
530 const GLfloat *transformValues)
531{
532 const auto &pathObjs = GatherPaths(paths);
533
534 mFunctions->stencilThenCoverStrokePathInstancedNV(
535 static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, reference, mask,
536 coverMode, transformType, transformValues);
537
538 ASSERT(mFunctions->getError() == GL_NO_ERROR);
539}
540
Corentin Wallezb920e362016-08-03 18:19:41 -0400541GLenum RendererGL::getResetStatus()
542{
543 return mFunctions->getGraphicsResetStatus();
544}
545
Jamie Madill8415b5f2016-04-26 13:41:39 -0400546ContextImpl *RendererGL::createContext(const gl::ContextState &state)
Jamie Madill437fa652016-05-03 15:13:24 -0400547{
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400548 return new ContextGL(state, this);
Geoff Lang0af0b812015-09-23 13:56:25 -0400549}
550
Geoff Langf6ade2e2015-09-29 11:21:43 -0400551void RendererGL::insertEventMarker(GLsizei length, const char *marker)
Austin Kinross6ee1e782015-05-29 17:05:37 -0700552{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700553}
554
Geoff Langf6ade2e2015-09-29 11:21:43 -0400555void RendererGL::pushGroupMarker(GLsizei length, const char *marker)
Austin Kinross6ee1e782015-05-29 17:05:37 -0700556{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700557}
558
559void RendererGL::popGroupMarker()
560{
Geoff Lang5d5253a2017-11-22 14:51:12 -0500561}
562
563void RendererGL::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
564{
Geoff Lang5d5253a2017-11-22 14:51:12 -0500565}
566
567void RendererGL::popDebugGroup()
568{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700569}
570
Geoff Langf9a6f082015-01-22 13:32:49 -0500571std::string RendererGL::getVendorString() const
572{
Jamie Madill231c7f52017-04-26 13:45:37 -0400573 return std::string(reinterpret_cast<const char *>(mFunctions->getString(GL_VENDOR)));
Geoff Langf9a6f082015-01-22 13:32:49 -0500574}
575
576std::string RendererGL::getRendererDescription() const
577{
Jamie Madill231c7f52017-04-26 13:45:37 -0400578 std::string nativeVendorString(
579 reinterpret_cast<const char *>(mFunctions->getString(GL_VENDOR)));
580 std::string nativeRendererString(
581 reinterpret_cast<const char *>(mFunctions->getString(GL_RENDERER)));
Geoff Lange42753b2015-04-08 13:46:33 -0400582
Geoff Lange42753b2015-04-08 13:46:33 -0400583 std::ostringstream rendererString;
584 rendererString << nativeVendorString << " " << nativeRendererString << " OpenGL";
Geoff Lang08dcfed2015-05-25 13:38:42 -0400585 if (mFunctions->standard == STANDARD_GL_ES)
Geoff Lange42753b2015-04-08 13:46:33 -0400586 {
587 rendererString << " ES";
588 }
Geoff Lang08dcfed2015-05-25 13:38:42 -0400589 rendererString << " " << mFunctions->version.major << "." << mFunctions->version.minor;
Geoff Lang8b0f0b32015-07-20 15:59:28 -0400590 if (mFunctions->standard == STANDARD_GL_DESKTOP)
591 {
592 // Some drivers (NVIDIA) use a profile mask of 0 when in compatibility profile.
593 if ((mFunctions->profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0 ||
594 (mFunctions->isAtLeastGL(gl::Version(3, 2)) && mFunctions->profile == 0))
595 {
596 rendererString << " compatibility";
597 }
598 else if ((mFunctions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0)
599 {
600 rendererString << " core";
601 }
602 }
Geoff Lange42753b2015-04-08 13:46:33 -0400603
604 return rendererString.str();
Geoff Langf9a6f082015-01-22 13:32:49 -0500605}
606
Geoff Lang862c0ba2015-05-25 15:31:16 -0400607const gl::Version &RendererGL::getMaxSupportedESVersion() const
608{
609 // Force generation of caps
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400610 getNativeCaps();
Geoff Lang862c0ba2015-05-25 15:31:16 -0400611
612 return mMaxSupportedESVersion;
613}
614
Jamie Madill231c7f52017-04-26 13:45:37 -0400615void RendererGL::generateCaps(gl::Caps *outCaps,
616 gl::TextureCapsMap *outTextureCaps,
Austin Kinross02df7962015-07-01 10:03:42 -0700617 gl::Extensions *outExtensions,
618 gl::Limitations * /* outLimitations */) const
Geoff Langf9a6f082015-01-22 13:32:49 -0500619{
Shao86904b82017-03-21 09:30:59 +0800620 nativegl_gl::GenerateCaps(mFunctions, mWorkarounds, outCaps, outTextureCaps, outExtensions,
Martin Radev318f9aa2017-05-17 17:47:28 +0300621 &mMaxSupportedESVersion, &mMultiviewImplementationType);
Geoff Langf9a6f082015-01-22 13:32:49 -0500622}
623
Ian Ewell53f59f42016-01-28 17:36:55 -0500624GLint RendererGL::getGPUDisjoint()
625{
626 // TODO(ewell): On GLES backends we should find a way to reliably query disjoint events
627 return 0;
628}
629
630GLint64 RendererGL::getTimestamp()
631{
632 GLint64 result = 0;
633 mFunctions->getInteger64v(GL_TIMESTAMP, &result);
634 return result;
635}
Ian Ewell292f0052016-02-04 10:37:32 -0500636
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400637void RendererGL::ensureCapsInitialized() const
Ian Ewell292f0052016-02-04 10:37:32 -0500638{
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400639 if (!mCapsInitialized)
640 {
641 generateCaps(&mNativeCaps, &mNativeTextureCaps, &mNativeExtensions, &mNativeLimitations);
642 mCapsInitialized = true;
643 }
Ian Ewell292f0052016-02-04 10:37:32 -0500644}
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400645
646const gl::Caps &RendererGL::getNativeCaps() const
647{
648 ensureCapsInitialized();
649 return mNativeCaps;
Geoff Langf9a6f082015-01-22 13:32:49 -0500650}
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400651
652const gl::TextureCapsMap &RendererGL::getNativeTextureCaps() const
653{
654 ensureCapsInitialized();
655 return mNativeTextureCaps;
656}
657
658const gl::Extensions &RendererGL::getNativeExtensions() const
659{
660 ensureCapsInitialized();
661 return mNativeExtensions;
662}
663
664const gl::Limitations &RendererGL::getNativeLimitations() const
665{
666 ensureCapsInitialized();
667 return mNativeLimitations;
668}
669
Martin Radev318f9aa2017-05-17 17:47:28 +0300670MultiviewImplementationTypeGL RendererGL::getMultiviewImplementationType() const
671{
672 ensureCapsInitialized();
673 return mMultiviewImplementationType;
674}
675
Jamie Madill761b02c2017-06-23 16:27:06 -0400676void RendererGL::applyNativeWorkarounds(gl::Workarounds *workarounds) const
677{
678 ensureCapsInitialized();
679 nativegl_gl::ApplyWorkarounds(mFunctions, workarounds);
680}
681
Jamie Madill4928b7c2017-06-20 12:57:39 -0400682gl::Error RendererGL::dispatchCompute(const gl::Context *context,
Xinghua Cao2b396592017-03-29 15:36:04 +0800683 GLuint numGroupsX,
684 GLuint numGroupsY,
685 GLuint numGroupsZ)
686{
Jiajia Qin5b6b9c62017-12-25 16:10:51 +0800687 ANGLE_TRY(mStateManager->setDispatchComputeState(context));
Xinghua Cao2b396592017-03-29 15:36:04 +0800688 mFunctions->dispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
689 return gl::NoError();
690}
691
Qin Jiajia62fcf622017-11-30 16:16:12 +0800692gl::Error RendererGL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
693{
Jiajia Qin5b6b9c62017-12-25 16:10:51 +0800694 ANGLE_TRY(mStateManager->setDispatchComputeState(context));
Qin Jiajia62fcf622017-11-30 16:16:12 +0800695 mFunctions->dispatchComputeIndirect(indirect);
696 return gl::NoError();
697}
698
Xinghua Cao89c422a2017-11-29 18:24:20 +0800699gl::Error RendererGL::memoryBarrier(GLbitfield barriers)
700{
701 mFunctions->memoryBarrier(barriers);
702 return gl::NoError();
703}
704gl::Error RendererGL::memoryBarrierByRegion(GLbitfield barriers)
705{
706 mFunctions->memoryBarrierByRegion(barriers);
707 return gl::NoError();
708}
709
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400710} // namespace rx