Commit 69bde01a by Geoff Lang

Add texture format utilities for GL and generate GL texture caps.

BUG=angleproject:884 Change-Id: Iba0108b22e6a404842ec1013d22c00d206c865d3 Reviewed-on: https://chromium-review.googlesource.com/255512Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 8c25cdec
//
// Copyright (c) 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.
//
// formatutilsgl.h: Queries for GL image formats and their translations to native
// GL formats.
#ifndef LIBANGLE_RENDERER_GL_FORMATUTILSGL_H_
#define LIBANGLE_RENDERER_GL_FORMATUTILSGL_H_
#include <string>
#include <vector>
#include "angle_gl.h"
namespace rx
{
namespace nativegl
{
struct InternalFormat
{
InternalFormat();
typedef bool(*SupportCheckFunction)(GLuint majorVersion, GLuint minorVersion,
const std::vector<std::string> &extensions);
SupportCheckFunction textureSupport;
SupportCheckFunction renderSupport;
SupportCheckFunction filterSupport;
};
const InternalFormat &GetInternalFormatInfo(GLenum internalFormat);
}
}
#endif // LIBANGLE_RENDERER_GL_FORMATUTILSGL_H_
......@@ -12,14 +12,75 @@
#include <limits>
#include "libANGLE/Caps.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/formatutilsgl.h"
#include <algorithm>
namespace rx
{
namespace nativegl
{
void GetGLVersion(PFNGLGETSTRINGPROC getStringFunction, GLuint *outMajorVersion, GLuint *outMinorVersion,
bool *outIsES)
{
const std::string version = reinterpret_cast<const char*>(getStringFunction(GL_VERSION));
if (version.find("OpenGL ES") == std::string::npos)
{
// ES spec states that the GL_VERSION string will be in the following format:
// "OpenGL ES N.M vendor-specific information"
*outIsES = false;
*outMajorVersion = version[0] - '0';
*outMinorVersion = version[2] - '0';
}
else
{
// 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
*outIsES = true;
*outMajorVersion = version[10] - '0';
*outMinorVersion = version[12] - '0';
}
}
std::vector<std::string> GetGLExtensions(PFNGLGETSTRINGPROC getStringFunction)
{
std::vector<std::string> result;
std::istringstream stream(reinterpret_cast<const char*>(getStringFunction(GL_EXTENSIONS)));
std::string extension;
while (std::getline(stream, extension, ' '))
{
result.push_back(extension);
}
return result;
}
}
namespace nativegl_gl
{
static gl::TextureCaps GenerateTextureFormatCaps(const FunctionsGL *functions, GLenum internalFormat, GLuint majorVersion, GLuint minorVersion,
const std::vector<std::string> &extensions)
{
gl::TextureCaps textureCaps;
const nativegl::InternalFormat &formatInfo = nativegl::GetInternalFormatInfo(internalFormat);
textureCaps.texturable = formatInfo.textureSupport(majorVersion, minorVersion, extensions);
textureCaps.renderable = formatInfo.renderSupport(majorVersion, minorVersion, extensions);
textureCaps.filterable = formatInfo.filterSupport(majorVersion, minorVersion, extensions);
return textureCaps;
}
static GLint QuerySingleGLInt(const FunctionsGL *functions, GLenum name)
{
GLint result;
......@@ -30,6 +91,29 @@ static GLint QuerySingleGLInt(const FunctionsGL *functions, GLenum name)
void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsMap *textureCapsMap,
gl::Extensions *extensions)
{
GLuint majorVersion = 0;
GLuint minorVersion = 0;
bool isES = false;
nativegl::GetGLVersion(functions->getString, &majorVersion, &minorVersion, &isES);
std::vector<std::string> nativeExtensions = nativegl::GetGLExtensions(functions->getString);
// Texture format support checks
GLuint maxSamples = 0;
const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats();
for (GLenum internalFormat : allFormats)
{
gl::TextureCaps textureCaps = GenerateTextureFormatCaps(functions, internalFormat, majorVersion, minorVersion, nativeExtensions);
textureCapsMap->insert(internalFormat, textureCaps);
maxSamples = std::max(maxSamples, textureCaps.getMaxSamples());
if (gl::GetInternalFormatInfo(internalFormat).compressed)
{
caps->compressedTextureFormats.push_back(internalFormat);
}
}
// Set some minimum GLES2 caps, TODO: query for real GL caps
// Table 6.28, implementation dependent values
......@@ -99,21 +183,6 @@ void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsM
caps->maxTransformFeedbackSeparateAttributes = 4;
caps->maxTransformFeedbackSeparateComponents = 4;
// Texture Caps
gl::TextureCaps supportedTextureFormat;
supportedTextureFormat.texturable = true;
supportedTextureFormat.filterable = true;
supportedTextureFormat.renderable = true;
textureCapsMap->insert(GL_RGB565, supportedTextureFormat);
textureCapsMap->insert(GL_RGBA4, supportedTextureFormat);
textureCapsMap->insert(GL_RGB5_A1, supportedTextureFormat);
textureCapsMap->insert(GL_RGB8_OES, supportedTextureFormat);
textureCapsMap->insert(GL_RGBA8_OES, supportedTextureFormat);
textureCapsMap->insert(GL_DEPTH_COMPONENT16, supportedTextureFormat);
textureCapsMap->insert(GL_STENCIL_INDEX8, supportedTextureFormat);
// Extension support
extensions->setTextureExtensionSupport(*textureCapsMap);
extensions->textureNPOT = true;
......
......@@ -10,6 +10,10 @@
#ifndef LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
#define LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
#include "libANGLE/renderer/gl/functionsgl_typedefs.h"
#include <vector>
namespace gl
{
struct Caps;
......@@ -21,6 +25,14 @@ namespace rx
{
class FunctionsGL;
namespace nativegl
{
void GetGLVersion(PFNGLGETSTRINGPROC getStringFunction, GLuint *outMajorVersion, GLuint *outMinorVersion, bool *outIsES);
std::vector<std::string> GetGLExtensions(PFNGLGETSTRINGPROC getStringFunction);
}
namespace nativegl_gl
{
......
......@@ -12,6 +12,7 @@
#include "libANGLE/Config.h"
#include "libANGLE/Display.h"
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/gl/renderergl_utils.h"
#include "libANGLE/renderer/gl/wgl/FunctionsWGL.h"
#include "libANGLE/renderer/gl/wgl/WindowSurfaceWGL.h"
#include "libANGLE/renderer/gl/wgl/wgl_utils.h"
......@@ -184,14 +185,11 @@ egl::Error DisplayWGL::initialize(egl::Display *display)
return egl::Error(EGL_NOT_INITIALIZED, "Failed to get glGetString pointer.");
}
const char *dummyGLVersionString = reinterpret_cast<const char*>(getString(GL_VERSION));
if (!dummyGLVersionString)
{
return egl::Error(EGL_NOT_INITIALIZED, "Failed to get OpenGL version string.");
}
GLuint maxGLVersionMajor = dummyGLVersionString[0] - '0';
GLuint maxGLVersionMinor = dummyGLVersionString[2] - '0';
GLuint maxGLVersionMajor = 0;
GLuint maxGLVersionMinor = 0;
bool isES = false;
nativegl::GetGLVersion(getString, &maxGLVersionMajor, &maxGLVersionMinor, &isES);
ASSERT(!isES);
// Reinitialize the wgl functions to grab the extensions
mFunctionsWGL->intialize(mOpenGLModule, dummyDeviceContext);
......@@ -300,9 +298,8 @@ egl::Error DisplayWGL::initialize(egl::Display *display)
return egl::Error(EGL_NOT_INITIALIZED, "Failed to make the intermediate WGL context current.");
}
const char *versionString = reinterpret_cast<const char*>(getString(GL_VERSION));
mGLVersionMajor = versionString[0] - '0';
mGLVersionMinor = versionString[2] - '0';
nativegl::GetGLVersion(getString, &mGLVersionMajor, &mGLVersionMinor, &isES);
ASSERT(!isES);
mFunctionsGL = new FunctionsGLWindows(mOpenGLModule, mFunctionsWGL->getProcAddress);
mFunctionsGL->initialize(mGLVersionMajor, mGLVersionMinor);
......
......@@ -404,6 +404,8 @@
'libANGLE/renderer/gl/TransformFeedbackGL.h',
'libANGLE/renderer/gl/VertexArrayGL.cpp',
'libANGLE/renderer/gl/VertexArrayGL.h',
'libANGLE/renderer/gl/formatutilsgl.cpp',
'libANGLE/renderer/gl/formatutilsgl.h',
'libANGLE/renderer/gl/functionsgl_enums.h',
'libANGLE/renderer/gl/functionsgl_typedefs.h',
'libANGLE/renderer/gl/renderergl_utils.cpp',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment