5#include <QOffscreenSurface>
6#include <QOpenGLContext>
7#include <QtCore/qmap.h>
8#include <QtGui/private/qopenglextensions_p.h>
9#include <QtGui/private/qopenglprogrambinarycache_p.h>
10#include <QtGui/private/qwindow_p.h>
11#include <qpa/qplatformopenglcontext.h>
156#define GL_BGRA 0x80E1
176#define GL_RG16 0x822C
184#define GL_RGBA8 0x8058
188#define GL_RGBA32F 0x8814
192#define GL_RGBA16F 0x881A
196#define GL_R16F 0x822D
200#define GL_R32F 0x822E
204#define GL_HALF_FLOAT 0x140B
207#ifndef GL_DEPTH_COMPONENT16
208#define GL_DEPTH_COMPONENT16 0x81A5
211#ifndef GL_DEPTH_COMPONENT24
212#define GL_DEPTH_COMPONENT24 0x81A6
215#ifndef GL_DEPTH_COMPONENT32F
216#define GL_DEPTH_COMPONENT32F 0x8CAC
219#ifndef GL_DEPTH32F_STENCIL8
220#define GL_DEPTH32F_STENCIL8 0x8CAD
223#ifndef GL_FLOAT_32_UNSIGNED_INT_24_8_REV
224#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD
227#ifndef GL_UNSIGNED_INT_24_8
228#define GL_UNSIGNED_INT_24_8 0x84FA
231#ifndef GL_STENCIL_INDEX
232#define GL_STENCIL_INDEX 0x1901
235#ifndef GL_STENCIL_INDEX8
236#define GL_STENCIL_INDEX8 0x8D48
239#ifndef GL_DEPTH24_STENCIL8
240#define GL_DEPTH24_STENCIL8 0x88F0
243#ifndef GL_DEPTH_STENCIL_ATTACHMENT
244#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
247#ifndef GL_DEPTH_STENCIL
248#define GL_DEPTH_STENCIL 0x84F9
251#ifndef GL_PRIMITIVE_RESTART_FIXED_INDEX
252#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69
255#ifndef GL_FRAMEBUFFER_SRGB
256#define GL_FRAMEBUFFER_SRGB 0x8DB9
259#ifndef GL_READ_FRAMEBUFFER
260#define GL_READ_FRAMEBUFFER 0x8CA8
263#ifndef GL_DRAW_FRAMEBUFFER
264#define GL_DRAW_FRAMEBUFFER 0x8CA9
267#ifndef GL_MAX_DRAW_BUFFERS
268#define GL_MAX_DRAW_BUFFERS 0x8824
271#ifndef GL_TEXTURE_COMPARE_MODE
272#define GL_TEXTURE_COMPARE_MODE 0x884C
275#ifndef GL_COMPARE_REF_TO_TEXTURE
276#define GL_COMPARE_REF_TO_TEXTURE 0x884E
279#ifndef GL_TEXTURE_COMPARE_FUNC
280#define GL_TEXTURE_COMPARE_FUNC 0x884D
283#ifndef GL_MAX_SAMPLES
284#define GL_MAX_SAMPLES 0x8D57
287#ifndef GL_SHADER_STORAGE_BUFFER
288#define GL_SHADER_STORAGE_BUFFER 0x90D2
292#define GL_READ_ONLY 0x88B8
296#define GL_WRITE_ONLY 0x88B9
300#define GL_READ_WRITE 0x88BA
303#ifndef GL_COMPUTE_SHADER
304#define GL_COMPUTE_SHADER 0x91B9
307#ifndef GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT
308#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001
311#ifndef GL_ELEMENT_ARRAY_BARRIER_BIT
312#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002
315#ifndef GL_UNIFORM_BARRIER_BIT
316#define GL_UNIFORM_BARRIER_BIT 0x00000004
319#ifndef GL_BUFFER_UPDATE_BARRIER_BIT
320#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200
323#ifndef GL_SHADER_STORAGE_BARRIER_BIT
324#define GL_SHADER_STORAGE_BARRIER_BIT 0x00002000
327#ifndef GL_TEXTURE_FETCH_BARRIER_BIT
328#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008
331#ifndef GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
332#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
335#ifndef GL_PIXEL_BUFFER_BARRIER_BIT
336#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080
339#ifndef GL_TEXTURE_UPDATE_BARRIER_BIT
340#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100
343#ifndef GL_FRAMEBUFFER_BARRIER_BIT
344#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400
347#ifndef GL_ALL_BARRIER_BITS
348#define GL_ALL_BARRIER_BITS 0xFFFFFFFF
351#ifndef GL_VERTEX_PROGRAM_POINT_SIZE
352#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
355#ifndef GL_POINT_SPRITE
356#define GL_POINT_SPRITE 0x8861
359#ifndef GL_MAP_READ_BIT
360#define GL_MAP_READ_BIT 0x0001
363#ifndef GL_MAP_WRITE_BIT
364#define GL_MAP_WRITE_BIT 0x0002
367#ifndef GL_TEXTURE_2D_MULTISAMPLE
368#define GL_TEXTURE_2D_MULTISAMPLE 0x9100
371#ifndef GL_TEXTURE_2D_MULTISAMPLE_ARRAY
372#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102
375#ifndef GL_TEXTURE_EXTERNAL_OES
376#define GL_TEXTURE_EXTERNAL_OES 0x8D65
379#ifndef GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS
380#define GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS 0x90EB
383#ifndef GL_MAX_COMPUTE_WORK_GROUP_COUNT
384#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE
387#ifndef GL_MAX_COMPUTE_WORK_GROUP_SIZE
388#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF
391#ifndef GL_TEXTURE_CUBE_MAP_SEAMLESS
392#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
395#ifndef GL_CONTEXT_LOST
396#define GL_CONTEXT_LOST 0x0507
399#ifndef GL_PROGRAM_BINARY_LENGTH
400#define GL_PROGRAM_BINARY_LENGTH 0x8741
403#ifndef GL_NUM_PROGRAM_BINARY_FORMATS
404#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE
407#ifndef GL_UNPACK_ROW_LENGTH
408#define GL_UNPACK_ROW_LENGTH 0x0CF2
412#define GL_TEXTURE_3D 0x806F
415#ifndef GL_TEXTURE_WRAP_R
416#define GL_TEXTURE_WRAP_R 0x8072
419#ifndef GL_TEXTURE_RECTANGLE
420#define GL_TEXTURE_RECTANGLE 0x84F5
423#ifndef GL_TEXTURE_2D_ARRAY
424#define GL_TEXTURE_2D_ARRAY 0x8C1A
427#ifndef GL_MAX_ARRAY_TEXTURE_LAYERS
428#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF
431#ifndef GL_MAX_VERTEX_UNIFORM_COMPONENTS
432#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A
435#ifndef GL_MAX_FRAGMENT_UNIFORM_COMPONENTS
436#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49
439#ifndef GL_MAX_VERTEX_UNIFORM_VECTORS
440#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
443#ifndef GL_MAX_FRAGMENT_UNIFORM_VECTORS
444#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
448#define GL_RGB10_A2 0x8059
451#ifndef GL_UNSIGNED_INT_2_10_10_10_REV
452#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
455#ifndef GL_MAX_VARYING_COMPONENTS
456#define GL_MAX_VARYING_COMPONENTS 0x8B4B
459#ifndef GL_MAX_VARYING_FLOATS
460#define GL_MAX_VARYING_FLOATS 0x8B4B
463#ifndef GL_MAX_VARYING_VECTORS
464#define GL_MAX_VARYING_VECTORS 0x8DFC
467#ifndef GL_TESS_CONTROL_SHADER
468#define GL_TESS_CONTROL_SHADER 0x8E88
471#ifndef GL_TESS_EVALUATION_SHADER
472#define GL_TESS_EVALUATION_SHADER 0x8E87
475#ifndef GL_PATCH_VERTICES
476#define GL_PATCH_VERTICES 0x8E72
480#define GL_LINE 0x1B01
484#define GL_FILL 0x1B02
488#define GL_PATCHES 0x000E
491#ifndef GL_GEOMETRY_SHADER
492#define GL_GEOMETRY_SHADER 0x8DD9
496#define GL_BACK_LEFT 0x0402
500#define GL_BACK_RIGHT 0x0403
504# define GL_TEXTURE_1D 0x0DE0
507#ifndef GL_TEXTURE_1D_ARRAY
508# define GL_TEXTURE_1D_ARRAY 0x8C18
512#define GL_HALF_FLOAT 0x140B
515#ifndef GL_MAX_VERTEX_OUTPUT_COMPONENTS
516#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122
520#define GL_TIMESTAMP 0x8E28
523#ifndef GL_QUERY_RESULT
524#define GL_QUERY_RESULT 0x8866
527#ifndef GL_QUERY_RESULT_AVAILABLE
528#define GL_QUERY_RESULT_AVAILABLE 0x8867
532#define GL_BUFFER 0x82E0
536#define GL_PROGRAM 0x82E2
544QRhiGles2InitParams::QRhiGles2InitParams()
573 if (tempContext.create())
574 fmt = tempContext.format();
576 qWarning(
"QRhiGles2: Failed to create temporary context");
595 ctx = importDevice->context;
597 qWarning(
"No OpenGL context given, cannot import");
612 if (currentSurface->surfaceClass() ==
QSurface::Window && !currentSurface->surfaceHandle())
615 return currentSurface;
623#if defined(Q_OS_MACOS)
648 if (!
ctx->makeCurrent(surface)) {
649 if (
ctx->isValid()) {
650 qWarning(
"QRhiGles2: Failed to make context current. Expect bad things to happen.");
652 qWarning(
"QRhiGles2: Context is lost.");
666 return srgb ? 0x8C4C : 0x83F0;
668 return srgb ? 0x8C4E : 0x83F2;
670 return srgb ? 0x8C4F : 0x83F3;
673 return srgb ? 0x9275 : 0x9274;
675 return srgb ? 0x9277 : 0x9276;
677 return srgb ? 0x9279 : 0x9278;
680 return srgb ? 0x93D0 : 0x93B0;
682 return srgb ? 0x93D1 : 0x93B1;
684 return srgb ? 0x93D2 : 0x93B2;
686 return srgb ? 0x93D3 : 0x93B3;
688 return srgb ? 0x93D4 : 0x93B4;
690 return srgb ? 0x93D5 : 0x93B5;
692 return srgb ? 0x93D6 : 0x93B6;
694 return srgb ? 0x93D7 : 0x93B7;
696 return srgb ? 0x93D8 : 0x93B8;
698 return srgb ? 0x93D9 : 0x93B9;
700 return srgb ? 0x93DA : 0x93BA;
702 return srgb ? 0x93DB : 0x93BB;
704 return srgb ? 0x93DC : 0x93BC;
706 return srgb ? 0x93DD : 0x93BD;
725 ctx->setShareContext(shareContext);
726 ctx->setScreen(shareContext->screen());
730 if (!
ctx->create()) {
731 qWarning(
"QRhiGles2: Failed to create context");
736 qCDebug(QRHI_LOG_INFO) <<
"Created OpenGL context" <<
ctx->format();
773 glFramebufferTexture1D =
778 const char *vendor =
reinterpret_cast<const char *
>(
f->glGetString(GL_VENDOR));
779 const char *
renderer =
reinterpret_cast<const char *
>(
f->glGetString(GL_RENDERER));
780 const char *version =
reinterpret_cast<const char *
>(
f->glGetString(GL_VERSION));
782 qCDebug(QRHI_LOG_INFO,
"OpenGL VENDOR: %s RENDERER: %s VERSION: %s", vendor,
renderer, version);
795 caps.ctxMajor = actualFormat.majorVersion();
796 caps.ctxMinor = actualFormat.minorVersion();
801 QVarLengthArray<GLint, 16> compressedTextureFormats(
n);
817 std::array<QRhiTexture::Flags, 2> textureVariantFlags;
818 textureVariantFlags[0] = {};
821 for (QRhiTexture::Flags
f : textureVariantFlags) {
828 for (QRhiTexture::Flags
f : textureVariantFlags) {
835 for (QRhiTexture::Flags
f : textureVariantFlags) {
852 f->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &
caps.maxTextureSize);
854 if (!
caps.gles ||
caps.ctxMajor >= 3) {
857 caps.hasDrawBuffersFunc =
true;
862 caps.maxDrawBuffers = 1;
863 caps.hasDrawBuffersFunc =
false;
876 caps.fixedIndexPrimitiveRestart =
caps.ctxMajor >= 3;
878 caps.fixedIndexPrimitiveRestart =
caps.ctxMajor > 4 || (
caps.ctxMajor == 4 &&
caps.ctxMinor >= 3);
880 if (
caps.fixedIndexPrimitiveRestart) {
891 caps.bgraInternalFormat =
caps.bgraExternalFormat &&
caps.gles;
894 caps.floatFormats =
caps.ctxMajor >= 3;
895 caps.rgb10Formats =
caps.ctxMajor >= 3;
896 caps.depthTexture =
caps.ctxMajor >= 3;
899 caps.needsDepthStencilCombinedAttach =
true;
901 caps.needsDepthStencilCombinedAttach =
false;
908 caps.srgbWriteControl =
ctx->hasExtension(
"GL_EXT_framebuffer_sRGB") ||
ctx->hasExtension(
"GL_EXT_sRGB_write_control");
913 caps.uniformBuffers =
caps.ctxMajor >= 3;
915 caps.uniformBuffers =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 1);
922 caps.instancing =
caps.ctxMajor >= 3;
924 caps.instancing =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 3);
926 caps.baseVertex =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 2);
929 caps.compute =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 1);
931 caps.compute =
caps.ctxMajor > 4 || (
caps.ctxMajor == 4 &&
caps.ctxMinor >= 3);
939 caps.maxThreadGroupsPerDimension =
qMin(tgPerDim[0],
qMin(tgPerDim[1], tgPerDim[2]));
946 caps.textureCompareMode =
caps.ctxMajor >= 3;
948 caps.textureCompareMode =
true;
955 caps.nonBaseLevelFramebufferTexture =
caps.ctxMajor >= 3;
957 caps.nonBaseLevelFramebufferTexture =
true;
959 caps.texelFetch =
caps.ctxMajor >= 3;
960 caps.intAttributes =
caps.ctxMajor >= 3;
964 caps.multisampledTexture =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 1);
966 caps.multisampledTexture =
caps.ctxMajor >= 3;
971 caps.programBinary =
caps.ctxMajor >= 3;
973 caps.programBinary =
caps.ctxMajor > 4 || (
caps.ctxMajor == 4 &&
caps.ctxMinor >= 1);
975 if (
caps.programBinary) {
979 caps.programBinary =
false;
982 caps.texture3D =
caps.ctxMajor >= 3;
985 caps.texture1D =
false;
987 caps.texture1D = glTexImage1D && (
caps.ctxMajor >= 2);
990 caps.tessellation =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 2);
992 caps.tessellation =
caps.ctxMajor >= 4;
995 caps.geometryShader =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 2);
997 caps.geometryShader =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 2);
999 if (
caps.ctxMajor >= 3) {
1000 GLint maxArraySize = 0;
1002 caps.maxTextureArraySize = maxArraySize;
1004 caps.maxTextureArraySize = 0;
1011 GLint maxVertexUniformVectors = 0;
1013 GLint maxFragmentUniformVectors = 0;
1015 caps.maxUniformVectors =
qMin(maxVertexUniformVectors, maxFragmentUniformVectors);
1017 GLint maxVertexUniformComponents = 0;
1019 GLint maxFragmentUniformComponents = 0;
1021 caps.maxUniformVectors =
qMin(maxVertexUniformComponents, maxFragmentUniformComponents) / 4;
1028 }
else if (
caps.ctxMajor >= 3) {
1043 if (!
caps.coreProfile)
1050 if (!
caps.gles && (
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 2)))
1058 if (
caps.multiView) {
1059 glFramebufferTextureMultiviewOVR =
1065 caps.timestamps = !
caps.gles && (
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 3));
1066 if (
caps.timestamps) {
1071 if (!glQueryCounter || !glGetQueryObjectui64v)
1072 caps.timestamps =
false;
1077 caps.objectLabel =
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 2);
1079 caps.objectLabel =
caps.ctxMajor > 4 || (
caps.ctxMajor == 4 &&
caps.ctxMinor >= 3);
1080 if (
caps.objectLabel) {
1092 caps.glesMultisampleRenderToTexture =
ctx->hasExtension(
"GL_EXT_multisampled_render_to_texture");
1093 if (
caps.glesMultisampleRenderToTexture) {
1097 caps.glesMultiviewMultisampleRenderToTexture =
ctx->hasExtension(
"GL_OVR_multiview_multisampled_render_to_texture");
1098 if (
caps.glesMultiviewMultisampleRenderToTexture) {
1103 caps.glesMultisampleRenderToTexture =
false;
1104 caps.glesMultiviewMultisampleRenderToTexture =
false;
1107 caps.unpackRowLength = !
caps.gles ||
caps.ctxMajor >= 3;
1124 if (
ofr.tsQueries[0]) {
1125 f->glDeleteQueries(2,
ofr.tsQueries);
1126 ofr.tsQueries[0] =
ofr.tsQueries[1] = 0;
1130 f->glDeleteVertexArrays(1, &
vao);
1152 f->glDeleteBuffers(1, &e.
buffer.buffer);
1158 f->glDeleteTextures(1, &e.
texture.texture);
1180 for (
int i = 1;
i <=
caps.maxSamples;
i *= 2)
1242 *glsizedintformat = *glintformat;
1244 *gltype = GL_UNSIGNED_SHORT;
1248 *glsizedintformat = *glintformat;
1250 *gltype = GL_UNSIGNED_SHORT;
1253 *glintformat =
GL_R8;
1254 *glsizedintformat = *glintformat;
1260 *glsizedintformat = *glintformat;
1266 *glsizedintformat = *glintformat;
1272 *glsizedintformat = *glintformat;
1278 *glsizedintformat = *glintformat;
1284 *glsizedintformat = *glintformat;
1290 *glsizedintformat = *glintformat;
1296 *glsizedintformat = *glintformat;
1302 *glsizedintformat = *glintformat;
1303 *glformat = GL_DEPTH_COMPONENT;
1304 *gltype = GL_UNSIGNED_SHORT;
1308 *glsizedintformat = *glintformat;
1309 *glformat = GL_DEPTH_COMPONENT;
1310 *gltype = GL_UNSIGNED_INT;
1314 *glsizedintformat = *glintformat;
1320 *glsizedintformat = *glintformat;
1321 *glformat = GL_DEPTH_COMPONENT;
1326 *glsizedintformat = *glintformat;
1349 return caps.depthTexture;
1352 return caps.depth24;
1355 return caps.depth24 &&
caps.packedDepthStencil;
1358 return caps.bgraExternalFormat;
1361 return caps.r8Format;
1364 return caps.r8Format;
1367 return caps.r16Format;
1370 return caps.r16Format;
1374 return caps.floatFormats;
1378 return caps.floatFormats;
1381 return caps.rgb10Formats;
1394 return caps.multisampledTexture;
1396 return caps.msaaRenderBuffer;
1400 return caps.timestamps;
1402 return caps.instancing;
1406 return caps.fixedIndexPrimitiveRestart;
1412 return caps.npotTextureFull;
1414 return caps.coreProfile;
1416 return caps.elementIndexUint;
1418 return caps.compute;
1420 return !
caps.coreProfile;
1424 return caps.baseVertex;
1430 return !
caps.gles ||
caps.properMapBuffer;
1432 return caps.nonBaseLevelFramebufferTexture;
1434 return caps.texelFetch;
1436 return caps.nonBaseLevelFramebufferTexture;
1438 return caps.intAttributes;
1440 return caps.screenSpaceDerivatives;
1444 return caps.programBinary;
1446 return caps.unpackRowLength;
1450 return caps.texture3D;
1452 return caps.texture3D;
1454 return caps.maxTextureArraySize > 0;
1456 return caps.tessellation;
1458 return caps.geometryShader;
1464 return caps.texture1D;
1466 return caps.texture1D;
1468 return caps.halfAttributes;
1470 return caps.texture1D;
1472 return caps.texture3D;
1474 return caps.multiView &&
caps.maxTextureArraySize > 0;
1480 Q_UNREACHABLE_RETURN(
false);
1490 return caps.maxTextureSize;
1492 return caps.maxDrawBuffers;
1500 return caps.maxThreadGroupsPerDimension;
1502 return caps.maxThreadsPerThreadGroup;
1504 return caps.maxThreadGroupsX;
1506 return caps.maxThreadGroupsY;
1508 return caps.maxThreadGroupsZ;
1512 return int(qMin<qint64>(INT_MAX,
caps.maxUniformVectors *
qint64(16)));
1514 return caps.maxVertexInputs;
1516 return caps.maxVertexOutputs;
1518 Q_UNREACHABLE_RETURN(0);
1589 header.driver[driverStrLen] =
'\0';
1591 const size_t dataOffset =
sizeof(
header);
1600 char *
p =
buf.data() + dataOffset;
1609 memcpy(
p,
key.constData(),
key.size());
1615 memcpy(
p,
data.constData(),
data.size());
1636 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: Invalid blob size (header incomplete)");
1644 if (
header.rhiId != rhiId) {
1645 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: The data is for a different QRhi version or backend (%u, %u)",
1650 if (
header.arch != arch) {
1651 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: Architecture does not match (%u, %u)",
1655 if (
header.programBinaryCount == 0)
1660 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: OpenGL vendor/renderer/version does not match");
1665 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: Invalid blob size (data incomplete)");
1671 const char *
p =
data.constData() + dataOffset;
1697 int sampleCount, QRhiRenderBuffer::Flags
flags,
1704 const QSize &pixelSize,
int depth,
int arraySize,
1705 int sampleCount, QRhiTexture::Flags
flags)
1714 return new QGles2Sampler(
this, magFilter, minFilter, mipmapMode, u,
v,
w);
1718 QRhiTextureRenderTarget::Flags
flags)
1745 if (pipelineChanged) {
1752 cmd.
args.bindGraphicsPipeline.ps = ps;
1757 int dynamicOffsetCount,
1767 srb = gfxPsD->m_shaderResourceBindings;
1769 srb = compPsD->m_shaderResourceBindings;
1775 for (
int i = 0, ie = srbD->m_bindings.size();
i != ie; ++
i) {
1783 for (
int elem = 0; elem <
b->u.stex.count; ++elem) {
1841 if (gfxPsD && (gfxPsD->currentSrb != srb || gfxPsD->currentSrbGeneration != srbD->generation)) {
1843 gfxPsD->currentSrb = srb;
1844 gfxPsD->currentSrbGeneration = srbD->generation;
1845 }
else if (compPsD && (compPsD->currentSrb != srb || compPsD->currentSrbGeneration != srbD->generation)) {
1847 compPsD->currentSrb = srb;
1848 compPsD->currentSrbGeneration = srbD->generation;
1863 cmd.
args.bindShaderResources.maybeGraphicsPs = gfxPsD;
1864 cmd.
args.bindShaderResources.maybeComputePs = compPsD;
1865 cmd.
args.bindShaderResources.srb = srb;
1866 cmd.
args.bindShaderResources.dynamicOffsetCount = 0;
1867 if (srbD->hasDynamicOffset) {
1869 cmd.
args.bindShaderResources.dynamicOffsetCount = dynamicOffsetCount;
1870 uint *
p = cmd.
args.bindShaderResources.dynamicOffsetPairs;
1871 for (
int i = 0;
i < dynamicOffsetCount; ++
i) {
1873 *
p++ =
uint(dynOfs.first);
1874 *
p++ = dynOfs.second;
1877 qWarning(
"Too many dynamic offsets (%d, max is %d)",
1892 for (
int i = 0;
i < bindingCount; ++
i) {
1901 cmd.
args.bindVertexBuffer.buffer = bufD->buffer;
1902 cmd.
args.bindVertexBuffer.offset = ofs;
1903 cmd.
args.bindVertexBuffer.binding = startBinding +
i;
1917 cmd.
args.bindIndexBuffer.buffer = ibufD->buffer;
1918 cmd.
args.bindIndexBuffer.offset = indexOffset;
1933 const std::array<float, 4>
r =
viewport.viewport();
1935 if (
r[2] < 0.0f ||
r[3] < 0.0f)
1940 cmd.
args.viewport.x =
r[0];
1941 cmd.
args.viewport.y =
r[1];
1942 cmd.
args.viewport.w =
r[2];
1943 cmd.
args.viewport.h =
r[3];
1953 const std::array<int, 4>
r = scissor.
scissor();
1955 if (
r[2] < 0 ||
r[3] < 0)
1960 cmd.
args.scissor.x =
r[0];
1961 cmd.
args.scissor.y =
r[1];
1962 cmd.
args.scissor.w =
r[2];
1963 cmd.
args.scissor.h =
r[3];
1973 cmd.
args.blendConstants.r = float(
c.redF());
1974 cmd.
args.blendConstants.g = float(
c.greenF());
1975 cmd.
args.blendConstants.b = float(
c.blueF());
1976 cmd.
args.blendConstants.a = float(
c.alphaF());
1986 cmd.
args.stencilRef.ref = refValue;
1999 cmd.
args.draw.vertexCount = vertexCount;
2000 cmd.
args.draw.firstVertex = firstVertex;
2002 cmd.
args.draw.baseInstance = firstInstance;
2014 cmd.
args.drawIndexed.indexCount = indexCount;
2015 cmd.
args.drawIndexed.firstIndex = firstIndex;
2017 cmd.
args.drawIndexed.baseInstance = firstInstance;
2018 cmd.
args.drawIndexed.baseVertex = vertexOffset;
2058 cmd.
args.beginFrame.timestampQuery = tsQuery;
2060 cmd.
args.endFrame.timestampQuery = tsQuery;
2090 f->glBindVertexArray(0);
2132 ctx->handle()->beginFrame();
2137 swapChainD->cb.resetState();
2139 if (swapChainD->timestamps.active[swapChainD->currentTimestampPairIndex]) {
2140 double elapsedSec = 0;
2141 if (swapChainD->timestamps.tryQueryTimestamps(swapChainD->currentTimestampPairIndex,
this, &elapsedSec))
2142 swapChainD->cb.lastGpuTime = elapsedSec;
2145 GLuint tsStart = swapChainD->timestamps.query[swapChainD->currentTimestampPairIndex * 2];
2146 GLuint tsEnd = swapChainD->timestamps.query[swapChainD->currentTimestampPairIndex * 2 + 1];
2147 const bool recordTimestamps = tsStart && tsEnd && !swapChainD->timestamps.active[swapChainD->currentTimestampPairIndex];
2159 GLuint tsStart = swapChainD->timestamps.query[swapChainD->currentTimestampPairIndex * 2];
2160 GLuint tsEnd = swapChainD->timestamps.query[swapChainD->currentTimestampPairIndex * 2 + 1];
2161 const bool recordTimestamps = tsStart && tsEnd && !swapChainD->timestamps.active[swapChainD->currentTimestampPairIndex];
2162 if (recordTimestamps) {
2163 swapChainD->timestamps.active[swapChainD->currentTimestampPairIndex] =
true;
2175 ctx->swapBuffers(swapChainD->surface);
2181 swapChainD->frameCount += 1;
2184 ctx->handle()->endFrame();
2197 ofr.cbWrapper.resetState();
2200 if (!
ofr.tsQueries[0])
2201 f->glGenQueries(2,
ofr.tsQueries);
2205 *
cb = &
ofr.cbWrapper;
2229 if (
ofr.tsQueries[0]) {
2233 if (timestamps[1] >= timestamps[0]) {
2234 const quint64 nanoseconds = timestamps[1] - timestamps[0];
2235 ofr.cbWrapper.lastGpuTime = nanoseconds / 1000000000.0;
2251 ofr.cbWrapper.resetCommands();
2310 if (
access == prevAccess)
2323 bufD->usageState.access =
access;
2333 if (
access == prevAccess)
2342 texD->usageState.access =
access;
2367 cmd.
args.subImage.target = texD->target;
2368 cmd.
args.subImage.texture = texD->texture;
2369 cmd.
args.subImage.faceTarget = effectiveTarget;
2371 cmd.
args.subImage.dx = dp.x();
2372 cmd.
args.subImage.dy = is1D && isArray ?
layer : dp.y();
2373 cmd.
args.subImage.dz = is3D || isArray ?
layer : 0;
2374 cmd.
args.subImage.w =
size.width();
2375 cmd.
args.subImage.h =
size.height();
2376 cmd.
args.subImage.glformat = texD->glformat;
2377 cmd.
args.subImage.gltype = texD->gltype;
2379 if (dataStride == 0)
2380 dataStride = bytesPerLine;
2382 cmd.
args.subImage.rowStartAlign = (dataStride & 3) ? 1 : 4;
2383 cmd.
args.subImage.rowLength =
caps.unpackRowLength ? (bytesPerPixel ? dataStride / bytesPerPixel : 0) : 0;
2396 if (
caps.unpackRowLength) {
2407 }
else if (!rawData.
isEmpty() && isCompressed) {
2408 const int depth =
qMax(1, texD->m_depth);
2409 const int arraySize =
qMax(0, texD->m_arraySize);
2411 && !texD->zeroInitialized)
2423 byteSize *= arraySize;
2427 cmd.
args.compressedImage.target = texD->target;
2428 cmd.
args.compressedImage.texture = texD->texture;
2429 cmd.
args.compressedImage.faceTarget = effectiveTarget;
2431 cmd.
args.compressedImage.glintformat = texD->glintformat;
2432 cmd.
args.compressedImage.w = texD->m_pixelSize.width();
2433 cmd.
args.compressedImage.h = is1D && isArray ? arraySize : texD->m_pixelSize.height();
2434 cmd.
args.compressedImage.depth = is3D ?
depth : (isArray ? arraySize : 0);
2435 cmd.
args.compressedImage.size = byteSize;
2437 texD->zeroInitialized =
true;
2442 if (texD->specified || texD->zeroInitialized) {
2445 cmd.
args.compressedSubImage.target = texD->target;
2446 cmd.
args.compressedSubImage.texture = texD->texture;
2447 cmd.
args.compressedSubImage.faceTarget = effectiveTarget;
2448 cmd.
args.compressedSubImage.level =
level;
2449 cmd.
args.compressedSubImage.dx = dp.x();
2450 cmd.
args.compressedSubImage.dy = is1D && isArray ?
layer : dp.y();
2451 cmd.
args.compressedSubImage.dz = is3D || isArray ?
layer : 0;
2452 cmd.
args.compressedSubImage.w =
size.width();
2453 cmd.
args.compressedSubImage.h =
size.height();
2454 cmd.
args.compressedSubImage.glintformat = texD->glintformat;
2455 cmd.
args.compressedSubImage.size = rawData.
size();
2460 cmd.
args.compressedImage.target = texD->target;
2461 cmd.
args.compressedImage.texture = texD->texture;
2462 cmd.
args.compressedImage.faceTarget = effectiveTarget;
2464 cmd.
args.compressedImage.glintformat = texD->glintformat;
2465 cmd.
args.compressedImage.w =
size.width();
2466 cmd.
args.compressedImage.h = is1D && isArray ? arraySize :
size.height();
2467 cmd.
args.compressedImage.depth = is3D ?
depth : (isArray ? arraySize : 0);
2468 cmd.
args.compressedImage.size = rawData.
size();
2471 }
else if (!rawData.
isEmpty()) {
2486 for (
int opIdx = 0; opIdx < ud->activeBufferOpCount; ++opIdx) {
2497 cmd.
args.bufferSubData.target = bufD->targetForDataOps;
2498 cmd.
args.bufferSubData.buffer = bufD->buffer;
2513 cmd.
args.bufferSubData.target = bufD->targetForDataOps;
2514 cmd.
args.bufferSubData.buffer = bufD->buffer;
2530 cmd.
args.getBufferSubData.target = bufD->targetForDataOps;
2531 cmd.
args.getBufferSubData.buffer = bufD->buffer;
2538 for (
int opIdx = 0; opIdx < ud->activeTextureOpCount; ++opIdx) {
2548 texD->specified =
true;
2576 cmd.
args.copyTex.srcTarget = srcD->target;
2578 cmd.
args.copyTex.srcTexture = srcD->texture;
2580 cmd.
args.copyTex.srcX =
sp.x();
2581 cmd.
args.copyTex.srcY =
sp.y();
2584 cmd.
args.copyTex.dstTarget = dstD->target;
2586 cmd.
args.copyTex.dstTexture = dstD->texture;
2588 cmd.
args.copyTex.dstX = dp.x();
2592 cmd.
args.copyTex.w = copySize.width();
2593 cmd.
args.copyTex.h = copySize.height();
2601 cmd.
args.readPixels.texture = texD ? texD->texture : 0;
2602 cmd.
args.readPixels.slice3D = -1;
2604 const QSize readImageSize =
q->sizeForMipLevel(u.
rb.
level(), texD->m_pixelSize);
2605 cmd.
args.readPixels.w = readImageSize.width();
2606 cmd.
args.readPixels.h = readImageSize.height();
2607 cmd.
args.readPixels.format = texD->m_format;
2611 cmd.
args.readPixels.readTarget = texD->target;
2625 cmd.
args.genMip.target = texD->target;
2626 cmd.
args.genMip.texture = texD->texture;
2637 return GL_TRIANGLES;
2639 return GL_TRIANGLE_STRIP;
2641 return GL_TRIANGLE_FAN;
2645 return GL_LINE_STRIP;
2651 Q_UNREACHABLE_RETURN(GL_TRIANGLES);
2663 Q_UNREACHABLE_RETURN(GL_BACK);
2675 Q_UNREACHABLE_RETURN(GL_CCW);
2687 return GL_SRC_COLOR;
2689 return GL_ONE_MINUS_SRC_COLOR;
2691 return GL_DST_COLOR;
2693 return GL_ONE_MINUS_DST_COLOR;
2695 return GL_SRC_ALPHA;
2697 return GL_ONE_MINUS_SRC_ALPHA;
2699 return GL_DST_ALPHA;
2701 return GL_ONE_MINUS_DST_ALPHA;
2711 return GL_SRC_ALPHA_SATURATE;
2716 qWarning(
"Unsupported blend factor %d",
f);
2719 Q_UNREACHABLE_RETURN(GL_ZERO);
2761 Q_UNREACHABLE_RETURN(GL_ALWAYS);
2785 Q_UNREACHABLE_RETURN(GL_KEEP);
2797 Q_UNREACHABLE_RETURN(
GL_FILL);
2815 Q_UNREACHABLE_RETURN(GL_LINEAR);
2827 Q_UNREACHABLE_RETURN(GL_LINEAR);
2865 Q_UNREACHABLE_RETURN(GL_NEVER);
2895 u.
access = bufUsage.access;
2926 u.
access = texUsage.access;
2979 state->currentArrayBuffer = 0;
2980 state->currentElementArrayBuffer = 0;
2981 state->lastBindVertexBuffer.buffer = 0;
2994 if (cmd.
args.beginFrame.timestampQuery)
2996 if (
caps.coreProfile) {
2998 f->glGenVertexArrays(1, &
vao);
2999 f->glBindVertexArray(
vao);
3003 if (
state.instancedAttributesUsed) {
3005 if (
state.nonzeroAttribDivisor[
i])
3006 f->glVertexAttribDivisor(
GLuint(
i), 0);
3009 f->glVertexAttribDivisor(
GLuint(
i), 0);
3010 state.instancedAttributesUsed =
false;
3014 if (
state.enabledAttribArrays[
i]) {
3015 f->glDisableVertexAttribArray(
GLuint(
i));
3016 state.enabledAttribArrays[
i] =
false;
3021 f->glBindVertexArray(0);
3022 if (cmd.
args.endFrame.timestampQuery)
3027 f->glBindVertexArray(
vao);
3031 f->glDepthRangef(cmd.
args.viewport.d0, cmd.
args.viewport.d1);
3034 f->glScissor(cmd.
args.scissor.x, cmd.
args.scissor.y, cmd.
args.scissor.w, cmd.
args.scissor.h);
3037 f->glBlendColor(cmd.
args.blendConstants.r, cmd.
args.blendConstants.g, cmd.
args.blendConstants.b, cmd.
args.blendConstants.a);
3044 f->glStencilFuncSeparate(GL_FRONT,
toGlCompareOp(psD->m_stencilFront.compareOp),
ref, psD->m_stencilReadMask);
3045 f->glStencilFuncSeparate(GL_BACK,
toGlCompareOp(psD->m_stencilBack.compareOp),
ref, psD->m_stencilReadMask);
3048 qWarning(
"No graphics pipeline active for setStencilRef; ignored");
3056 if (
state.lastBindVertexBuffer.ps == psD
3057 &&
state.lastBindVertexBuffer.buffer == cmd.
args.bindVertexBuffer.buffer
3058 &&
state.lastBindVertexBuffer.offset == cmd.
args.bindVertexBuffer.offset
3059 &&
state.lastBindVertexBuffer.binding == cmd.
args.bindVertexBuffer.binding)
3066 state.lastBindVertexBuffer.ps = psD;
3067 state.lastBindVertexBuffer.buffer = cmd.
args.bindVertexBuffer.buffer;
3068 state.lastBindVertexBuffer.offset = cmd.
args.bindVertexBuffer.offset;
3069 state.lastBindVertexBuffer.binding = cmd.
args.bindVertexBuffer.binding;
3071 if (cmd.
args.bindVertexBuffer.buffer !=
state.currentArrayBuffer) {
3072 state.currentArrayBuffer = cmd.
args.bindVertexBuffer.buffer;
3076 for (
auto it = psD->m_vertexInputLayout.cbeginAttributes(), itEnd = psD->m_vertexInputLayout.cendAttributes();
3079 const int bindingIdx =
it->binding();
3080 if (bindingIdx != cmd.
args.bindVertexBuffer.binding)
3084 const int stride = int(inputBinding->stride());
3088 switch (
it->format()) {
3121 type = GL_UNSIGNED_INT;
3125 type = GL_UNSIGNED_INT;
3129 type = GL_UNSIGNED_INT;
3133 type = GL_UNSIGNED_INT;
3169 type = GL_UNSIGNED_SHORT;
3173 type = GL_UNSIGNED_SHORT;
3177 type = GL_UNSIGNED_SHORT;
3181 type = GL_UNSIGNED_SHORT;
3204 const int locationIdx =
it->location();
3205 quint32 ofs =
it->offset() + cmd.
args.bindVertexBuffer.offset;
3206 if (
type == GL_UNSIGNED_INT ||
type == GL_INT) {
3207 if (
caps.intAttributes) {
3209 reinterpret_cast<const GLvoid *
>(
quintptr(ofs)));
3211 qWarning(
"Current RHI backend does not support IntAttributes. Check supported features.");
3214 state.enabledAttribArrays[locationIdx] =
true;
3218 reinterpret_cast<const GLvoid *
>(
quintptr(ofs)));
3222 state.enabledAttribArrays[locationIdx] =
true;
3223 f->glEnableVertexAttribArray(
GLuint(locationIdx));
3226 f->glVertexAttribDivisor(
GLuint(locationIdx), inputBinding->instanceStepRate());
3228 state.nonzeroAttribDivisor[locationIdx] =
true;
3230 state.maxUntrackedInstancedAttribute =
qMax(
state.maxUntrackedInstancedAttribute, locationIdx);
3231 state.instancedAttributesUsed =
true;
3233 &&
state.nonzeroAttribDivisor[locationIdx])
3235 && locationIdx <=
state.maxUntrackedInstancedAttribute))
3237 f->glVertexAttribDivisor(
GLuint(locationIdx), 0);
3239 state.nonzeroAttribDivisor[locationIdx] =
false;
3243 qWarning(
"No graphics pipeline active for setVertexInput; ignored");
3248 state.indexType = cmd.
args.bindIndexBuffer.type;
3250 state.indexOffset = cmd.
args.bindIndexBuffer.offset;
3251 if (
state.currentElementArrayBuffer != cmd.
args.bindIndexBuffer.buffer) {
3252 state.currentElementArrayBuffer = cmd.
args.bindIndexBuffer.buffer;
3260 if (cmd.
args.draw.instanceCount == 1 || !
caps.instancing) {
3261 f->glDrawArrays(psD->drawMode,
GLint(cmd.
args.draw.firstVertex),
GLsizei(cmd.
args.draw.vertexCount));
3263 f->glDrawArraysInstanced(psD->drawMode,
GLint(cmd.
args.draw.firstVertex),
GLsizei(cmd.
args.draw.vertexCount),
3267 qWarning(
"No graphics pipeline active for draw; ignored");
3275 const GLvoid *ofs =
reinterpret_cast<const GLvoid *
>(
3277 if (cmd.
args.drawIndexed.instanceCount == 1 || !
caps.instancing) {
3278 if (cmd.
args.drawIndexed.baseVertex != 0 &&
caps.baseVertex) {
3279 f->glDrawElementsBaseVertex(psD->drawMode,
3283 cmd.
args.drawIndexed.baseVertex);
3285 f->glDrawElements(psD->drawMode,
3291 if (cmd.
args.drawIndexed.baseVertex != 0 &&
caps.baseVertex) {
3292 f->glDrawElementsInstancedBaseVertex(psD->drawMode,
3297 cmd.
args.drawIndexed.baseVertex);
3299 f->glDrawElementsInstanced(psD->drawMode,
3307 qWarning(
"No graphics pipeline active for drawIndexed; ignored");
3316 cmd.
args.bindShaderResources.maybeGraphicsPs,
3317 cmd.
args.bindShaderResources.maybeComputePs,
3318 cmd.
args.bindShaderResources.srb,
3319 cmd.
args.bindShaderResources.dynamicOffsetPairs,
3320 cmd.
args.bindShaderResources.dynamicOffsetCount);
3324 QVarLengthArray<GLenum, 8>
bufs;
3325 if (cmd.
args.bindFramebuffer.fbo) {
3327 const int colorAttCount = cmd.
args.bindFramebuffer.colorAttCount;
3329 if (
caps.maxDrawBuffers > 1) {
3330 for (
int i = 1;
i < colorAttCount; ++
i)
3340 if (
caps.hasDrawBuffersFunc)
3341 f->glDrawBuffers(
bufs.count(),
bufs.constData());
3342 if (
caps.srgbWriteControl) {
3343 if (cmd.
args.bindFramebuffer.srgb)
3351 f->glDisable(GL_SCISSOR_TEST);
3352 if (cmd.
args.clear.mask & GL_COLOR_BUFFER_BIT) {
3353 f->glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3354 f->glClearColor(cmd.
args.clear.c[0], cmd.
args.clear.c[1], cmd.
args.clear.c[2], cmd.
args.clear.c[3]);
3356 if (cmd.
args.clear.mask & GL_DEPTH_BUFFER_BIT) {
3357 f->glDepthMask(GL_TRUE);
3358 f->glClearDepthf(cmd.
args.clear.d);
3360 if (cmd.
args.clear.mask & GL_STENCIL_BUFFER_BIT) {
3361 f->glStencilMask(0xFF);
3364 f->glClear(cmd.
args.clear.mask);
3369 f->glBufferSubData(cmd.
args.bufferSubData.target, cmd.
args.bufferSubData.offset, cmd.
args.bufferSubData.size,
3370 cmd.
args.bufferSubData.data);
3377 if (
caps.properMapBuffer) {
3378 void *
p =
f->glMapBufferRange(cmd.
args.getBufferSubData.target,
3379 cmd.
args.getBufferSubData.offset,
3380 cmd.
args.getBufferSubData.size,
3383 result->data.resize(cmd.
args.getBufferSubData.size);
3384 memcpy(
result->data.data(),
p,
size_t(cmd.
args.getBufferSubData.size));
3385 f->glUnmapBuffer(cmd.
args.getBufferSubData.target);
3389 result->data.resize(cmd.
args.getBufferSubData.size);
3390 f->glGetBufferSubData(cmd.
args.getBufferSubData.target,
3391 cmd.
args.getBufferSubData.offset,
3392 cmd.
args.getBufferSubData.size,
3402 f->glGenFramebuffers(1, &fbo);
3408 cmd.
args.copyTex.srcLevel, cmd.
args.copyTex.srcZ);
3411 cmd.
args.copyTex.srcTarget, cmd.
args.copyTex.srcTexture,
3412 cmd.
args.copyTex.srcLevel);
3415 cmd.
args.copyTex.srcFaceTarget, cmd.
args.copyTex.srcTexture, cmd.
args.copyTex.srcLevel);
3417 f->glBindTexture(cmd.
args.copyTex.dstTarget, cmd.
args.copyTex.dstTexture);
3419 f->glCopyTexSubImage3D(cmd.
args.copyTex.dstTarget, cmd.
args.copyTex.dstLevel,
3420 cmd.
args.copyTex.dstX, cmd.
args.copyTex.dstY, cmd.
args.copyTex.dstZ,
3421 cmd.
args.copyTex.srcX, cmd.
args.copyTex.srcY,
3422 cmd.
args.copyTex.w, cmd.
args.copyTex.h);
3424 glCopyTexSubImage1D(cmd.
args.copyTex.dstTarget, cmd.
args.copyTex.dstLevel,
3425 cmd.
args.copyTex.dstX, cmd.
args.copyTex.srcX,
3426 cmd.
args.copyTex.srcY, cmd.
args.copyTex.w);
3428 f->glCopyTexSubImage2D(cmd.
args.copyTex.dstFaceTarget, cmd.
args.copyTex.dstLevel,
3429 cmd.
args.copyTex.dstX, cmd.
args.copyTex.dstY,
3430 cmd.
args.copyTex.srcX, cmd.
args.copyTex.srcY,
3431 cmd.
args.copyTex.w, cmd.
args.copyTex.h);
3434 f->glDeleteFramebuffers(1, &fbo);
3446 mipLevel = cmd.
args.readPixels.level;
3447 if (mipLevel == 0 ||
caps.nonBaseLevelFramebufferTexture) {
3448 f->glGenFramebuffers(1, &fbo);
3450 if (cmd.
args.readPixels.slice3D >= 0) {
3452 tex, mipLevel, cmd.
args.readPixels.slice3D);
3455 cmd.
args.readPixels.readTarget, tex, mipLevel);
3458 cmd.
args.readPixels.readTarget, tex, mipLevel);
3467 const int h =
result->pixelSize.height();
3468 if (mipLevel == 0 ||
caps.nonBaseLevelFramebufferTexture) {
3476 const quint8 *srcBase =
reinterpret_cast<const quint8 *
>(tmpBuf.constData());
3479 for (
int y = 0;
y <
h; ++
y) {
3483 while (
count-- > 0) {
3484 *
dst++ =
src[componentIndex];
3489 switch (
result->format) {
3525 f->glDeleteFramebuffers(1, &fbo);
3532 f->glBindTexture(cmd.
args.subImage.target, cmd.
args.subImage.texture);
3533 if (cmd.
args.subImage.rowStartAlign != 4)
3534 f->glPixelStorei(GL_UNPACK_ALIGNMENT, cmd.
args.subImage.rowStartAlign);
3535 if (cmd.
args.subImage.rowLength != 0)
3538 f->glTexSubImage3D(cmd.
args.subImage.target, cmd.
args.subImage.level,
3539 cmd.
args.subImage.dx, cmd.
args.subImage.dy, cmd.
args.subImage.dz,
3540 cmd.
args.subImage.w, cmd.
args.subImage.h, 1,
3541 cmd.
args.subImage.glformat, cmd.
args.subImage.gltype,
3542 cmd.
args.subImage.data);
3544 glTexSubImage1D(cmd.
args.subImage.target, cmd.
args.subImage.level,
3545 cmd.
args.subImage.dx, cmd.
args.subImage.w,
3546 cmd.
args.subImage.glformat, cmd.
args.subImage.gltype,
3547 cmd.
args.subImage.data);
3549 f->glTexSubImage2D(cmd.
args.subImage.faceTarget, cmd.
args.subImage.level,
3550 cmd.
args.subImage.dx, cmd.
args.subImage.dy,
3551 cmd.
args.subImage.w, cmd.
args.subImage.h,
3552 cmd.
args.subImage.glformat, cmd.
args.subImage.gltype,
3553 cmd.
args.subImage.data);
3555 if (cmd.
args.subImage.rowStartAlign != 4)
3556 f->glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
3557 if (cmd.
args.subImage.rowLength != 0)
3561 f->glBindTexture(cmd.
args.compressedImage.target, cmd.
args.compressedImage.texture);
3563 f->glCompressedTexImage3D(cmd.
args.compressedImage.target, cmd.
args.compressedImage.level,
3564 cmd.
args.compressedImage.glintformat,
3565 cmd.
args.compressedImage.w, cmd.
args.compressedImage.h, cmd.
args.compressedImage.depth,
3566 0, cmd.
args.compressedImage.size, cmd.
args.compressedImage.data);
3568 glCompressedTexImage1D(
3569 cmd.
args.compressedImage.target, cmd.
args.compressedImage.level,
3570 cmd.
args.compressedImage.glintformat, cmd.
args.compressedImage.w, 0,
3571 cmd.
args.compressedImage.size, cmd.
args.compressedImage.data);
3573 f->glCompressedTexImage2D(cmd.
args.compressedImage.faceTarget, cmd.
args.compressedImage.level,
3574 cmd.
args.compressedImage.glintformat,
3575 cmd.
args.compressedImage.w, cmd.
args.compressedImage.h,
3576 0, cmd.
args.compressedImage.size, cmd.
args.compressedImage.data);
3580 f->glBindTexture(cmd.
args.compressedSubImage.target, cmd.
args.compressedSubImage.texture);
3582 f->glCompressedTexSubImage3D(cmd.
args.compressedSubImage.target, cmd.
args.compressedSubImage.level,
3583 cmd.
args.compressedSubImage.dx, cmd.
args.compressedSubImage.dy, cmd.
args.compressedSubImage.dz,
3584 cmd.
args.compressedSubImage.w, cmd.
args.compressedSubImage.h, 1,
3585 cmd.
args.compressedSubImage.glintformat,
3586 cmd.
args.compressedSubImage.size, cmd.
args.compressedSubImage.data);
3588 glCompressedTexSubImage1D(
3589 cmd.
args.compressedSubImage.target, cmd.
args.compressedSubImage.level,
3590 cmd.
args.compressedSubImage.dx, cmd.
args.compressedSubImage.w,
3591 cmd.
args.compressedSubImage.glintformat, cmd.
args.compressedSubImage.size,
3592 cmd.
args.compressedSubImage.data);
3594 f->glCompressedTexSubImage2D(cmd.
args.compressedSubImage.faceTarget, cmd.
args.compressedSubImage.level,
3595 cmd.
args.compressedSubImage.dx, cmd.
args.compressedSubImage.dy,
3596 cmd.
args.compressedSubImage.w, cmd.
args.compressedSubImage.h,
3597 cmd.
args.compressedSubImage.glintformat,
3598 cmd.
args.compressedSubImage.size, cmd.
args.compressedSubImage.data);
3606 f->glDisable(GL_SCISSOR_TEST);
3608 f->glGenFramebuffers(2, fbo);
3610 const bool ds = cmd.
args.blitFromRenderbuffer.isDepthStencil;
3624 cmd.
args.blitFromRenderbuffer.dstTexture,
3625 cmd.
args.blitFromRenderbuffer.dstLevel,
3626 cmd.
args.blitFromRenderbuffer.dstLayer);
3628 cmd.
args.blitFromRenderbuffer.dstTexture,
3629 cmd.
args.blitFromRenderbuffer.dstLevel,
3630 cmd.
args.blitFromRenderbuffer.dstLayer);
3633 cmd.
args.blitFromRenderbuffer.dstTexture,
3634 cmd.
args.blitFromRenderbuffer.dstLevel,
3635 cmd.
args.blitFromRenderbuffer.dstLayer);
3640 cmd.
args.blitFromRenderbuffer.dstTexture, cmd.
args.blitFromRenderbuffer.dstLevel);
3642 cmd.
args.blitFromRenderbuffer.dstTexture, cmd.
args.blitFromRenderbuffer.dstLevel);
3645 cmd.
args.blitFromRenderbuffer.dstTexture, cmd.
args.blitFromRenderbuffer.dstLevel);
3648 f->glBlitFramebuffer(0, 0, cmd.
args.blitFromRenderbuffer.w, cmd.
args.blitFromRenderbuffer.h,
3649 0, 0, cmd.
args.blitFromRenderbuffer.w, cmd.
args.blitFromRenderbuffer.h,
3650 ds ? GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT : GL_COLOR_BUFFER_BIT,
3653 f->glDeleteFramebuffers(2, fbo);
3661 f->glDisable(GL_SCISSOR_TEST);
3663 f->glGenFramebuffers(2, fbo);
3665 const bool ds = cmd.
args.blitFromTexture.isDepthStencil;
3669 cmd.
args.blitFromTexture.srcTexture,
3670 cmd.
args.blitFromTexture.srcLevel,
3671 cmd.
args.blitFromTexture.srcLayer);
3673 cmd.
args.blitFromTexture.srcTexture,
3674 cmd.
args.blitFromTexture.srcLevel,
3675 cmd.
args.blitFromTexture.srcLayer);
3678 cmd.
args.blitFromTexture.srcTexture,
3679 cmd.
args.blitFromTexture.srcLevel,
3680 cmd.
args.blitFromTexture.srcLayer);
3685 cmd.
args.blitFromTexture.srcTexture, cmd.
args.blitFromTexture.srcLevel);
3687 cmd.
args.blitFromTexture.srcTexture, cmd.
args.blitFromTexture.srcLevel);
3690 cmd.
args.blitFromTexture.srcTexture, cmd.
args.blitFromTexture.srcLevel);
3697 cmd.
args.blitFromTexture.dstTexture,
3698 cmd.
args.blitFromTexture.dstLevel,
3699 cmd.
args.blitFromTexture.dstLayer);
3701 cmd.
args.blitFromTexture.dstTexture,
3702 cmd.
args.blitFromTexture.dstLevel,
3703 cmd.
args.blitFromTexture.dstLayer);
3706 cmd.
args.blitFromTexture.dstTexture,
3707 cmd.
args.blitFromTexture.dstLevel,
3708 cmd.
args.blitFromTexture.dstLayer);
3713 cmd.
args.blitFromTexture.dstTexture, cmd.
args.blitFromTexture.dstLevel);
3715 cmd.
args.blitFromTexture.dstTexture, cmd.
args.blitFromTexture.dstLevel);
3718 cmd.
args.blitFromTexture.dstTexture, cmd.
args.blitFromTexture.dstLevel);
3721 f->glBlitFramebuffer(0, 0, cmd.
args.blitFromTexture.w, cmd.
args.blitFromTexture.h,
3722 0, 0, cmd.
args.blitFromTexture.w, cmd.
args.blitFromTexture.h,
3723 ds ? GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT : GL_COLOR_BUFFER_BIT,
3726 f->glDeleteFramebuffers(2, fbo);
3730 f->glBindTexture(cmd.
args.genMip.target, cmd.
args.genMip.texture);
3731 f->glGenerateMipmap(cmd.
args.genMip.target);
3736 f->glUseProgram(psD->program);
3740 f->glDispatchCompute(cmd.
args.dispatch.x, cmd.
args.dispatch.y, cmd.
args.dispatch.z);
3755 for (
auto it = tracker.cbeginBuffers(), itEnd = tracker.cendBuffers();
it != itEnd; ++
it) {
3760 for (
auto it = tracker.cbeginTextures(), itEnd = tracker.cendTextures();
it != itEnd; ++
it) {
3766 f->glMemoryBarrier(barriers);
3771 f->glMemoryBarrier(cmd.
args.barrier.barriers);
3774 if (
caps.gles &&
caps.ctxMajor >= 3) {
3776 cmd.
args.invalidateFramebuffer.attCount,
3777 cmd.
args.invalidateFramebuffer.att);
3784 if (
state.instancedAttributesUsed) {
3786 if (
state.nonzeroAttribDivisor[
i])
3787 f->glVertexAttribDivisor(
GLuint(
i), 0);
3790 f->glVertexAttribDivisor(
GLuint(
i), 0);
3802 state.scissor = scissor;
3804 f->glEnable(GL_SCISSOR_TEST);
3806 f->glDisable(GL_SCISSOR_TEST);
3812 state.cullFace = cullFace;
3813 state.cullMode = cullMode;
3815 f->glEnable(GL_CULL_FACE);
3816 f->glCullFace(cullMode);
3818 f->glDisable(GL_CULL_FACE);
3824 state.frontFace = frontFace;
3825 f->glFrontFace(frontFace);
3830 state.polygonMode = polygonMode;
3831 glPolygonMode(GL_FRONT_AND_BACK, polygonMode);
3834 if (!psD->m_targetBlends.isEmpty()) {
3850 state.colorMask = colorMask;
3851 f->glColorMask(colorMask.
r, colorMask.
g, colorMask.
b, colorMask.
a);
3854 const bool blendEnabled = targetBlend.
enable;
3864 state.blendEnabled = blendEnabled;
3866 state.blend = blend;
3867 f->glEnable(GL_BLEND);
3871 f->glDisable(GL_BLEND);
3877 state.colorMask = colorMask;
3878 f->glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3880 const bool blendEnabled =
false;
3882 state.blendEnabled = blendEnabled;
3883 f->glDisable(GL_BLEND);
3887 const bool depthTest = psD->m_depthTest;
3889 state.depthTest = depthTest;
3891 f->glEnable(GL_DEPTH_TEST);
3893 f->glDisable(GL_DEPTH_TEST);
3896 const bool depthWrite = psD->m_depthWrite;
3898 state.depthWrite = depthWrite;
3899 f->glDepthMask(depthWrite);
3904 state.depthFunc = depthFunc;
3905 f->glDepthFunc(depthFunc);
3908 const bool stencilTest = psD->m_stencilTest;
3909 const GLuint stencilReadMask = psD->m_stencilReadMask;
3910 const GLuint stencilWriteMask = psD->m_stencilWriteMask;
3925 && (stencilReadMask !=
state.stencilReadMask || stencilWriteMask !=
state.stencilWriteMask
3926 || stencilFront !=
state.stencil[0] || stencilBack !=
state.stencil[1])))
3928 state.stencilTest = stencilTest;
3930 state.stencilReadMask = stencilReadMask;
3931 state.stencilWriteMask = stencilWriteMask;
3932 state.stencil[0] = stencilFront;
3933 state.stencil[1] = stencilBack;
3935 f->glEnable(GL_STENCIL_TEST);
3937 f->glStencilFuncSeparate(GL_FRONT, stencilFront.
func,
state.dynamic.stencilRef, stencilReadMask);
3939 f->glStencilMaskSeparate(GL_FRONT, stencilWriteMask);
3941 f->glStencilFuncSeparate(GL_BACK, stencilBack.
func,
state.dynamic.stencilRef, stencilReadMask);
3943 f->glStencilMaskSeparate(GL_BACK, stencilWriteMask);
3945 f->glDisable(GL_STENCIL_TEST);
3949 const bool polyOffsetFill = psD->m_depthBias != 0 || !
qFuzzyIsNull(psD->m_slopeScaledDepthBias);
3950 const float polyOffsetFactor = psD->m_slopeScaledDepthBias;
3951 const float polyOffsetUnits = psD->m_depthBias;
3953 || polyOffsetFactor !=
state.polyOffsetFactor || polyOffsetUnits !=
state.polyOffsetUnits)
3955 state.polyOffsetFill = polyOffsetFill;
3956 state.polyOffsetFactor = polyOffsetFactor;
3957 state.polyOffsetUnits = polyOffsetUnits;
3958 if (polyOffsetFill) {
3959 f->glPolygonOffset(polyOffsetFactor, polyOffsetUnits);
3960 f->glEnable(GL_POLYGON_OFFSET_FILL);
3962 f->glDisable(GL_POLYGON_OFFSET_FILL);
3967 const float lineWidth = psD->m_lineWidth;
3969 state.lineWidth = lineWidth;
3970 f->glLineWidth(lineWidth);
3975 const int cpCount = psD->m_patchControlPointCount;
3977 state.cpCount = cpCount;
3982 f->glUseProgram(psD->program);
3985template <
typename T>
3988 const T *
p =
reinterpret_cast<const T *
>(
src);
3989 for (
int i = 0;
i < elemCount; ++
i) {
3990 for (
int j = 0;
j < vecSize; ++
j)
3991 dst[vecSize *
i +
j] = *
p++;
3997 void *ps,
uint psGeneration,
int glslLocation,
3998 int *texUnit,
bool *activeTexUnitAltered)
4000 const bool samplerStateValid = texD->samplerState == samplerD->d;
4001 const bool cachedStateInRange = *texUnit < 16;
4002 bool updateTextureBinding =
true;
4003 if (samplerStateValid && cachedStateInRange) {
4015 updateTextureBinding =
false;
4018 if (updateTextureBinding) {
4020 *activeTexUnitAltered =
true;
4021 f->glBindTexture(texD->target, texD->texture);
4022 f->glUniform1i(glslLocation, *texUnit);
4023 if (cachedStateInRange) {
4030 if (!samplerStateValid) {
4031 f->glTexParameteri(texD->target, GL_TEXTURE_MIN_FILTER,
GLint(samplerD->d.glminfilter));
4032 f->glTexParameteri(texD->target, GL_TEXTURE_MAG_FILTER,
GLint(samplerD->d.glmagfilter));
4033 f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_S,
GLint(samplerD->d.glwraps));
4034 f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_T,
GLint(samplerD->d.glwrapt));
4037 if (
caps.textureCompareMode) {
4038 if (samplerD->d.gltexcomparefunc != GL_NEVER) {
4045 texD->samplerState = samplerD->d;
4052 const uint *dynOfsPairs,
int dynOfsCount)
4056 bool activeTexUnitAltered =
false;
4061 QVarLengthArray<data32_t, 256> packedArray;
4066 struct SeparateTexture {
4071 QVarLengthArray<SeparateTexture, 8> separateTextureBindings;
4072 struct SeparateSampler {
4076 QVarLengthArray<SeparateSampler, 4> separateSamplerBindings;
4078 for (
int i = 0, ie = srbD->m_bindings.size();
i != ie; ++
i) {
4084 int viewOffset =
b->u.ubuf.offset;
4085 for (
int j = 0;
j < dynOfsCount; ++
j) {
4086 if (dynOfsPairs[2 *
j] ==
uint(
b->binding)) {
4087 viewOffset = int(dynOfsPairs[2 *
j + 1]);
4092 const char *bufView = bufD->data.constData() + viewOffset;
4094 if (uniform.binding ==
b->binding) {
4097 const void *
src = bufView + uniform.offset;
4100 if (uniform.arrayDim > 0
4112 qWarning(
"Uniform with buffer binding %d, buffer offset %d, type %d is an array, "
4113 "but arrays are only supported for float, vec2, vec3, vec4, int, "
4114 "ivec2, ivec3, ivec4, mat3 and mat4. "
4115 "Only the first element will be set.",
4116 uniform.binding, uniform.offset, uniform.type);
4126 switch (uniform.type) {
4129 const int elemCount = uniform.arrayDim;
4130 if (elemCount < 1) {
4131 const float v = *
reinterpret_cast<const float *
>(
src);
4134 if (thisUniformState.componentCount != 1 || thisUniformState.v[0] !=
v) {
4135 thisUniformState.componentCount = 1;
4136 thisUniformState.v[0] =
v;
4137 f->glUniform1f(uniform.glslLocation,
v);
4140 f->glUniform1f(uniform.glslLocation,
v);
4144 packedArray.resize(elemCount);
4146 f->glUniform1fv(uniform.glslLocation, elemCount, &packedArray.constData()->f);
4152 const int elemCount = uniform.arrayDim;
4153 if (elemCount < 1) {
4154 const float *
v =
reinterpret_cast<const float *
>(
src);
4157 if (thisUniformState.componentCount != 2
4158 || thisUniformState.v[0] !=
v[0]
4159 || thisUniformState.v[1] !=
v[1])
4161 thisUniformState.componentCount = 2;
4162 thisUniformState.v[0] =
v[0];
4163 thisUniformState.v[1] =
v[1];
4164 f->glUniform2fv(uniform.glslLocation, 1,
v);
4167 f->glUniform2fv(uniform.glslLocation, 1,
v);
4170 packedArray.resize(elemCount * 2);
4172 f->glUniform2fv(uniform.glslLocation, elemCount, &packedArray.constData()->f);
4178 const int elemCount = uniform.arrayDim;
4179 if (elemCount < 1) {
4180 const float *
v =
reinterpret_cast<const float *
>(
src);
4183 if (thisUniformState.componentCount != 3
4184 || thisUniformState.v[0] !=
v[0]
4185 || thisUniformState.v[1] !=
v[1]
4186 || thisUniformState.v[2] !=
v[2])
4188 thisUniformState.componentCount = 3;
4189 thisUniformState.v[0] =
v[0];
4190 thisUniformState.v[1] =
v[1];
4191 thisUniformState.v[2] =
v[2];
4192 f->glUniform3fv(uniform.glslLocation, 1,
v);
4195 f->glUniform3fv(uniform.glslLocation, 1,
v);
4198 packedArray.resize(elemCount * 3);
4200 f->glUniform3fv(uniform.glslLocation, elemCount, &packedArray.constData()->f);
4206 const int elemCount = uniform.arrayDim;
4207 if (elemCount < 1) {
4208 const float *
v =
reinterpret_cast<const float *
>(
src);
4211 if (thisUniformState.componentCount != 4
4212 || thisUniformState.v[0] !=
v[0]
4213 || thisUniformState.v[1] !=
v[1]
4214 || thisUniformState.v[2] !=
v[2]
4215 || thisUniformState.v[3] !=
v[3])
4217 thisUniformState.componentCount = 4;
4218 thisUniformState.v[0] =
v[0];
4219 thisUniformState.v[1] =
v[1];
4220 thisUniformState.v[2] =
v[2];
4221 thisUniformState.v[3] =
v[3];
4222 f->glUniform4fv(uniform.glslLocation, 1,
v);
4225 f->glUniform4fv(uniform.glslLocation, 1,
v);
4228 f->glUniform4fv(uniform.glslLocation, elemCount,
reinterpret_cast<const float *
>(
src));
4233 f->glUniformMatrix2fv(uniform.glslLocation, 1, GL_FALSE,
reinterpret_cast<const float *
>(
src));
4237 const int elemCount = uniform.arrayDim;
4238 if (elemCount < 1) {
4241 const float *srcMat =
reinterpret_cast<const float *
>(
src);
4242 memcpy(mat, srcMat, 3 *
sizeof(
float));
4243 memcpy(mat + 3, srcMat + 4, 3 *
sizeof(
float));
4244 memcpy(mat + 6, srcMat + 8, 3 *
sizeof(
float));
4245 f->glUniformMatrix3fv(uniform.glslLocation, 1, GL_FALSE, mat);
4247 packedArray.resize(elemCount * 9);
4249 f->glUniformMatrix3fv(uniform.glslLocation, elemCount, GL_FALSE, &packedArray.constData()->f);
4254 f->glUniformMatrix4fv(uniform.glslLocation,
qMax(1, uniform.arrayDim), GL_FALSE,
reinterpret_cast<const float *
>(
src));
4258 const int elemCount = uniform.arrayDim;
4259 if (elemCount < 1) {
4260 f->glUniform1i(uniform.glslLocation, *
reinterpret_cast<const qint32 *
>(
src));
4262 packedArray.resize(elemCount);
4264 f->glUniform1iv(uniform.glslLocation, elemCount, &packedArray.constData()->i);
4270 const int elemCount = uniform.arrayDim;
4271 if (elemCount < 1) {
4272 f->glUniform2iv(uniform.glslLocation, 1,
reinterpret_cast<const qint32 *
>(
src));
4274 packedArray.resize(elemCount * 2);
4276 f->glUniform2iv(uniform.glslLocation, elemCount, &packedArray.constData()->i);
4282 const int elemCount = uniform.arrayDim;
4283 if (elemCount < 1) {
4284 f->glUniform3iv(uniform.glslLocation, 1,
reinterpret_cast<const qint32 *
>(
src));
4286 packedArray.resize(elemCount * 3);
4288 f->glUniform3iv(uniform.glslLocation, elemCount, &packedArray.constData()->i);
4293 f->glUniform4iv(uniform.glslLocation,
qMax(1, uniform.arrayDim),
reinterpret_cast<const qint32 *
>(
src));
4296 f->glUniform1ui(uniform.glslLocation, *
reinterpret_cast<const quint32 *
>(
src));
4299 f->glUniform2uiv(uniform.glslLocation, 1,
reinterpret_cast<const quint32 *
>(
src));
4302 f->glUniform3uiv(uniform.glslLocation, 1,
reinterpret_cast<const quint32 *
>(
src));
4305 f->glUniform4uiv(uniform.glslLocation, 1,
reinterpret_cast<const quint32 *
>(
src));
4308 f->glUniform1i(uniform.glslLocation, *
reinterpret_cast<const qint32 *
>(
src));
4311 f->glUniform2iv(uniform.glslLocation, 1,
reinterpret_cast<const qint32 *
>(
src));
4314 f->glUniform3iv(uniform.glslLocation, 1,
reinterpret_cast<const qint32 *
>(
src));
4317 f->glUniform4iv(uniform.glslLocation, 1,
reinterpret_cast<const qint32 *
>(
src));
4320 qWarning(
"Uniform with buffer binding %d, buffer offset %d has unsupported type %d",
4321 uniform.binding, uniform.offset, uniform.type);
4334 if (maybeGraphicsPs) {
4335 ps = maybeGraphicsPs;
4338 ps = maybeComputePs;
4341 for (
int elem = 0; elem <
b->u.stex.count; ++elem) {
4345 if (shaderSampler.combinedBinding ==
b->binding) {
4346 const int loc = shaderSampler.glslLocation + elem;
4347 bindCombinedSampler(cbD, texD, samplerD, ps, psGeneration, loc, &texUnit, &activeTexUnitAltered);
4355 for (
int elem = 0; elem <
b->u.stex.count; ++elem) {
4357 separateTextureBindings.append({ texD,
b->binding, elem });
4363 separateSamplerBindings.append({ samplerD,
b->binding });
4378 f->glBindImageTexture(
GLuint(
b->binding), texD->texture,
4380 access, texD->glsizedintformat);
4389 if (
b->u.sbuf.offset == 0 &&
b->u.sbuf.maybeSize == 0)
4393 b->u.sbuf.offset,
b->u.sbuf.maybeSize ?
b->u.sbuf.maybeSize : bufD->m_size);
4402 if (!separateTextureBindings.isEmpty() || !separateSamplerBindings.isEmpty()) {
4407 if (maybeGraphicsPs) {
4408 ps = maybeGraphicsPs;
4411 ps = maybeComputePs;
4415 if (shaderSampler.combinedBinding >= 0)
4417 for (
const SeparateSampler &sepSampler : separateSamplerBindings) {
4418 if (sepSampler.binding != shaderSampler.sbinding)
4420 for (
const SeparateTexture &sepTex : separateTextureBindings) {
4421 if (sepTex.binding != shaderSampler.tbinding)
4423 const int loc = shaderSampler.glslLocation + sepTex.elem;
4425 loc, &texUnit, &activeTexUnitAltered);
4431 if (activeTexUnitAltered)
4443 bool *wantsColorClear,
bool *wantsDsClear)
4457 if (wantsColorClear)
4458 *wantsColorClear = doClearBuffers && doClearColorBuffer;
4460 *wantsDsClear = doClearBuffers;
4461 fbCmd.args.bindFramebuffer.fbo = 0;
4462 fbCmd.args.bindFramebuffer.colorAttCount = 1;
4463 fbCmd.args.bindFramebuffer.stereo = rtD->stereoTarget.has_value();
4464 if (fbCmd.args.bindFramebuffer.stereo)
4465 fbCmd.args.bindFramebuffer.stereoTarget = rtD->stereoTarget.value();
4471 if (wantsColorClear)
4475 fbCmd.args.bindFramebuffer.fbo = rtTex->framebuffer;
4476 fbCmd.args.bindFramebuffer.colorAttCount = rtD->colorAttCount;
4477 fbCmd.args.bindFramebuffer.stereo =
false;
4479 for (
auto it = rtTex->m_desc.cbeginColorAttachments(), itEnd = rtTex->m_desc.cendColorAttachments();
4510 fbCmd.args.bindFramebuffer.srgb = rtD->srgbUpdateAndBlend;
4526 const QColor &colorClearValue,
4529 QRhiCommandBuffer::BeginPassFlags
flags)
4534 if (resourceUpdates)
4543 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QGles2Texture, QGles2RenderBuffer>(rtTex->description(), rtTex->d.currentResIdList))
4547 bool wantsColorClear, wantsDsClear;
4552 clearCmd.args.clear.mask = 0;
4553 if (rtD->colorAttCount && wantsColorClear)
4554 clearCmd.args.clear.mask |= GL_COLOR_BUFFER_BIT;
4555 if (rtD->dsAttCount && wantsDsClear)
4556 clearCmd.args.clear.mask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
4557 clearCmd.args.clear.c[0] = float(colorClearValue.redF());
4558 clearCmd.args.clear.c[1] = float(colorClearValue.greenF());
4559 clearCmd.args.clear.c[2] = float(colorClearValue.blueF());
4560 clearCmd.args.clear.c[3] = float(colorClearValue.alphaF());
4561 clearCmd.args.clear.d = depthStencilClearValue.depthClearValue();
4562 clearCmd.args.clear.s = depthStencilClearValue.stencilClearValue();
4578 for (
auto it = rtTex->m_desc.cbeginColorAttachments(), itEnd = rtTex->m_desc.cendColorAttachments();
4586 const QSize size = resolveTexD->pixelSize();
4589 if (rbD->pixelSize() !=
size) {
4590 qWarning(
"Resolve source (%dx%d) and target (%dx%d) size does not match",
4591 rbD->pixelSize().width(), rbD->pixelSize().height(),
size.width(),
size.height());
4595 cmd.
args.blitFromRenderbuffer.renderbuffer = rbD->renderbuffer;
4596 cmd.
args.blitFromRenderbuffer.w =
size.width();
4597 cmd.
args.blitFromRenderbuffer.h =
size.height();
4601 cmd.
args.blitFromRenderbuffer.target = resolveTexD->target;
4602 cmd.
args.blitFromRenderbuffer.dstTexture = resolveTexD->texture;
4606 cmd.
args.blitFromRenderbuffer.dstLayer = hasZ ? colorAtt.
resolveLayer() : 0;
4607 cmd.
args.blitFromRenderbuffer.isDepthStencil =
false;
4608 }
else if (
caps.glesMultisampleRenderToTexture) {
4614 if (texD->pixelSize() !=
size) {
4615 qWarning(
"Resolve source (%dx%d) and target (%dx%d) size does not match",
4616 texD->pixelSize().width(), texD->pixelSize().height(),
size.width(),
size.height());
4619 for (
int resolveIdx = 0; resolveIdx < resolveCount; ++resolveIdx) {
4620 const int srcLayer = colorAtt.
layer() + resolveIdx;
4621 const int dstLayer = colorAtt.
resolveLayer() + resolveIdx;
4627 cmd.
args.blitFromTexture.srcTarget = texD->target;
4628 cmd.
args.blitFromTexture.srcTexture = texD->texture;
4629 cmd.
args.blitFromTexture.srcLevel = colorAtt.
level();
4630 cmd.
args.blitFromTexture.srcLayer = 0;
4632 cmd.
args.blitFromTexture.srcLayer = srcLayer;
4633 cmd.
args.blitFromTexture.w =
size.width();
4634 cmd.
args.blitFromTexture.h =
size.height();
4638 cmd.
args.blitFromTexture.dstTarget = resolveTexD->target;
4639 cmd.
args.blitFromTexture.dstTexture = resolveTexD->texture;
4641 cmd.
args.blitFromTexture.dstLayer = 0;
4643 cmd.
args.blitFromTexture.dstLayer = dstLayer;
4644 cmd.
args.blitFromTexture.isDepthStencil =
false;
4649 if (rtTex->m_desc.depthResolveTexture()) {
4651 const QSize size = depthResolveTexD->pixelSize();
4652 if (rtTex->m_desc.depthStencilBuffer()) {
4656 cmd.
args.blitFromRenderbuffer.renderbuffer = rbD->renderbuffer;
4657 cmd.
args.blitFromRenderbuffer.w =
size.width();
4658 cmd.
args.blitFromRenderbuffer.h =
size.height();
4659 cmd.
args.blitFromRenderbuffer.target = depthResolveTexD->target;
4660 cmd.
args.blitFromRenderbuffer.dstTexture = depthResolveTexD->texture;
4661 cmd.
args.blitFromRenderbuffer.dstLevel = 0;
4662 cmd.
args.blitFromRenderbuffer.dstLayer = 0;
4663 cmd.
args.blitFromRenderbuffer.isDepthStencil =
true;
4664 }
else if (
caps.glesMultisampleRenderToTexture) {
4668 const int resolveCount = depthTexD->arraySize() >= 2 ? depthTexD->arraySize() : 1;
4669 for (
int resolveIdx = 0; resolveIdx < resolveCount; ++resolveIdx) {
4672 cmd.
args.blitFromTexture.srcTarget = depthTexD->target;
4673 cmd.
args.blitFromTexture.srcTexture = depthTexD->texture;
4674 cmd.
args.blitFromTexture.srcLevel = 0;
4675 cmd.
args.blitFromTexture.srcLayer = resolveIdx;
4676 cmd.
args.blitFromTexture.w =
size.width();
4677 cmd.
args.blitFromTexture.h =
size.height();
4678 cmd.
args.blitFromTexture.dstTarget = depthResolveTexD->target;
4679 cmd.
args.blitFromTexture.dstTexture = depthResolveTexD->texture;
4680 cmd.
args.blitFromTexture.dstLevel = 0;
4681 cmd.
args.blitFromTexture.dstLayer = resolveIdx;
4682 cmd.
args.blitFromTexture.isDepthStencil =
true;
4687 const bool mayDiscardDepthStencil =
4688 (rtTex->m_desc.depthStencilBuffer()
4690 && !rtTex->m_desc.depthResolveTexture();
4691 if (mayDiscardDepthStencil) {
4694 if (
caps.needsDepthStencilCombinedAttach) {
4695 cmd.
args.invalidateFramebuffer.attCount = 1;
4698 cmd.
args.invalidateFramebuffer.attCount = 2;
4708 if (resourceUpdates)
4714 QRhiCommandBuffer::BeginPassFlags)
4719 if (resourceUpdates)
4736 if (resourceUpdates)
4747 if (pipelineChanged) {
4754 cmd.
args.bindComputePipeline.ps = ps;
4761 int loadTypeVal,
int storeTypeVal,
int loadStoreTypeVal)
4764 if (bindingType == loadTypeVal) {
4768 if (bindingType == loadStoreTypeVal)
4771 auto it = writtenResources->find(resource);
4772 if (
it != writtenResources->end())
4774 else if (bindingType == storeTypeVal || bindingType == loadStoreTypeVal)
4775 writtenResources->insert(resource, {
access,
true });
4790 accessAndIsNewFlag = { 0,
false };
4793 const int bindingCount = srbD->m_bindings.size();
4794 for (
int i = 0;
i < bindingCount; ++
i) {
4823 const int accessInThisDispatch =
it->first;
4824 const bool isNewInThisDispatch =
it->second;
4825 if (accessInThisDispatch && !isNewInThisDispatch) {
4843 cmd.
args.barrier.barriers = barriers;
4877 QList<int> versionsToTry;
4880 if (
caps.ctxMajor > 3 || (
caps.ctxMajor == 3 &&
caps.ctxMinor >= 2)) {
4881 versionsToTry << 320 << 310 << 300 << 100;
4882 }
else if (
caps.ctxMajor == 3 &&
caps.ctxMinor == 1) {
4883 versionsToTry << 310 << 300 << 100;
4884 }
else if (
caps.ctxMajor == 3 &&
caps.ctxMinor == 0) {
4885 versionsToTry << 300 << 100;
4887 versionsToTry << 100;
4889 for (
int v : versionsToTry) {
4894 *shaderVersion = ver;
4899 if (
caps.ctxMajor > 4 || (
caps.ctxMajor == 4 &&
caps.ctxMinor >= 6)) {
4900 versionsToTry << 460 << 450 << 440 << 430 << 420 << 410 << 400 << 330 << 150 << 140 << 130;
4901 }
else if (
caps.ctxMajor == 4 &&
caps.ctxMinor == 5) {
4902 versionsToTry << 450 << 440 << 430 << 420 << 410 << 400 << 330 << 150 << 140 << 130;
4903 }
else if (
caps.ctxMajor == 4 &&
caps.ctxMinor == 4) {
4904 versionsToTry << 440 << 430 << 420 << 410 << 400 << 330 << 150 << 140 << 130;
4905 }
else if (
caps.ctxMajor == 4 &&
caps.ctxMinor == 3) {
4906 versionsToTry << 430 << 420 << 410 << 400 << 330 << 150 << 140 << 130;
4907 }
else if (
caps.ctxMajor == 4 &&
caps.ctxMinor == 2) {
4908 versionsToTry << 420 << 410 << 400 << 330 << 150 << 140 << 130;
4909 }
else if (
caps.ctxMajor == 4 &&
caps.ctxMinor == 1) {
4910 versionsToTry << 410 << 400 << 330 << 150 << 140 << 130;
4911 }
else if (
caps.ctxMajor == 4 &&
caps.ctxMinor == 0) {
4912 versionsToTry << 400 << 330 << 150 << 140 << 130;
4913 }
else if (
caps.ctxMajor == 3 &&
caps.ctxMinor == 3) {
4914 versionsToTry << 330 << 150 << 140 << 130;
4915 }
else if (
caps.ctxMajor == 3 &&
caps.ctxMinor == 2) {
4916 versionsToTry << 150 << 140 << 130;
4917 }
else if (
caps.ctxMajor == 3 &&
caps.ctxMinor == 1) {
4918 versionsToTry << 140 << 130;
4919 }
else if (
caps.ctxMajor == 3 &&
caps.ctxMinor == 0) {
4920 versionsToTry << 130;
4922 if (!
caps.coreProfile)
4923 versionsToTry << 120;
4924 for (
int v : versionsToTry) {
4934 qWarning() <<
"No GLSL shader code found (versions tried: " << versionsToTry
4935 <<
") in baked shader" << bakedShader;
4952 const char *srcStr =
source.constData();
4954 f->glShaderSource(
shader, 1, &srcStr, &srcLength);
4959 GLint infoLogLength = 0;
4962 if (infoLogLength > 1) {
4964 log.
resize(infoLogLength);
4990 GLint infoLogLength = 0;
4993 if (infoLogLength > 1) {
4995 log.
resize(infoLogLength);
5009 QDuplicateTracker<int, 256> *activeUniformLocations,
5013 qWarning(
"Nested structs are not supported at the moment. '%s' ignored.",
5025 uniform.glslLocation =
f->glGetUniformLocation(
program,
name.constData());
5026 if (uniform.glslLocation >= 0 && !activeUniformLocations->hasSeen(uniform.glslLocation)) {
5027 if (
var.arrayDims.size() > 1) {
5028 qWarning(
"Array '%s' has more than one dimension. This is not supported.",
5032 uniform.binding = binding;
5033 uniform.offset =
uint(baseOffset +
var.offset);
5034 uniform.size =
var.size;
5035 uniform.arrayDim =
var.arrayDims.isEmpty() ? 0 :
var.arrayDims.first();
5036 dst->append(uniform);
5042 QDuplicateTracker<int, 256> *activeUniformLocations,
5048 QByteArray structPrefix = prefix + blockMember.name;
5050 const int baseOffset = blockMember.offset;
5051 if (blockMember.arrayDims.isEmpty()) {
5054 baseOffset,
program, activeUniformLocations,
dst);
5056 if (blockMember.arrayDims.size() > 1) {
5057 qWarning(
"Array of struct '%s' has more than one dimension. Only the first "
5058 "dimension is used.",
5059 blockMember.name.constData());
5061 const int dim = blockMember.arrayDims.first();
5062 const int elemSize = blockMember.size / dim;
5063 int elemOffset = baseOffset;
5064 for (
int di = 0; di < dim; ++di) {
5068 elemOffset += elemSize;
5083 if (
sampler.glslLocation >= 0) {
5084 sampler.combinedBinding =
v.binding;
5097 if (
sampler.glslLocation >= 0) {
5107 if (!vsDesc.isValid() || !fsDesc.isValid())
5116 if (inVar.location == outVar.location) {
5117 if (inVar.name != outVar.name) {
5118 qWarning(
"Vertex output name '%s' does not match fragment input '%s'. "
5119 "This should be avoided because it causes problems with older GLSL versions.",
5120 outVar.name.constData(), inVar.name.constData());
5159 const QVector<QShaderDescription::InOutVariable> &inputVars,
5171 if (legacyDiskCacheEnabled || pipelineCacheEnabled) {
5173 for (
int i = 0;
i < stageCount; ++
i) {
5196 QMap<QByteArray, int> inputLocations;
5198 inputLocations.insert(
var.name,
var.location);
5200 for (
auto it = inputLocations.
cbegin(),
end = inputLocations.cend();
it !=
end; ++
it) {
5215 if (pipelineCacheEnabled) {
5220 err =
f->glGetError();
5225 err =
f->glGetError();
5226 if (err == GL_NO_ERROR) {
5227 GLint linkStatus = 0;
5229 if (linkStatus == GL_TRUE)
5237 qCDebug(lcOpenGLProgramDiskCache,
"Program binary received from cache, program %u, key %s",
5252 qCDebug(lcOpenGLProgramDiskCache,
"Saving program binary, program %u, key %s",
5270 if (blobSize == outSize)
5299 rhiD->releaseQueue.append(e);
5300 rhiD->unregisterResource(
this);
5315 qWarning(
"Uniform buffer: multiple usages specified, this is not supported by the OpenGL backend");
5322 if (!rhiD->ensureContext())
5331 rhiD->f->glGenBuffers(1, &
buffer);
5335 if (rhiD->glObjectLabel)
5340 rhiD->registerResource(
this);
5349 return { { &
buffer }, 1 };
5358 if (rhiD->caps.properMapBuffer) {
5374 if (rhiD->caps.properMapBuffer)
5382 int sampleCount, QRhiRenderBuffer::Flags
flags,
5410 rhiD->releaseQueue.append(e);
5411 rhiD->unregisterResource(
this);
5427 qWarning(
"RenderBuffer: UsedWithSwapChainOnly is meaningless in combination with Color");
5430 if (!rhiD->ensureContext())
5440 if (rhiD->caps.msaaRenderBuffer &&
samples > 1) {
5444 }
else if (rhiD->caps.packedDepthStencil || rhiD->caps.needsDepthStencilCombinedAttach) {
5450 GLenum depthStorage = GL_DEPTH_COMPONENT;
5451 if (rhiD->caps.gles) {
5452 if (rhiD->caps.depth24)
5469 if (rhiD->caps.rgba8Format) {
5472 GLenum glintformat, glformat, gltype;
5478 if (rhiD->caps.msaaRenderBuffer &&
samples > 1) {
5492 if (rhiD->glObjectLabel)
5497 rhiD->registerResource(
this);
5513 qWarning(
"RenderBuffer: UsedWithSwapChainOnly is meaningless when importing an existing native object");
5515 if (!rhiD->ensureContext())
5522 rhiD->registerResource(
this);
5562 rhiD->releaseQueue.append(e);
5563 rhiD->unregisterResource(
this);
5573 if (!rhiD->ensureContext())
5580 const bool isCompressed = rhiD->isCompressedFormat(
m_format);
5586 if (is3D && !rhiD->caps.texture3D) {
5587 qWarning(
"3D textures are not supported");
5590 if (isCube && is3D) {
5591 qWarning(
"Texture cannot be both cube and 3D");
5594 if (isArray && is3D) {
5595 qWarning(
"Texture cannot be both array and 3D");
5598 if (is1D && !rhiD->caps.texture1D) {
5599 qWarning(
"1D textures are not supported");
5603 qWarning(
"Texture cannot be both 1D and 3D");
5606 if (is1D && isCube) {
5607 qWarning(
"Texture cannot be both 1D and cube");
5612 qWarning(
"Texture cannot have a depth of %d when it is not 3D",
m_depth);
5640 qWarning(
"Compressed texture cannot be used with image load/store");
5645 qWarning(
"Compressed format %d not mappable to GL compressed format",
m_format);
5660 *adjustedSize =
size;
5672 rhiD->f->glGenTextures(1, &
texture);
5678 const bool isCompressed = rhiD->isCompressedFormat(
m_format);
5681 if (!isCompressed) {
5694 }
else if (is3D || isArray) {
5706 }
else if (hasMipMaps || isCube) {
5708 for (
int layer = 0, layerCount = isCube ? 6 : 1;
layer != layerCount; ++
layer) {
5712 mipSize.width(), mipSize.height(), 0,
5722 size.width(),
size.height(), GL_TRUE);
5732 if (is1D && !isArray)
5734 else if (!is1D && (is3D || isArray))
5739 size.width(),
size.height(), GL_TRUE);
5752 if (rhiD->glObjectLabel)
5758 rhiD->registerResource(
this);
5779 rhiD->registerResource(
this);
5790 :
QRhiSampler(rhi, magFilter, minFilter, mipmapMode, u,
v,
w)
5803 rhiD->unregisterResource(
this);
5817 rhiD->registerResource(
this,
false);
5836 rhiD->unregisterResource(
this);
5849 rhiD->registerResource(rpD,
false);
5918 rhiD->releaseQueue.append(e);
5919 rhiD->unregisterResource(
this);
5927 rhiD->registerResource(rpD,
false);
5943 if (hasColorAttachments) {
5945 if (
count > rhiD->caps.maxDrawBuffers) {
5946 qWarning(
"QGles2TextureRenderTarget: Too many color attachments (%d, max is %d)",
5947 count, rhiD->caps.maxDrawBuffers);
5951 qWarning(
"QGles2TextureRenderTarget: Depth texture is not supported and will be ignored");
5953 if (!rhiD->ensureContext())
5961 int multiViewCount = 0;
5970 Q_ASSERT(texD->texture && texD->specified);
5977 if (texD->sampleCount() > 1 && rhiD->caps.glesMultiviewMultisampleRenderToTexture && colorAtt.
resolveTexture()) {
5983 rhiD->glFramebufferTextureMultisampleMultiviewOVR(
GL_FRAMEBUFFER,
5985 resolveTexD->texture,
5987 texD->sampleCount(),
6001 texD->target +
uint(colorAtt.
layer()), texD->texture,
6004 if (texD->sampleCount() > 1 && rhiD->caps.glesMultisampleRenderToTexture && colorAtt.
resolveTexture()) {
6012 resolveTexD->texture, colorAtt.
level(), texD->sampleCount());
6016 texD->texture, colorAtt.
level());
6019 if (attIndex == 0) {
6020 d.
pixelSize = rhiD->q->sizeForMipLevel(colorAtt.
level(), texD->pixelSize());
6023 }
else if (renderBuffer) {
6026 if (attIndex == 0) {
6033 if (hasDepthStencil) {
6036 if (rhiD->caps.needsDepthStencilCombinedAttach) {
6038 depthRbD->renderbuffer);
6041 depthRbD->renderbuffer);
6042 if (depthRbD->stencilRenderbuffer) {
6044 depthRbD->stencilRenderbuffer);
6048 depthRbD->renderbuffer);
6057 if (multiViewCount < 2) {
6064 depthResolveTexD->texture, 0, depthTexD->sampleCount());
6065 if (rhiD->isStencilSupportingFormat(depthResolveTexD->format())) {
6067 depthResolveTexD->texture, 0, depthTexD->sampleCount());
6071 depthTexD->texture, 0);
6072 if (rhiD->isStencilSupportingFormat(depthTexD->format())) {
6074 depthTexD->texture, 0);
6078 if (depthTexD->sampleCount() > 1 && rhiD->caps.glesMultiviewMultisampleRenderToTexture) {
6097 qWarning(
"Attempted to create a multiview+multisample QRhiTextureRenderTarget, but DoNotStoreDepthStencilContents was not set."
6098 " This path has no choice but to behave as if DoNotStoreDepthStencilContents was set, because QRhi is forced to create"
6099 " a throwaway non-multisample depth texture here. Set the flag to silence this warning, or set a depthResolveTexture.");
6103 rhiD->glFramebufferTextureMultisampleMultiviewOVR(
GL_FRAMEBUFFER,
6105 depthResolveTexD->texture,
6107 depthTexD->sampleCount(),
6110 if (rhiD->isStencilSupportingFormat(depthResolveTexD->format())) {
6111 rhiD->glFramebufferTextureMultisampleMultiviewOVR(
GL_FRAMEBUFFER,
6113 depthResolveTexD->texture,
6115 depthTexD->sampleCount(),
6124 depthTexD->pixelSize().width(), depthTexD->pixelSize().height(), multiViewCount);
6126 rhiD->glFramebufferTextureMultisampleMultiviewOVR(
GL_FRAMEBUFFER,
6130 depthTexD->sampleCount(),
6133 rhiD->glFramebufferTextureMultisampleMultiviewOVR(
GL_FRAMEBUFFER,
6137 depthTexD->sampleCount(),
6146 0, 0, multiViewCount);
6147 if (rhiD->isStencilSupportingFormat(depthTexD->format())) {
6149 0, 0, multiViewCount);
6168 qWarning(
"Framebuffer incomplete: 0x%x", status);
6172 if (rhiD->glObjectLabel)
6175 QRhiRenderTargetAttachmentTracker::updateResIdList<QGles2Texture, QGles2RenderBuffer>(
m_desc, &
d.
currentResIdList);
6177 rhiD->registerResource(
this);
6183 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QGles2Texture, QGles2RenderBuffer>(
m_desc,
d.
currentResIdList))
6213 rhiD->unregisterResource(
this);
6219 if (!rhiD->sanityCheckShaderResourceBindings(
this))
6226 if (
b->u.ubuf.hasDynamicOffset) {
6233 rhiD->updateLayoutDesc(
this);
6236 rhiD->registerResource(
this,
false);
6272 rhiD->releaseQueue.append(e);
6273 rhiD->unregisterResource(
this);
6294 if (!rhiD->ensureContext())
6297 rhiD->pipelineCreationStart();
6298 if (!rhiD->sanityCheckGraphicsPipeline(
this))
6303 program = rhiD->f->glCreateProgram();
6314 switch (shaderStage.type()) {
6328 Q_UNREACHABLE_RETURN(VtxIdx);
6332 bool vertexFragmentOnly =
true;
6335 const int idx = descIdxForStage(shaderStage);
6336 if (idx != VtxIdx && idx != FragIdx)
6337 vertexFragmentOnly =
false;
6340 desc[idx] =
shader.description();
6341 if (!rhiD->shaderSource(shaderStage, &shaderVersion).isEmpty()) {
6342 samplerMappingList[idx] =
shader.separateToCombinedImageSamplerMappingList(
6352 desc[VtxIdx].inputVariables(),
6360 if (!rhiD->compileShader(
program, shaderStage,
nullptr))
6367 rhiD->f->glBindAttribLocation(
program,
GLuint(inVar.location), inVar.name);
6369 if (vertexFragmentOnly)
6370 rhiD->sanityCheckVertexFragmentInterface(desc[VtxIdx], desc[FragIdx]);
6372 if (!rhiD->linkProgram(
program))
6396 QDuplicateTracker<int, 256> activeUniformLocations;
6400 const int idx = descIdxForStage(shaderStage);
6402 rhiD->gatherUniforms(
program, ub, &activeUniformLocations, &
uniforms);
6413 return a.offset < b.offset;
6421 if (rhiD->glObjectLabel)
6424 rhiD->pipelineCreationEnd();
6426 rhiD->registerResource(
this);
6456 rhiD->releaseQueue.append(e);
6457 rhiD->unregisterResource(
this);
6468 if (!rhiD->ensureContext())
6471 rhiD->pipelineCreationStart();
6476 if (!rhiD->shaderSource(
m_shaderStage, &shaderVersion).isEmpty()) {
6481 program = rhiD->f->glCreateProgram();
6492 if (!rhiD->linkProgram(
program))
6513 QDuplicateTracker<int, 256> activeUniformLocations;
6515 rhiD->gatherUniforms(
program, ub, &activeUniformLocations, &
uniforms);
6528 rhiD->pipelineCreationEnd();
6530 rhiD->registerResource(
this);
6568 rhiD->unregisterResource(
this);
6588 Q_UNREACHABLE_RETURN(
nullptr);
6597 return platformWindow->geometry().size() * platformWindow->devicePixelRatio();
6611 rhiD->registerResource(rpD,
false);
6663 if (needsRegistration)
6664 rhiD->registerResource(
this,
false);
6698 rhiD->glGetQueryObjectui64v(tsStart,
GL_QUERY_RESULT, ×tamps[0]);
6701 if (timestamps[1] >= timestamps[0]) {
6702 const quint64 nanoseconds = timestamps[1] - timestamps[0];
6703 *elapsedSec = nanoseconds / 1000000000.0;
6707 active[pairIndex] =
false;
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
void resize(qsizetype size)
Sets the size of the byte array to size bytes.
The QColor class provides colors based on RGB, HSV or CMYK values.
qsizetype size() const noexcept
Returns the number of items in the hash.
const_iterator constFind(const Key &key) const noexcept
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
bool isEmpty() const noexcept
void append(parameter_type t)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void setFormat(const QSurfaceFormat &format)
Sets the offscreen surface format.
QOpenGLContext * shareContext() const
Returns the share context this context was created with.
void setFormat(const QSurfaceFormat &format)
Sets the format the OpenGL context should be compatible with.
static QOpenGLContext * currentContext()
Returns the last context which called makeCurrent in the current thread, or \nullptr,...
QScreen * screen() const
Returns the screen the context was created for.
QOpenGLProgramBinarySupportCheck * get(QOpenGLContext *context)
\inmodule QtCore\reentrant
constexpr bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
const char * constData() const
Type
Specifies storage type of buffer resource.
QRhiRenderBuffer * renderBuffer() const
int multiViewCount() const
QRhiTexture * texture() const
QRhiTexture * resolveTexture() const
@ DoNotTrackResourcesForCompute
QPair< int, quint32 > DynamicOffset
Synonym for QPair<int, quint32>.
QPair< QRhiBuffer *, quint32 > VertexInput
Synonym for QPair<QRhiBuffer *, quint32>.
IndexFormat
Specifies the index data type.
QRhiShaderStage m_shaderStage
\variable QRhiGles2InitParams::format
QHash< QRhiShaderStage, uint > m_shaderCache
QRhiStats statistics() override
void gatherUniforms(GLuint program, const QShaderDescription::UniformBlock &ub, QDuplicateTracker< int, 256 > *activeUniformLocations, QGles2UniformDescriptionVector *dst)
void registerUniformIfActive(const QShaderDescription::BlockVariable &var, const QByteArray &namePrefix, int binding, int baseOffset, GLuint program, QDuplicateTracker< int, 256 > *activeUniformLocations, QGles2UniformDescriptionVector *dst)
const GLvoid const GLvoid GLuint
void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance) override
QOpenGLContext * maybeShareContext
void trackedBufferBarrier(QGles2CommandBuffer *cbD, QGles2Buffer *bufD, QGles2Buffer::Access access)
QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override
void enqueueBarriersForPass(QGles2CommandBuffer *cbD)
QList< DeferredReleaseEntry > releaseQueue
int resourceLimit(QRhi::ResourceLimit limit) const override
void setVertexInput(QRhiCommandBuffer *cb, int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat) override
bool isFeatureSupported(QRhi::Feature feature) const override
QRhiGraphicsPipeline * createGraphicsPipeline() override
void bindShaderResources(QGles2CommandBuffer *cbD, QRhiGraphicsPipeline *maybeGraphicsPs, QRhiComputePipeline *maybeComputePs, QRhiShaderResourceBindings *srb, const uint *dynOfsPairs, int dynOfsCount)
bool create(QRhi::Flags flags) override
void trackedRegisterTexture(QRhiPassResourceTracker *passResTracker, QGles2Texture *texD, QRhiPassResourceTracker::TextureAccess access, QRhiPassResourceTracker::TextureStage stage)
void executeBindGraphicsPipeline(QGles2CommandBuffer *cbD, QGles2GraphicsPipeline *psD)
QRhiDriverInfo driverInfo() const override
QSurfaceFormat requestedFormat
QHash< QByteArray, PipelineCacheData > m_pipelineCache
bool isProgramBinaryDiskCacheEnabled() const
bool needsMakeCurrentDueToSwap
void trackedImageBarrier(QGles2CommandBuffer *cbD, QGles2Texture *texD, QGles2Texture::Access access)
void trackedRegisterBuffer(QRhiPassResourceTracker *passResTracker, QGles2Buffer *bufD, QRhiPassResourceTracker::BufferAccess access, QRhiPassResourceTracker::BufferStage stage)
QRhiComputePipeline * createComputePipeline() override
QRhiDriverInfo driverInfoStruct
QSurface * evaluateFallbackSurface() const
void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
void sanityCheckVertexFragmentInterface(const QShaderDescription &vsDesc, const QShaderDescription &fsDesc)
QRhiGles2NativeHandles nativeHandlesStruct
QMatrix4x4 clipSpaceCorrMatrix() const override
QRhi::FrameOpResult finish() override
void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override
QList< int > supportedSampleCounts() const override
void gatherSamplers(GLuint program, const QShaderDescription::InOutVariable &v, QGles2SamplerDescriptionVector *dst)
QSet< GLint > supportedCompressedFormats
QRhiSwapChain * createSwapChain() override
void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override
QRhiRenderBuffer * createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint) override
void executeCommandBuffer(QRhiCommandBuffer *cb)
void setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline *ps) override
QSurface * fallbackSurface
QRhiGles2(QRhiGles2InitParams *params, QRhiGles2NativeHandles *importDevice=nullptr)
void trySaveToDiskCache(GLuint program, const QByteArray &cacheKey)
struct QRhiGles2::Caps caps
bool compileShader(GLuint program, const QRhiShaderStage &shaderStage, QShaderVersion *shaderVersion)
QRhiTexture * createTexture(QRhiTexture::Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, QRhiTexture::Flags flags) override
void bindCombinedSampler(QGles2CommandBuffer *cbD, QGles2Texture *texD, QGles2Sampler *samplerD, void *ps, uint psGeneration, int glslLocation, int *texUnit, bool *activeTexUnitAltered)
void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override
QRhiTextureRenderTarget * createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags) override
QRhiSampler * createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w) override
void beginPass(QRhiCommandBuffer *cb, QRhiRenderTarget *rt, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
QGles2SwapChain * currentSwapChain
bool isDeviceLost() const override
QRhiShaderResourceBindings * createShaderResourceBindings() override
bool isYUpInNDC() const override
void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override
void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
bool makeThreadLocalNativeContextCurrent() override
int ubufAlignment() const override
void beginExternal(QRhiCommandBuffer *cb) override
void endExternal(QRhiCommandBuffer *cb) override
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override
QByteArray shaderSource(const QRhiShaderStage &shaderStage, QShaderVersion *shaderVersion)
QRhiBuffer * createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size) override
void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override
void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override
bool ensureContext(QSurface *surface=nullptr) const
void draw(QRhiCommandBuffer *cb, quint32 vertexCount, quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override
void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
ProgramCacheResult tryLoadFromDiskOrPipelineCache(const QRhiShaderStage *stages, int stageCount, GLuint program, const QVector< QShaderDescription::InOutVariable > &inputVars, QByteArray *cacheKey)
void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
bool isYUpInFramebuffer() const override
bool linkProgram(GLuint program)
void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override
QGles2RenderTargetData * enqueueBindFramebuffer(QRhiRenderTarget *rt, QGles2CommandBuffer *cbD, bool *wantsColorClear=nullptr, bool *wantsDsClear=nullptr)
void debugMarkEnd(QRhiCommandBuffer *cb) override
void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override
void setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override
void releaseCachedResources() override
bool isClipDepthZeroToOne() const override
void trySaveToPipelineCache(GLuint program, const QByteArray &cacheKey, bool force=false)
void executeDeferredReleases()
QByteArray pipelineCacheData() override
double lastCompletedGpuTime(QRhiCommandBuffer *cb) override
QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override
QList< int > supportedSampleCountList
QPointer< QWindow > maybeWindow
void enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cbD, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc)
struct QRhiGles2::OffscreenFrame ofr
QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override
void setPipelineCacheData(const QByteArray &data) override
QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override
void gatherGeneratedSamplers(GLuint program, const QShader::SeparateToCombinedImageSamplerMapping &mapping, QGles2SamplerDescriptionVector *dst)
const QRhiNativeHandles * nativeHandles() override
BlendOp
Specifies the blend operation.
PolygonMode
Specifies the polygon rasterization mode.
FrontFace
Specifies the front face winding order.
BlendFactor
Specifies the blend factor.
CompareOp
Specifies the depth or stencil comparison function.
CullMode
Specifies the culling mode.
QVarLengthArray< QRhiShaderStage, 4 > m_shaderStages
Topology
Specifies the primitive topology.
StencilOp
Specifies the stencil operation.
bool isCompressedFormat(QRhiTexture::Format format) const
static const QRhiShaderResourceBinding::Data * shaderResourceBindingData(const QRhiShaderResourceBinding &binding)
quint32 pipelineCacheRhiId() const
void compressedFormatInfo(QRhiTexture::Format format, const QSize &size, quint32 *bpl, quint32 *byteSize, QSize *blockDim) const
static const int MAX_SHADER_CACHE_ENTRIES
qint64 totalPipelineCreationTime() const
void textureFormatInfo(QRhiTexture::Format format, const QSize &size, quint32 *bpl, quint32 *byteSize, quint32 *bytesPerPixel) const
static TextureStage toPassTrackerTextureStage(QRhiShaderResourceBinding::StageFlags stages)
static BufferStage toPassTrackerBufferStage(QRhiShaderResourceBinding::StageFlags stages)
QRhiTexture * texture() const
void setPixelSize(const QSize &sz)
Sets the size (in pixels) to sz.
QRhiTexture::Format m_backingFormatHint
Type
Specifies the type of the renderbuffer.
virtual bool create()=0
Creates the corresponding native graphics resources.
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc)
Sets the QRhiRenderPassDescriptor desc for use with this render target.
QRhiRenderPassDescriptor * m_renderPassDesc
static QRhiResourceUpdateBatchPrivate * get(QRhiResourceUpdateBatch *b)
virtual Type resourceType() const =0
QRhiImplementation * m_rhi
Filter
Specifies the minification, magnification, or mipmap filtering.
AddressMode
Specifies the addressing mode.
CompareOp
Specifies the texture comparison function.
std::array< int, 4 > scissor() const
Type
Specifies type of the shader resource bound to a binding point.
QVarLengthArray< QRhiShaderResourceBinding, BINDING_PREALLOC > m_bindings
QShader::Variant shaderVariant() const
Type
Specifies the type of the shader stage.
QRhiRenderPassDescriptor * m_renderPassDesc
Format
Describes the swapchain format.
StereoTargetBuffer
Selects the backbuffer to use with a stereoscopic swapchain.
QRhiRenderBuffer * m_depthStencil
QPoint destinationTopLeft() const
QPoint sourceTopLeft() const
int destinationLevel() const
int destinationLayer() const
const QRhiColorAttachment * cbeginColorAttachments() const
QRhiTexture * depthTexture() const
const QRhiColorAttachment * cendColorAttachments() const
QRhiRenderBuffer * depthStencilBuffer() const
qsizetype colorAttachmentCount() const
QRhiTexture * depthResolveTexture() const
QRhiTextureRenderTargetDescription m_desc
@ DoNotStoreDepthStencilContents
@ PreserveDepthStencilContents
quint32 dataStride() const
QPoint sourceTopLeft() const
QPoint destinationTopLeft() const
Format
Specifies the texture format.
static constexpr int MAX_MIP_LEVELS
ResourceLimit
Describes the resource limit to query.
@ MaxThreadsPerThreadGroup
@ MaxThreadGroupsPerDimension
Feature
Flag values to indicate what features are supported by the backend currently in use.
@ NonDynamicUniformBuffers
@ RenderToNonBaseMipLevel
@ MultisampleRenderBuffer
@ PipelineCacheDataLoadSave
@ ReadBackNonUniformBuffer
@ RenderToOneDimensionalTexture
@ OneDimensionalTextureMipmaps
@ ReadBackNonBaseMipLevel
@ ThreeDimensionalTextureMipmaps
@ NonFourAlignedEffectiveIndexBufferOffset
@ ThreeDimensionalTextures
@ ReadBackAnyTextureFormat
FrameOpResult
Describes the result of operations that can have a soft failure.
@ EnablePipelineCacheDataSave
bool contains(const T &value) const
const_iterator cbegin() const noexcept
iterator insert(const T &value)
SeparateToCombinedImageSamplerMappingList separateToCombinedImageSamplerMappingList(const QShaderKey &key) const
\variable QShader::SeparateToCombinedImageSamplerMapping::combinedSamplerName
QShaderCode shader(const QShaderKey &key) const
QShaderDescription description() const
Stage
Describes the stage of the graphics pipeline the shader is suitable for.
@ TessellationEvaluationStage
@ TessellationControlStage
constexpr int width() const noexcept
Returns the width.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
SurfaceClass surfaceClass() const
Returns the surface class of this surface.
virtual QPlatformSurface * surfaceHandle() const =0
Returns a handle to the platform-specific implementation of the surface.
constexpr size_type size() const noexcept
const T & at(qsizetype idx) const
const T * constData() const
iterator begin() noexcept
const void * constData() const
QSurfaceFormat format() const override
Returns the actual format of this window.
QSize size() const override
Returns the size of the window excluding any window frame.
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr Initialization Uninitialized
#define Q_STATIC_ASSERT(Condition)
#define QByteArrayLiteral(str)
static QString header(const QString &name)
static bool isCubeMap(const DDSHeader &dds)
static const qint64 headerSize
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
bool qFuzzyIsNull(qfloat16 f) noexcept
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static QByteArray cacheKey(Args &&...args)
#define qCDebug(category,...)
QT_BEGIN_NAMESPACE constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qBound(const T &min, const T &val, const T &max)
constexpr const T & qMax(const T &a, const T &b)
#define QOPENGLF_APIENTRYP
QOpenGLContext * qt_gl_global_share_context()
GLboolean GLboolean GLboolean b
typedef GLint(GL_APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXEXTPROC)(GLuint program
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLenum GLint components
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
const void GLsizei GLsizei stride
#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
GLenum GLuint GLenum GLsizei const GLchar * buf
#define GL_TEXTURE_2D_MULTISAMPLE
GLenum GLuint GLintptr offset
GLsizei GLsizei GLenum * binaryFormat
#define GL_TEXTURE_2D_ARRAY
#define GL_TEXTURE_EXTERNAL_OES
GLint GLsizei GLsizei GLenum format
GLsizei GLenum internalFormat
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
#define GL_NUM_PROGRAM_BINARY_FORMATS
#define GL_MIRRORED_REPEAT
#define GL_TEXTURE_COMPARE_FUNC
#define GL_MAX_VARYING_VECTORS
#define GL_MAX_COMPUTE_WORK_GROUP_COUNT
#define GL_FRAGMENT_SHADER
#define GL_TEXTURE_WRAP_R
#define GL_DEPTH24_STENCIL8
#define GL_DEPTH_COMPONENT16
#define GL_TEXTURE_CUBE_MAP
#define GL_PRIMITIVE_RESTART_FIXED_INDEX
#define GL_ONE_MINUS_CONSTANT_ALPHA
#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
#define GL_COMPRESSED_TEXTURE_FORMATS
#define GL_CONSTANT_COLOR
#define GL_FRAMEBUFFER_SRGB
#define GL_MAX_VERTEX_OUTPUT_COMPONENTS
#define GL_COLOR_ATTACHMENT0
#define GL_DEPTH_STENCIL_ATTACHMENT
#define GL_TEXTURE_CUBE_MAP_SEAMLESS
#define GL_COMPARE_REF_TO_TEXTURE
#define GL_SHADER_STORAGE_BUFFER
#define GL_ALL_BARRIER_BITS
#define GL_MAX_VERTEX_ATTRIBS
#define GL_STENCIL_INDEX8
#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS
typedef GLbitfield(APIENTRYP PFNGLQUERYMATRIXXOESPROC)(GLfixed *mantissa
#define GL_FRAMEBUFFER_COMPLETE
#define GL_MAX_COMPUTE_WORK_GROUP_SIZE
#define GL_VERTEX_PROGRAM_POINT_SIZE
#define GL_DRAW_FRAMEBUFFER
#define GL_PROGRAM_BINARY_LENGTH
#define GL_FUNC_REVERSE_SUBTRACT
#define GL_NUM_COMPRESSED_TEXTURE_FORMATS
#define GL_TEXTURE_RECTANGLE
#define GL_TEXTURE_1D_ARRAY
#define GL_COMPILE_STATUS
GLdouble GLdouble GLdouble GLdouble q
#define GL_MAX_DRAW_BUFFERS
#define GL_QUERY_RESULT_AVAILABLE
GLenum GLenum GLenum GLenum mapping
#define GL_MAX_ARRAY_TEXTURE_LAYERS
#define GL_CONSTANT_ALPHA
#define GL_ONE_MINUS_CONSTANT_COLOR
#define GL_MAX_VERTEX_UNIFORM_VECTORS
#define GL_READ_FRAMEBUFFER
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X
#define GL_MAX_FRAGMENT_UNIFORM_VECTORS
#define GL_DEPTH_ATTACHMENT
#define GL_SHADER_STORAGE_BARRIER_BIT
#define GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS
#define GL_ELEMENT_ARRAY_BUFFER
#define GL_DEPTH_COMPONENT24
#define GL_PATCH_VERTICES
#define GL_MAX_VERTEX_UNIFORM_COMPONENTS
#define GL_INFO_LOG_LENGTH
#define GL_STENCIL_ATTACHMENT
#define GL_MAX_VARYING_COMPONENTS
#define GL_MAX_VARYING_FLOATS
#define GL_TEXTURE_COMPARE_MODE
GLsizeiptr const void GLenum usage
static void normalize(double &x, double &y)
void forceUpdate(QQuickItem *item)
#define GL_DEPTH32F_STENCIL8
static GLenum toGlMinFilter(QRhiSampler::Filter f, QRhiSampler::Filter m)
static QGles2Buffer::Access toGlAccess(QRhiPassResourceTracker::BufferAccess access)
static GLenum toGlCompressedTextureFormat(QRhiTexture::Format format, QRhiTexture::Flags flags)
#define GL_DEPTH_COMPONENT32F
static GLenum toGlTextureCompareFunc(QRhiSampler::CompareOp op)
#define GL_GEOMETRY_SHADER
static GLenum toGlCompareOp(QRhiGraphicsPipeline::CompareOp op)
#define GL_DEPTH24_STENCIL8
#define GL_DEPTH_COMPONENT16
static GLenum toGlWrapMode(QRhiSampler::AddressMode m)
static GLenum toGlBlendFactor(QRhiGraphicsPipeline::BlendFactor f)
#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
static GLbitfield barriersForTexture()
#define GL_TESS_CONTROL_SHADER
static GLenum toGlFrontFace(QRhiGraphicsPipeline::FrontFace f)
#define GL_BGRA
\variable QRhiGles2NativeHandles::context
#define GL_UNIFORM_BARRIER_BIT
#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV
#define GL_ELEMENT_ARRAY_BARRIER_BIT
#define GL_TEXTURE_FETCH_BARRIER_BIT
static void addBoundaryCommand(QGles2CommandBuffer *cbD, QGles2CommandBuffer::Command::Cmd type, GLuint tsQuery=0)
#define GL_UNSIGNED_INT_24_8
#define GL_COMPUTE_SHADER
static QRhiPassResourceTracker::UsageState toPassTrackerUsageState(const QGles2Buffer::UsageState &bufUsage)
static bool bufferAccessIsWrite(QGles2Buffer::Access access)
static bool isGraphicsStage(const QRhiShaderStage &shaderStage)
static QShader::Stage toShaderStage(QRhiShaderStage::Type type)
static GLenum toGlBlendOp(QRhiGraphicsPipeline::BlendOp op)
#define GL_TESS_EVALUATION_SHADER
#define GL_PIXEL_BUFFER_BARRIER_BIT
static void toGlTextureFormat(QRhiTexture::Format format, const QRhiGles2::Caps &caps, GLenum *glintformat, GLenum *glsizedintformat, GLenum *glformat, GLenum *gltype)
#define GL_TEXTURE_UPDATE_BARRIER_BIT
static GLenum toGlShaderType(QRhiShaderStage::Type type)
#define GL_BUFFER_UPDATE_BARRIER_BIT
static GLenum toGlCullMode(QRhiGraphicsPipeline::CullMode c)
static GLenum toGlStencilOp(QRhiGraphicsPipeline::StencilOp op)
static GLbitfield barriersForBuffer()
static GLenum toGlTopology(QRhiGraphicsPipeline::Topology t)
#define GL_SHADER_STORAGE_BARRIER_BIT
void qrhigl_accumulateComputeResource(T *writtenResources, QRhiResource *resource, QRhiShaderResourceBinding::Type bindingType, int loadTypeVal, int storeTypeVal, int loadStoreTypeVal)
static void bindVertexIndexBufferWithStateReset(CommandBufferExecTrackedState *state, QOpenGLExtensions *f, GLenum target, GLuint buffer)
#define GL_DEPTH_COMPONENT24
static bool textureAccessIsWrite(QGles2Texture::Access access)
static GLenum toGlMagFilter(QRhiSampler::Filter f)
#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT
#define GL_FRAMEBUFFER_BARRIER_BIT
static void qrhi_std140_to_packed(T *dst, int vecSize, int elemCount, const void *src)
#define GL_UNSIGNED_INT_2_10_10_10_REV
static GLenum toGlPolygonMode(QRhiGraphicsPipeline::PolygonMode mode)
static QSurface * currentSurfaceForCurrentContext(QOpenGLContext *ctx)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
unsigned long long quint64
QVideoFrameFormat::PixelFormat fmt
view viewport() -> scroll(dx, dy, deviceRect)
QSvgRenderer * renderer
[0]
struct CommandBufferExecTrackedState::@364 lastBindVertexBuffer
bool nonzeroAttribDivisor[TRACKED_ATTRIB_COUNT]
GLuint currentArrayBuffer
GLuint currentElementArrayBuffer
int maxUntrackedInstancedAttribute
bool instancedAttributesUsed
static const int TRACKED_ATTRIB_COUNT
QRhiGraphicsPipeline * ps
bool enabledAttribArrays[TRACKED_ATTRIB_COUNT]
QGles2Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
char * beginFullDynamicBufferUpdateForCurrentFrame() override
void endFullDynamicBufferUpdateForCurrentFrame() override
To be called when the entire contents of the buffer data has been updated in the memory block returne...
QRhiBuffer::NativeBuffer nativeBuffer() override
bool create() override
Creates the corresponding native graphics resources.
union QGles2CommandBuffer::Command::Args args
struct QGles2CommandBuffer::ComputePassState computePassState
QRhiShaderResourceBindings * currentGraphicsSrb
uint currentPipelineGeneration
int currentPassResTrackerIndex
uint currentSrbGeneration
static const int MAX_DYNAMIC_OFFSET_COUNT
struct QGles2CommandBuffer::GraphicsPassState graphicsPassState
QRhiBackendCommandList< Command > commands
QRhiComputePipeline * currentComputePipeline
QRhiRenderTarget * currentTarget
QRhiShaderResourceBindings * currentComputeSrb
QVarLengthArray< QRhiPassResourceTracker, 8 > passResTrackers
bool passNeedsResourceTracking
QGles2CommandBuffer(QRhiImplementation *rhi)
const void * retainImage(const QImage &image)
const void * retainData(const QByteArray &data)
const uchar * retainBufferData(const QRhiBufferData &data)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
struct QGles2CommandBuffer::TextureUnitState textureUnitState[16]
QRhiGraphicsPipeline * currentGraphicsPipeline
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QGles2UniformState uniformState[QGles2UniformState::MAX_TRACKED_LOCATION+1]
QGles2UniformDescriptionVector uniforms
QRhiShaderResourceBindings * currentSrb
QGles2ComputePipeline(QRhiImplementation *rhi)
uint currentSrbGeneration
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool create() override
Creates the corresponding native graphics resources.
QGles2GraphicsPipeline(QRhiImplementation *rhi)
~QGles2GraphicsPipeline()
QRhiShaderResourceBindings * currentSrb
uint currentSrbGeneration
QGles2UniformDescriptionVector uniforms
QGles2UniformState uniformState[QGles2UniformState::MAX_TRACKED_LOCATION+1]
bool create() override
Creates the corresponding native graphics resources.
QGles2RenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint)
bool createFrom(NativeRenderBuffer src) override
Similar to create() except that no new native renderbuffer objects are created.
QRhiTexture::Format backingFormat() const override
GLuint stencilRenderbuffer
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QVector< quint32 > serializedFormat() const override
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() const override
bool isCompatible(const QRhiRenderPassDescriptor *other) const override
~QGles2RenderPassDescriptor()
QGles2RenderPassDescriptor(QRhiImplementation *rhi)
std::optional< QRhiSwapChain::StereoTargetBuffer > stereoTarget
QGles2RenderPassDescriptor * rp
QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QGles2Sampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode, AddressMode u, AddressMode v, AddressMode w)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
void updateResources(UpdateFlags flags) override
~QGles2ShaderResourceBindings()
QGles2ShaderResourceBindings(QRhiImplementation *rhi)
float devicePixelRatio() const override
QGles2SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
QSize pixelSize() const override
int sampleCount() const override
~QGles2SwapChainRenderTarget()
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
void prepare(QRhiGles2 *rhiD)
bool active[TIMESTAMP_PAIRS]
bool tryQueryTimestamps(int pairIndex, QRhiGles2 *rhiD, double *elapsedSec)
static const int TIMESTAMP_PAIRS
void destroy(QRhiGles2 *rhiD)
void initSwapChainRenderTarget(QGles2SwapChainRenderTarget *rt)
QGles2SwapChainRenderTarget rtRight
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QGles2SwapChainRenderTarget rt
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
bool isFormatSupported(Format f) override
bool createOrResize() override
Creates the swapchain if not already done and resizes the swapchain buffers to match the current size...
QGles2SwapChainTimestamps timestamps
QGles2SwapChain(QRhiImplementation *rhi)
QRhiCommandBuffer * currentFrameCommandBuffer() override
QGles2SwapChainRenderTarget rtLeft
QSize surfacePixelSize() override
QRhiRenderTarget * currentFrameRenderTarget() override
int sampleCount() const override
QGles2TextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags)
~QGles2TextureRenderTarget()
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
float devicePixelRatio() const override
QSize pixelSize() const override
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
bool create() override
Creates the corresponding native graphics resources.
GLuint nonMsaaThrowawayDepthTexture
bool createFrom(NativeTexture src) override
Similar to create(), except that no new native textures are created.
QGles2Texture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, Flags flags)
QGles2SamplerData samplerState
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool prepareCreate(QSize *adjustedSize=nullptr)
bool create() override
Creates the corresponding native graphics resources.
NativeTexture nativeTexture() override
QList< ShaderDesc > shaders
QByteArray cacheKey() const
struct QRhiGles2::DeferredReleaseEntry::@302::@308 textureRenderTarget
struct QRhiGles2::DeferredReleaseEntry::@302::@305 pipeline
\variable QRhiReadbackResult::completed
std::function< void()> completed
QRhiReadbackResult * result
QRhiTextureCopyDescription desc
QRhiReadbackDescription rb
QVarLengthArray< MipLevelUploadList, 6 > subresDesc
QRhiReadbackResult * result
qint64 totalPipelineCreationTime
\variable QShaderDescription::InOutVariable::name