blob: 09524f8172dbcfb9f01b7ef971ab6b47eea60da4 [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{
Geoff Lang7c37ca12017-09-26 16:56:32 -040068 ASSERT(userParam != nullptr);
69 rx::RendererGL *renderer = static_cast<rx::RendererGL *>(const_cast<void *>(userParam));
70 renderer->onDebugMessage(source, type, id, severity, length, message);
Geoff Langb80360f2015-05-04 15:01:31 -040071}
Geoff Langb80360f2015-05-04 15:01:31 -040072
Geoff Langf9a6f082015-01-22 13:32:49 -050073namespace rx
74{
75
Geoff Lang5da66902018-06-05 12:24:06 -040076RendererGL::RendererGL(std::unique_ptr<FunctionsGL> functions, const egl::AttributeMap &attribMap)
Jamie Madill53ea9cc2016-05-17 10:12:52 -040077 : mMaxSupportedESVersion(0, 0),
Geoff Lang5da66902018-06-05 12:24:06 -040078 mFunctions(std::move(functions)),
Jamie Madill39fcf262015-06-08 14:39:07 -040079 mStateManager(nullptr),
Geoff Lang53b8aec2015-08-24 10:33:25 -040080 mBlitter(nullptr),
Martin Radev5e424fa2017-08-09 16:25:36 +030081 mMultiviewClearer(nullptr),
Jamie Madill222c5172017-07-19 16:15:42 -040082 mUseDebugOutput(false),
Martin Radev318f9aa2017-05-17 17:47:28 +030083 mCapsInitialized(false),
84 mMultiviewImplementationType(MultiviewImplementationTypeGL::UNSPECIFIED)
Geoff Lang56cf9af2015-02-17 10:16:49 -050085{
86 ASSERT(mFunctions);
Geoff Lang5da66902018-06-05 12:24:06 -040087 nativegl_gl::GenerateWorkarounds(mFunctions.get(), &mWorkarounds);
88 mStateManager = new StateManagerGL(mFunctions.get(), getNativeCaps(), getNativeExtensions());
89 mBlitter = new BlitGL(mFunctions.get(), mWorkarounds, mStateManager);
90 mMultiviewClearer = new ClearMultiviewGL(mFunctions.get(), mStateManager);
Geoff Langb80360f2015-05-04 15:01:31 -040091
Jamie Madill222c5172017-07-19 16:15:42 -040092 bool hasDebugOutput = mFunctions->isAtLeastGL(gl::Version(4, 3)) ||
93 mFunctions->hasGLExtension("GL_KHR_debug") ||
94 mFunctions->isAtLeastGLES(gl::Version(3, 2)) ||
95 mFunctions->hasGLESExtension("GL_KHR_debug");
96
97 mUseDebugOutput = hasDebugOutput && ShouldUseDebugLayers(attribMap);
98
99 if (mUseDebugOutput)
Geoff Langb80360f2015-05-04 15:01:31 -0400100 {
Corentin Wallez930fefc2016-09-14 15:54:18 -0400101 mFunctions->enable(GL_DEBUG_OUTPUT);
Geoff Langb80360f2015-05-04 15:01:31 -0400102 mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
Jamie Madill231c7f52017-04-26 13:45:37 -0400103 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0,
104 nullptr, GL_TRUE);
105 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0,
106 nullptr, GL_TRUE);
107 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0,
108 nullptr, GL_FALSE);
109 mFunctions->debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION,
110 0, nullptr, GL_FALSE);
Geoff Lang7c37ca12017-09-26 16:56:32 -0400111 mFunctions->debugMessageCallback(&LogGLDebugMessage, this);
Geoff Langb80360f2015-05-04 15:01:31 -0400112 }
Jamie Madill39fcf262015-06-08 14:39:07 -0400113
Corentin Wallez83144652016-08-31 17:03:30 -0400114 if (mWorkarounds.initializeCurrentVertexAttributes)
115 {
116 GLint maxVertexAttribs = 0;
117 mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
118
119 for (GLint i = 0; i < maxVertexAttribs; ++i)
120 {
121 mFunctions->vertexAttrib4f(i, 0.0f, 0.0f, 0.0f, 1.0f);
122 }
123 }
Geoff Lang56cf9af2015-02-17 10:16:49 -0500124}
Geoff Langf9a6f082015-01-22 13:32:49 -0500125
126RendererGL::~RendererGL()
Geoff Lang94463d52015-02-18 13:09:37 -0500127{
Geoff Lang53b8aec2015-08-24 10:33:25 -0400128 SafeDelete(mBlitter);
Martin Radev5e424fa2017-08-09 16:25:36 +0300129 SafeDelete(mMultiviewClearer);
Geoff Langbf8a72f2015-11-03 16:34:45 -0500130 SafeDelete(mStateManager);
Geoff Lang94463d52015-02-18 13:09:37 -0500131}
Geoff Langf9a6f082015-01-22 13:32:49 -0500132
133gl::Error RendererGL::flush()
134{
Geoff Lang2c919142015-04-01 14:44:13 -0400135 mFunctions->flush();
He Yunchaoacd18982017-01-04 10:46:42 +0800136 return gl::NoError();
Geoff Langf9a6f082015-01-22 13:32:49 -0500137}
138
139gl::Error RendererGL::finish()
140{
Jamie Madill222c5172017-07-19 16:15:42 -0400141 if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mUseDebugOutput)
Geoff Langf0aa8422015-09-29 15:08:34 -0400142 {
143 mFunctions->enable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
144 }
Geoff Langf0aa8422015-09-29 15:08:34 -0400145
Geoff Lang2c919142015-04-01 14:44:13 -0400146 mFunctions->finish();
Geoff Langf0aa8422015-09-29 15:08:34 -0400147
Jamie Madill222c5172017-07-19 16:15:42 -0400148 if (mWorkarounds.finishDoesNotCauseQueriesToBeAvailable && mUseDebugOutput)
Geoff Langf0aa8422015-09-29 15:08:34 -0400149 {
150 mFunctions->disable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
151 }
Geoff Langf0aa8422015-09-29 15:08:34 -0400152
He Yunchaoacd18982017-01-04 10:46:42 +0800153 return gl::NoError();
Geoff Langf9a6f082015-01-22 13:32:49 -0500154}
155
Jamie Madill4928b7c2017-06-20 12:57:39 -0400156gl::Error RendererGL::drawArrays(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400157 gl::PrimitiveMode mode,
Jamie Madill9082b982016-04-27 15:21:51 -0400158 GLint first,
159 GLsizei count)
Geoff Langf9a6f082015-01-22 13:32:49 -0500160{
Martin Radev8f276e22017-05-30 12:05:52 +0300161 const gl::Program *program = context->getGLState().getProgram();
162 const bool usesMultiview = program->usesMultiview();
163 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400164
Martin Radev8f276e22017-05-30 12:05:52 +0300165 ANGLE_TRY(mStateManager->setDrawArraysState(context, first, count, instanceCount));
Jamie Madill6d94f062017-10-21 22:19:40 -0400166 if (!usesMultiview)
Jamie Madill39fcf262015-06-08 14:39:07 -0400167 {
Jamie Madill493f9572018-05-24 19:52:15 -0400168 mFunctions->drawArrays(ToGLenum(mode), first, count);
Jamie Madill6d94f062017-10-21 22:19:40 -0400169 }
170 else
171 {
Jamie Madill493f9572018-05-24 19:52:15 -0400172 mFunctions->drawArraysInstanced(ToGLenum(mode), first, count, instanceCount);
Jamie Madill39fcf262015-06-08 14:39:07 -0400173 }
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400174 return gl::NoError();
Geoff Langf9a6f082015-01-22 13:32:49 -0500175}
176
Jamie Madill4928b7c2017-06-20 12:57:39 -0400177gl::Error RendererGL::drawArraysInstanced(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400178 gl::PrimitiveMode mode,
Geoff Langf6db0982015-08-25 13:04:00 -0400179 GLint first,
180 GLsizei count,
181 GLsizei instanceCount)
182{
Martin Radev8f276e22017-05-30 12:05:52 +0300183 GLsizei adjustedInstanceCount = instanceCount;
184 const gl::Program *program = context->getGLState().getProgram();
185 if (program->usesMultiview())
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400186 {
Martin Radev8f276e22017-05-30 12:05:52 +0300187 adjustedInstanceCount *= program->getNumViews();
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400188 }
189
Martin Radev8f276e22017-05-30 12:05:52 +0300190 ANGLE_TRY(mStateManager->setDrawArraysState(context, first, count, adjustedInstanceCount));
Jamie Madill493f9572018-05-24 19:52:15 -0400191 mFunctions->drawArraysInstanced(ToGLenum(mode), first, count, adjustedInstanceCount);
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400192 return gl::NoError();
Geoff Langf6db0982015-08-25 13:04:00 -0400193}
194
Jamie Madill4928b7c2017-06-20 12:57:39 -0400195gl::Error RendererGL::drawElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400196 gl::PrimitiveMode mode,
Geoff Langf6db0982015-08-25 13:04:00 -0400197 GLsizei count,
198 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800199 const void *indices)
Geoff Langf9a6f082015-01-22 13:32:49 -0500200{
Martin Radev8f276e22017-05-30 12:05:52 +0300201 const gl::Program *program = context->getGLState().getProgram();
202 const bool usesMultiview = program->usesMultiview();
203 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Jamie Madill493f9572018-05-24 19:52:15 -0400204 const void *drawIndexPtr = nullptr;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400205
Martin Radev8f276e22017-05-30 12:05:52 +0300206 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, instanceCount,
207 &drawIndexPtr));
Jamie Madill6d94f062017-10-21 22:19:40 -0400208 if (!usesMultiview)
Jamie Madill39fcf262015-06-08 14:39:07 -0400209 {
Jamie Madill493f9572018-05-24 19:52:15 -0400210 mFunctions->drawElements(ToGLenum(mode), count, type, drawIndexPtr);
Jamie Madill6d94f062017-10-21 22:19:40 -0400211 }
212 else
213 {
Jamie Madill493f9572018-05-24 19:52:15 -0400214 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPtr, instanceCount);
Jamie Madill39fcf262015-06-08 14:39:07 -0400215 }
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400216 return gl::NoError();
Geoff Langf9a6f082015-01-22 13:32:49 -0500217}
218
Jamie Madill4928b7c2017-06-20 12:57:39 -0400219gl::Error RendererGL::drawElementsInstanced(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400220 gl::PrimitiveMode mode,
Geoff Langf6db0982015-08-25 13:04:00 -0400221 GLsizei count,
222 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -0400223 const void *indices,
Qin Jiajia1da00652017-06-20 17:16:25 +0800224 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -0400225{
Martin Radev8f276e22017-05-30 12:05:52 +0300226 GLsizei adjustedInstanceCount = instances;
227 const gl::Program *program = context->getGLState().getProgram();
228 if (program->usesMultiview())
229 {
230 adjustedInstanceCount *= program->getNumViews();
231 }
Jamie Madill876429b2017-04-20 15:46:24 -0400232 const void *drawIndexPointer = nullptr;
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400233
Martin Radev8f276e22017-05-30 12:05:52 +0300234 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices,
235 adjustedInstanceCount, &drawIndexPointer));
Jamie Madill493f9572018-05-24 19:52:15 -0400236 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
237 adjustedInstanceCount);
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400238 return gl::NoError();
Geoff Langf6db0982015-08-25 13:04:00 -0400239}
240
Jamie Madill4928b7c2017-06-20 12:57:39 -0400241gl::Error RendererGL::drawRangeElements(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400242 gl::PrimitiveMode mode,
Geoff Langf6db0982015-08-25 13:04:00 -0400243 GLuint start,
244 GLuint end,
245 GLsizei count,
246 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800247 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -0400248{
Martin Radev8f276e22017-05-30 12:05:52 +0300249 const gl::Program *program = context->getGLState().getProgram();
250 const bool usesMultiview = program->usesMultiview();
251 const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
Jamie Madill876429b2017-04-20 15:46:24 -0400252 const void *drawIndexPointer = nullptr;
Geoff Lang47502232015-08-25 16:26:10 -0400253
Martin Radev8f276e22017-05-30 12:05:52 +0300254 ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, instanceCount,
255 &drawIndexPointer));
Jamie Madill6d94f062017-10-21 22:19:40 -0400256 if (!usesMultiview)
Geoff Lang47502232015-08-25 16:26:10 -0400257 {
Jamie Madill493f9572018-05-24 19:52:15 -0400258 mFunctions->drawRangeElements(ToGLenum(mode), start, end, count, type, drawIndexPointer);
Jamie Madill6d94f062017-10-21 22:19:40 -0400259 }
260 else
261 {
Jamie Madill493f9572018-05-24 19:52:15 -0400262 mFunctions->drawElementsInstanced(ToGLenum(mode), count, type, drawIndexPointer,
263 instanceCount);
Geoff Lang47502232015-08-25 16:26:10 -0400264 }
He Yunchaoacd18982017-01-04 10:46:42 +0800265 return gl::NoError();
Geoff Langf6db0982015-08-25 13:04:00 -0400266}
267
Jamie Madill4928b7c2017-06-20 12:57:39 -0400268gl::Error RendererGL::drawArraysIndirect(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400269 gl::PrimitiveMode mode,
Jamie Madill876429b2017-04-20 15:46:24 -0400270 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800271{
Jiajia Qin47474142017-12-29 13:41:00 +0800272 ANGLE_TRY(mStateManager->setDrawIndirectState(context));
Jamie Madill493f9572018-05-24 19:52:15 -0400273 mFunctions->drawArraysIndirect(ToGLenum(mode), indirect);
Jiajia Qind9671222016-11-29 16:30:31 +0800274 return gl::NoError();
275}
276
Jamie Madill4928b7c2017-06-20 12:57:39 -0400277gl::Error RendererGL::drawElementsIndirect(const gl::Context *context,
Jamie Madill493f9572018-05-24 19:52:15 -0400278 gl::PrimitiveMode mode,
Jiajia Qind9671222016-11-29 16:30:31 +0800279 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -0400280 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800281{
Jiajia Qin47474142017-12-29 13:41:00 +0800282 ANGLE_TRY(mStateManager->setDrawIndirectState(context));
Jamie Madill493f9572018-05-24 19:52:15 -0400283 mFunctions->drawElementsIndirect(ToGLenum(mode), type, indirect);
Jiajia Qind9671222016-11-29 16:30:31 +0800284 return gl::NoError();
285}
286
Sami Väisänene45e53b2016-05-25 10:36:04 +0300287void RendererGL::stencilFillPath(const gl::ContextState &state,
288 const gl::Path *path,
289 GLenum fillMode,
290 GLuint mask)
291{
292 const auto *pathObj = GetImplAs<PathGL>(path);
293
294 mFunctions->stencilFillPathNV(pathObj->getPathID(), fillMode, mask);
295
296 ASSERT(mFunctions->getError() == GL_NO_ERROR);
297}
298
299void RendererGL::stencilStrokePath(const gl::ContextState &state,
300 const gl::Path *path,
301 GLint reference,
302 GLuint mask)
303{
304 const auto *pathObj = GetImplAs<PathGL>(path);
305
306 mFunctions->stencilStrokePathNV(pathObj->getPathID(), reference, mask);
307
308 ASSERT(mFunctions->getError() == GL_NO_ERROR);
309}
310
311void RendererGL::coverFillPath(const gl::ContextState &state,
312 const gl::Path *path,
313 GLenum coverMode)
314{
315
316 const auto *pathObj = GetImplAs<PathGL>(path);
317 mFunctions->coverFillPathNV(pathObj->getPathID(), coverMode);
318
319 ASSERT(mFunctions->getError() == GL_NO_ERROR);
320}
321
322void RendererGL::coverStrokePath(const gl::ContextState &state,
323 const gl::Path *path,
324 GLenum coverMode)
325{
326 const auto *pathObj = GetImplAs<PathGL>(path);
327 mFunctions->coverStrokePathNV(pathObj->getPathID(), coverMode);
328
329 ASSERT(mFunctions->getError() == GL_NO_ERROR);
330}
331
332void RendererGL::stencilThenCoverFillPath(const gl::ContextState &state,
333 const gl::Path *path,
334 GLenum fillMode,
335 GLuint mask,
336 GLenum coverMode)
337{
338
339 const auto *pathObj = GetImplAs<PathGL>(path);
340 mFunctions->stencilThenCoverFillPathNV(pathObj->getPathID(), fillMode, mask, coverMode);
341
342 ASSERT(mFunctions->getError() == GL_NO_ERROR);
343}
344
345void RendererGL::stencilThenCoverStrokePath(const gl::ContextState &state,
346 const gl::Path *path,
347 GLint reference,
348 GLuint mask,
349 GLenum coverMode)
350{
351
352 const auto *pathObj = GetImplAs<PathGL>(path);
353 mFunctions->stencilThenCoverStrokePathNV(pathObj->getPathID(), reference, mask, coverMode);
354
355 ASSERT(mFunctions->getError() == GL_NO_ERROR);
356}
357
Sami Väisänend59ca052016-06-21 16:10:00 +0300358void RendererGL::coverFillPathInstanced(const gl::ContextState &state,
359 const std::vector<gl::Path *> &paths,
360 GLenum coverMode,
361 GLenum transformType,
362 const GLfloat *transformValues)
363{
364 const auto &pathObjs = GatherPaths(paths);
365
366 mFunctions->coverFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
367 &pathObjs[0], 0, coverMode, transformType,
368 transformValues);
369
370 ASSERT(mFunctions->getError() == GL_NO_ERROR);
371}
372void RendererGL::coverStrokePathInstanced(const gl::ContextState &state,
373 const std::vector<gl::Path *> &paths,
374 GLenum coverMode,
375 GLenum transformType,
376 const GLfloat *transformValues)
377{
378 const auto &pathObjs = GatherPaths(paths);
379
380 mFunctions->coverStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
381 &pathObjs[0], 0, coverMode, transformType,
382 transformValues);
383
384 ASSERT(mFunctions->getError() == GL_NO_ERROR);
385}
386void RendererGL::stencilFillPathInstanced(const gl::ContextState &state,
387 const std::vector<gl::Path *> &paths,
388 GLenum fillMode,
389 GLuint mask,
390 GLenum transformType,
391 const GLfloat *transformValues)
392{
393 const auto &pathObjs = GatherPaths(paths);
394
395 mFunctions->stencilFillPathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
396 &pathObjs[0], 0, fillMode, mask, transformType,
397 transformValues);
398
399 ASSERT(mFunctions->getError() == GL_NO_ERROR);
400}
401void RendererGL::stencilStrokePathInstanced(const gl::ContextState &state,
402 const std::vector<gl::Path *> &paths,
403 GLint reference,
404 GLuint mask,
405 GLenum transformType,
406 const GLfloat *transformValues)
407{
408 const auto &pathObjs = GatherPaths(paths);
409
410 mFunctions->stencilStrokePathInstancedNV(static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT,
411 &pathObjs[0], 0, reference, mask, transformType,
412 transformValues);
413
414 ASSERT(mFunctions->getError() == GL_NO_ERROR);
415}
416
417void RendererGL::stencilThenCoverFillPathInstanced(const gl::ContextState &state,
418 const std::vector<gl::Path *> &paths,
419 GLenum coverMode,
420 GLenum fillMode,
421 GLuint mask,
422 GLenum transformType,
423 const GLfloat *transformValues)
424{
425 const auto &pathObjs = GatherPaths(paths);
426
427 mFunctions->stencilThenCoverFillPathInstancedNV(
428 static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, fillMode, mask,
429 coverMode, transformType, transformValues);
430
431 ASSERT(mFunctions->getError() == GL_NO_ERROR);
432}
433void RendererGL::stencilThenCoverStrokePathInstanced(const gl::ContextState &state,
434 const std::vector<gl::Path *> &paths,
435 GLenum coverMode,
436 GLint reference,
437 GLuint mask,
438 GLenum transformType,
439 const GLfloat *transformValues)
440{
441 const auto &pathObjs = GatherPaths(paths);
442
443 mFunctions->stencilThenCoverStrokePathInstancedNV(
444 static_cast<GLsizei>(pathObjs.size()), GL_UNSIGNED_INT, &pathObjs[0], 0, reference, mask,
445 coverMode, transformType, transformValues);
446
447 ASSERT(mFunctions->getError() == GL_NO_ERROR);
448}
449
Corentin Wallezb920e362016-08-03 18:19:41 -0400450GLenum RendererGL::getResetStatus()
451{
452 return mFunctions->getGraphicsResetStatus();
453}
454
Geoff Langf6ade2e2015-09-29 11:21:43 -0400455void RendererGL::insertEventMarker(GLsizei length, const char *marker)
Austin Kinross6ee1e782015-05-29 17:05:37 -0700456{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700457}
458
Geoff Langf6ade2e2015-09-29 11:21:43 -0400459void RendererGL::pushGroupMarker(GLsizei length, const char *marker)
Austin Kinross6ee1e782015-05-29 17:05:37 -0700460{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700461}
462
463void RendererGL::popGroupMarker()
464{
Geoff Lang5d5253a2017-11-22 14:51:12 -0500465}
466
467void RendererGL::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
468{
Geoff Lang5d5253a2017-11-22 14:51:12 -0500469}
470
471void RendererGL::popDebugGroup()
472{
Austin Kinross6ee1e782015-05-29 17:05:37 -0700473}
474
Geoff Langf9a6f082015-01-22 13:32:49 -0500475std::string RendererGL::getVendorString() const
476{
Jamie Madill231c7f52017-04-26 13:45:37 -0400477 return std::string(reinterpret_cast<const char *>(mFunctions->getString(GL_VENDOR)));
Geoff Langf9a6f082015-01-22 13:32:49 -0500478}
479
480std::string RendererGL::getRendererDescription() const
481{
Jamie Madill231c7f52017-04-26 13:45:37 -0400482 std::string nativeVendorString(
483 reinterpret_cast<const char *>(mFunctions->getString(GL_VENDOR)));
484 std::string nativeRendererString(
485 reinterpret_cast<const char *>(mFunctions->getString(GL_RENDERER)));
Geoff Lange42753b2015-04-08 13:46:33 -0400486
Geoff Lange42753b2015-04-08 13:46:33 -0400487 std::ostringstream rendererString;
488 rendererString << nativeVendorString << " " << nativeRendererString << " OpenGL";
Geoff Lang08dcfed2015-05-25 13:38:42 -0400489 if (mFunctions->standard == STANDARD_GL_ES)
Geoff Lange42753b2015-04-08 13:46:33 -0400490 {
491 rendererString << " ES";
492 }
Geoff Lang08dcfed2015-05-25 13:38:42 -0400493 rendererString << " " << mFunctions->version.major << "." << mFunctions->version.minor;
Geoff Lang8b0f0b32015-07-20 15:59:28 -0400494 if (mFunctions->standard == STANDARD_GL_DESKTOP)
495 {
496 // Some drivers (NVIDIA) use a profile mask of 0 when in compatibility profile.
497 if ((mFunctions->profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0 ||
498 (mFunctions->isAtLeastGL(gl::Version(3, 2)) && mFunctions->profile == 0))
499 {
500 rendererString << " compatibility";
501 }
502 else if ((mFunctions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0)
503 {
504 rendererString << " core";
505 }
506 }
Geoff Lange42753b2015-04-08 13:46:33 -0400507
508 return rendererString.str();
Geoff Langf9a6f082015-01-22 13:32:49 -0500509}
510
Geoff Lang862c0ba2015-05-25 15:31:16 -0400511const gl::Version &RendererGL::getMaxSupportedESVersion() const
512{
513 // Force generation of caps
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400514 getNativeCaps();
Geoff Lang862c0ba2015-05-25 15:31:16 -0400515
516 return mMaxSupportedESVersion;
517}
518
Jamie Madill231c7f52017-04-26 13:45:37 -0400519void RendererGL::generateCaps(gl::Caps *outCaps,
520 gl::TextureCapsMap *outTextureCaps,
Austin Kinross02df7962015-07-01 10:03:42 -0700521 gl::Extensions *outExtensions,
522 gl::Limitations * /* outLimitations */) const
Geoff Langf9a6f082015-01-22 13:32:49 -0500523{
Geoff Lang5da66902018-06-05 12:24:06 -0400524 nativegl_gl::GenerateCaps(mFunctions.get(), mWorkarounds, outCaps, outTextureCaps,
525 outExtensions, &mMaxSupportedESVersion,
526 &mMultiviewImplementationType);
Geoff Langf9a6f082015-01-22 13:32:49 -0500527}
528
Ian Ewell53f59f42016-01-28 17:36:55 -0500529GLint RendererGL::getGPUDisjoint()
530{
531 // TODO(ewell): On GLES backends we should find a way to reliably query disjoint events
532 return 0;
533}
534
535GLint64 RendererGL::getTimestamp()
536{
537 GLint64 result = 0;
538 mFunctions->getInteger64v(GL_TIMESTAMP, &result);
539 return result;
540}
Ian Ewell292f0052016-02-04 10:37:32 -0500541
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400542void RendererGL::ensureCapsInitialized() const
Ian Ewell292f0052016-02-04 10:37:32 -0500543{
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400544 if (!mCapsInitialized)
545 {
546 generateCaps(&mNativeCaps, &mNativeTextureCaps, &mNativeExtensions, &mNativeLimitations);
547 mCapsInitialized = true;
548 }
Ian Ewell292f0052016-02-04 10:37:32 -0500549}
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400550
551const gl::Caps &RendererGL::getNativeCaps() const
552{
553 ensureCapsInitialized();
554 return mNativeCaps;
Geoff Langf9a6f082015-01-22 13:32:49 -0500555}
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400556
557const gl::TextureCapsMap &RendererGL::getNativeTextureCaps() const
558{
559 ensureCapsInitialized();
560 return mNativeTextureCaps;
561}
562
563const gl::Extensions &RendererGL::getNativeExtensions() const
564{
565 ensureCapsInitialized();
566 return mNativeExtensions;
567}
568
569const gl::Limitations &RendererGL::getNativeLimitations() const
570{
571 ensureCapsInitialized();
572 return mNativeLimitations;
573}
574
Martin Radev318f9aa2017-05-17 17:47:28 +0300575MultiviewImplementationTypeGL RendererGL::getMultiviewImplementationType() const
576{
577 ensureCapsInitialized();
578 return mMultiviewImplementationType;
579}
580
Jamie Madill761b02c2017-06-23 16:27:06 -0400581void RendererGL::applyNativeWorkarounds(gl::Workarounds *workarounds) const
582{
583 ensureCapsInitialized();
Geoff Lang5da66902018-06-05 12:24:06 -0400584 nativegl_gl::ApplyWorkarounds(mFunctions.get(), workarounds);
Jamie Madill761b02c2017-06-23 16:27:06 -0400585}
586
Jamie Madill4928b7c2017-06-20 12:57:39 -0400587gl::Error RendererGL::dispatchCompute(const gl::Context *context,
Xinghua Cao2b396592017-03-29 15:36:04 +0800588 GLuint numGroupsX,
589 GLuint numGroupsY,
590 GLuint numGroupsZ)
591{
Jiajia Qin5b6b9c62017-12-25 16:10:51 +0800592 ANGLE_TRY(mStateManager->setDispatchComputeState(context));
Xinghua Cao2b396592017-03-29 15:36:04 +0800593 mFunctions->dispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
594 return gl::NoError();
595}
596
Qin Jiajia62fcf622017-11-30 16:16:12 +0800597gl::Error RendererGL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
598{
Jiajia Qin5b6b9c62017-12-25 16:10:51 +0800599 ANGLE_TRY(mStateManager->setDispatchComputeState(context));
Qin Jiajia62fcf622017-11-30 16:16:12 +0800600 mFunctions->dispatchComputeIndirect(indirect);
601 return gl::NoError();
602}
603
Xinghua Cao89c422a2017-11-29 18:24:20 +0800604gl::Error RendererGL::memoryBarrier(GLbitfield barriers)
605{
606 mFunctions->memoryBarrier(barriers);
607 return gl::NoError();
608}
609gl::Error RendererGL::memoryBarrierByRegion(GLbitfield barriers)
610{
611 mFunctions->memoryBarrierByRegion(barriers);
612 return gl::NoError();
613}
614
Geoff Lang7c37ca12017-09-26 16:56:32 -0400615void RendererGL::onDebugMessage(GLenum source,
616 GLenum type,
617 GLuint id,
618 GLenum severity,
619 GLsizei length,
620 const GLchar *message)
621{
622 constexpr size_t kMaxDebugMessagesPerNonErrorType = 5;
623 const std::string formattedMessage =
624 nativegl::FormatDebugMessage(source, type, id, severity, length, message);
625 if (type == GL_DEBUG_TYPE_ERROR)
626 {
627 ERR() << std::endl << formattedMessage;
628 }
629 else if (mDebugMessageCounts[id] < kMaxDebugMessagesPerNonErrorType)
630 {
631 // TODO(ynovikov): filter into WARN and INFO if INFO is ever implemented
632 WARN() << std::endl << formattedMessage;
633 }
634
635 mDebugMessageCounts[id]++;
636}
637
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400638} // namespace rx