Hash :
d193d51b
Author :
Date :
2024-06-17T22:46:08
Replace issue ids post migration to new issue tracker This change replaces anglebug.com/NNNN links. Bug: None Change-Id: I8ac3aec8d2a8a844b3d7b99fc0a6b2be8da31761 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5637912 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// FunctionsGL.cpp: Implements the FuntionsGL class to contain loaded GL functions
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include <algorithm>
#include "common/string_utils.h"
#include "libANGLE/AttributeMap.h"
#include "libANGLE/renderer/gl/renderergl_utils.h"
namespace rx
{
static void GetGLVersion(PFNGLGETSTRINGPROC getStringFunction,
gl::Version *outVersion,
StandardGL *outStandard)
{
const std::string version = reinterpret_cast<const char *>(getStringFunction(GL_VERSION));
if (version.find("OpenGL ES") == std::string::npos)
{
// OpenGL spec states the GL_VERSION string will be in the following format:
// <version number><space><vendor-specific information>
// The version number is either of the form major number.minor number or major
// number.minor number.release number, where the numbers all have one or more
// digits
*outStandard = STANDARD_GL_DESKTOP;
*outVersion = gl::Version(version[0] - '0', version[2] - '0');
}
else
{
// ES spec states that the GL_VERSION string will be in the following format:
// "OpenGL ES N.M vendor-specific information"
*outStandard = STANDARD_GL_ES;
*outVersion = gl::Version(version[10] - '0', version[12] - '0');
}
}
static std::vector<std::string> GetIndexedExtensions(PFNGLGETINTEGERVPROC getIntegerFunction,
PFNGLGETSTRINGIPROC getStringIFunction)
{
std::vector<std::string> result;
GLint numExtensions;
getIntegerFunction(GL_NUM_EXTENSIONS, &numExtensions);
result.reserve(numExtensions);
for (GLint i = 0; i < numExtensions; i++)
{
result.push_back(reinterpret_cast<const char *>(getStringIFunction(GL_EXTENSIONS, i)));
}
return result;
}
#if defined(ANGLE_ENABLE_OPENGL_NULL)
static GLenum INTERNAL_GL_APIENTRY StubCheckFramebufferStatus(GLenum)
{
return GL_FRAMEBUFFER_COMPLETE;
}
static void INTERNAL_GL_APIENTRY StubGetProgramiv(GLuint program, GLenum pname, GLint *params)
{
switch (pname)
{
case GL_LINK_STATUS:
*params = GL_TRUE;
break;
case GL_VALIDATE_STATUS:
*params = GL_TRUE;
break;
default:
break;
}
}
static void INTERNAL_GL_APIENTRY StubGetShaderiv(GLuint program, GLenum pname, GLint *params)
{
switch (pname)
{
case GL_COMPILE_STATUS:
*params = GL_TRUE;
break;
default:
break;
}
}
#endif // defined(ANGLE_ENABLE_OPENGL_NULL)
#define ASSIGN(NAME, FP) FP = reinterpret_cast<decltype(FP)>(loadProcAddress(NAME))
FunctionsGL::FunctionsGL() : version(), standard(), extensions() {}
FunctionsGL::~FunctionsGL() {}
void FunctionsGL::initialize(const egl::AttributeMap &displayAttributes)
{
// Grab the version number
ASSIGN("glGetString", getString);
ASSIGN("glGetIntegerv", getIntegerv);
GetGLVersion(getString, &version, &standard);
// Grab the GL extensions
if (isAtLeastGL(gl::Version(3, 0)) || isAtLeastGLES(gl::Version(3, 0)))
{
ASSIGN("glGetStringi", getStringi);
extensions = GetIndexedExtensions(getIntegerv, getStringi);
}
else
{
const char *exts = reinterpret_cast<const char *>(getString(GL_EXTENSIONS));
angle::SplitStringAlongWhitespace(std::string(exts), &extensions);
}
std::set<std::string> extensionSet;
for (const auto &extension : extensions)
{
extensionSet.insert(extension);
}
// Note:
// Even though extensions are written against specific versions of GL, many drivers expose the
// extensions in even older versions. Always try loading the extensions regardless of GL
// version.
// Load the entry points
#if defined(ANGLE_ENABLE_OPENGL_NULL)
EGLint deviceType =
static_cast<EGLint>(displayAttributes.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_NONE));
#endif // defined(ANGLE_ENABLE_GL_NULL)
switch (standard)
{
case STANDARD_GL_DESKTOP:
{
// Check the context profile
profile = 0;
if (isAtLeastGL(gl::Version(3, 2)))
{
getIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
}
#if defined(ANGLE_ENABLE_OPENGL_NULL)
if (deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{
initProcsDesktopGLNULL(version, extensionSet);
}
else
#endif // defined(ANGLE_ENABLE_GL_NULL)
{
initProcsDesktopGL(version, extensionSet);
// Test that ANGLE_ENABLE_GL_DESKTOP_BACKEND has been enabled
// See http://anglebug.com/42266631
ASSERT(getString != nullptr && getError != nullptr);
}
break;
}
case STANDARD_GL_ES:
{
// No profiles in GLES
profile = 0;
#if defined(ANGLE_ENABLE_OPENGL_NULL)
if (deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{
initProcsGLESNULL(version, extensionSet);
}
else
#endif // defined(ANGLE_ENABLE_GL_NULL)
{
initProcsGLES(version, extensionSet);
}
break;
}
default:
UNREACHABLE();
break;
}
#if defined(ANGLE_ENABLE_OPENGL_NULL)
if (deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{
initProcsSharedExtensionsNULL(extensionSet);
initializeStubFunctionsForNULLDriver(extensionSet);
}
else
#endif // defined(ANGLE_ENABLE_OPENGL_NULL)
{
initProcsSharedExtensions(extensionSet);
}
}
bool FunctionsGL::isAtLeastGL(const gl::Version &glVersion) const
{
return standard == STANDARD_GL_DESKTOP && version >= glVersion;
}
bool FunctionsGL::isAtMostGL(const gl::Version &glVersion) const
{
return standard == STANDARD_GL_DESKTOP && glVersion >= version;
}
bool FunctionsGL::isAtLeastGLES(const gl::Version &glesVersion) const
{
return standard == STANDARD_GL_ES && version >= glesVersion;
}
bool FunctionsGL::isAtMostGLES(const gl::Version &glesVersion) const
{
return standard == STANDARD_GL_ES && glesVersion >= version;
}
bool FunctionsGL::hasExtension(const std::string &ext) const
{
return std::find(extensions.begin(), extensions.end(), ext) != extensions.end();
}
bool FunctionsGL::hasGLExtension(const std::string &ext) const
{
return standard == STANDARD_GL_DESKTOP && hasExtension(ext);
}
bool FunctionsGL::hasGLESExtension(const std::string &ext) const
{
return standard == STANDARD_GL_ES && hasExtension(ext);
}
#if defined(ANGLE_ENABLE_OPENGL_NULL)
void FunctionsGL::initializeStubFunctionsForNULLDriver(const std::set<std::string> &extensionSet)
{
// This is a quick hack to get the NULL driver working, but we might want to implement a true
// NULL/stub driver that never calls into the OS. See Chromium's implementation in
// ui/gl/gl_stub_api.cc. This might be useful for testing things like perf scaling due to
// the caps returned by the drivers (i.e. number of texture units) or a true NULL back-end
// that could be used in a VM for things like fuzzing.
// TODO(jmadill): Implement true no-op/stub back-end.
ASSIGN("glGetString", getString);
ASSIGN("glGetStringi", getStringi);
ASSIGN("glGetIntegerv", getIntegerv);
ASSIGN("glGetIntegeri_v", getIntegeri_v);
getProgramiv = &StubGetProgramiv;
getShaderiv = &StubGetShaderiv;
checkFramebufferStatus = &StubCheckFramebufferStatus;
if (isAtLeastGLES(gl::Version(3, 0)) || isAtLeastGL(gl::Version(4, 2)) ||
extensionSet.count("GL_ARB_internalformat_query") > 0)
{
ASSIGN("glGetInternalformativ", getInternalformativ);
}
if (isAtLeastGL(gl::Version(4, 3)))
{
ASSIGN("glGetInternalformati64v", getInternalformati64v);
}
if (extensionSet.count("GL_NV_internalformat_sample_query") > 0)
{
ASSIGN("glGetInternalformatSampleivNV", getInternalformatSampleivNV);
}
}
#endif // defined(ANGLE_ENABLE_OPENGL_NULL)
} // namespace rx