Commit c05f7065 by Geoff Lang

TextureGL implementation.

BUG=angleproject:884 Change-Id: I877c0a9f753dacff96bbb82486bee71d1996ecb7 Reviewed-on: https://chromium-review.googlesource.com/252982Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 559a2e8c
......@@ -36,7 +36,7 @@ RendererGL::RendererGL(const FunctionsGL *functions)
mStateManager(nullptr)
{
ASSERT(mFunctions);
mStateManager = new StateManagerGL(mFunctions);
mStateManager = new StateManagerGL(mFunctions, getRendererCaps());
}
RendererGL::~RendererGL()
......@@ -59,7 +59,7 @@ gl::Error RendererGL::finish()
gl::Error RendererGL::drawArrays(const gl::Data &data, GLenum mode,
GLint first, GLsizei count, GLsizei instances)
{
mStateManager->setDrawState(*data.state);
mStateManager->setDrawState(data);
mFunctions->drawArrays(mode, first, count);
return gl::Error(GL_NO_ERROR);
......@@ -74,7 +74,7 @@ gl::Error RendererGL::drawElements(const gl::Data &data, GLenum mode, GLsizei co
UNIMPLEMENTED();
}
mStateManager->setDrawState(*data.state);
mStateManager->setDrawState(data);
mFunctions->drawElements(mode, count, type, indices);
return gl::Error(GL_NO_ERROR);
......@@ -107,7 +107,7 @@ FramebufferImpl *RendererGL::createFramebuffer(const gl::Framebuffer::Data &data
TextureImpl *RendererGL::createTexture(GLenum target)
{
return new TextureGL();
return new TextureGL(target, mFunctions, mStateManager);
}
RenderbufferImpl *RendererGL::createRenderbuffer()
......
......@@ -12,18 +12,28 @@
#include "libANGLE/VertexArray.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/ProgramGL.h"
#include "libANGLE/renderer/gl/TextureGL.h"
#include "libANGLE/renderer/gl/VertexArrayGL.h"
namespace rx
{
StateManagerGL::StateManagerGL(const FunctionsGL *functions)
StateManagerGL::StateManagerGL(const FunctionsGL *functions, const gl::Caps &rendererCaps)
: mFunctions(functions),
mProgram(0),
mVAO(0),
mBuffers()
mBuffers(),
mTextureUnitIndex(0),
mTextures(),
mUnpackAlignment(4),
mUnpackRowLength(0)
{
ASSERT(mFunctions);
mTextures[GL_TEXTURE_2D].resize(rendererCaps.maxCombinedTextureImageUnits);
mTextures[GL_TEXTURE_CUBE_MAP].resize(rendererCaps.maxCombinedTextureImageUnits);
mTextures[GL_TEXTURE_2D_ARRAY].resize(rendererCaps.maxCombinedTextureImageUnits);
mTextures[GL_TEXTURE_3D].resize(rendererCaps.maxCombinedTextureImageUnits);
}
void StateManagerGL::useProgram(GLuint program)
......@@ -53,8 +63,44 @@ void StateManagerGL::bindBuffer(GLenum type, GLuint buffer)
}
}
void StateManagerGL::setDrawState(const gl::State &state)
void StateManagerGL::activeTexture(size_t unit)
{
if (mTextureUnitIndex != unit)
{
mTextureUnitIndex = unit;
mFunctions->activeTexture(GL_TEXTURE0 + mTextureUnitIndex);
}
}
void StateManagerGL::bindTexture(GLenum type, GLuint texture)
{
if (mTextures[type][mTextureUnitIndex] != texture)
{
mTextures[type][mTextureUnitIndex] = texture;
mFunctions->bindTexture(type, texture);
}
}
void StateManagerGL::setPixelUnpackState(GLint alignment, GLint rowLength)
{
if (mUnpackAlignment != alignment)
{
mUnpackAlignment = alignment;
mFunctions->pixelStorei(GL_UNPACK_ALIGNMENT, mUnpackAlignment);
}
if (mUnpackRowLength != rowLength)
{
mUnpackRowLength = rowLength;
mFunctions->pixelStorei(GL_UNPACK_ROW_LENGTH, mUnpackRowLength);
}
}
void StateManagerGL::setDrawState(const gl::Data &data)
{
const gl::State &state = *data.state;
const gl::Caps &caps = *data.caps;
const gl::VertexArray *vao = state.getVertexArray();
const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao);
bindVertexArray(vaoGL->getVertexArrayID());
......@@ -62,6 +108,51 @@ void StateManagerGL::setDrawState(const gl::State &state)
const gl::Program *program = state.getProgram();
const ProgramGL *programGL = GetImplAs<ProgramGL>(program);
useProgram(programGL->getProgramID());
// TODO: Only apply textures referenced by the program.
for (auto textureTypeIter = mTextures.begin(); textureTypeIter != mTextures.end(); textureTypeIter++)
{
GLenum textureType = textureTypeIter->first;
// Determine if this texture type can exist in the source context
bool validTextureType = (textureType == GL_TEXTURE_2D || textureType == GL_TEXTURE_CUBE_MAP ||
(textureType == GL_TEXTURE_2D_ARRAY && data.clientVersion >= 3) ||
(textureType == GL_TEXTURE_3D && data.clientVersion >= 3));
const std::vector<GLuint> &textureVector = textureTypeIter->second;
for (size_t textureUnitIndex = 0; textureUnitIndex < textureVector.size(); textureUnitIndex++)
{
const gl::Texture *texture = nullptr;
bool validTextureUnit = textureUnitIndex < caps.maxCombinedTextureImageUnits;
if (validTextureType && validTextureUnit)
{
texture = state.getSamplerTexture(textureUnitIndex, textureType);
}
if (texture != nullptr)
{
const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
if (mTextures[textureType][textureUnitIndex] != textureGL->getTextureID())
{
activeTexture(textureUnitIndex);
textureGL->syncSamplerState(texture->getSamplerState());
bindTexture(textureType, textureGL->getTextureID());
}
// TODO: apply sampler object if one is bound
}
else
{
if (mTextures[textureType][textureUnitIndex] != 0)
{
activeTexture(textureUnitIndex);
bindTexture(textureType, 0);
}
}
}
}
}
}
......@@ -16,7 +16,8 @@
namespace gl
{
class State;
struct Caps;
struct Data;
}
namespace rx
......@@ -27,13 +28,16 @@ class FunctionsGL;
class StateManagerGL
{
public:
StateManagerGL(const FunctionsGL *functions);
StateManagerGL(const FunctionsGL *functions, const gl::Caps &rendererCaps);
void useProgram(GLuint program);
void bindVertexArray(GLuint vao);
void bindBuffer(GLenum type, GLuint buffer);
void activeTexture(size_t unit);
void bindTexture(GLenum type, GLuint texture);
void setPixelUnpackState(GLint alignment, GLint rowLength);
void setDrawState(const gl::State &state);
void setDrawState(const gl::Data &data);
private:
DISALLOW_COPY_AND_ASSIGN(StateManagerGL);
......@@ -43,6 +47,12 @@ class StateManagerGL
GLuint mProgram;
GLuint mVAO;
std::map<GLenum, GLuint> mBuffers;
size_t mTextureUnitIndex;
std::map<GLenum, std::vector<GLuint>> mTextures;
GLint mUnpackAlignment;
GLint mUnpackRowLength;
};
}
......
......@@ -9,15 +9,19 @@
#ifndef LIBANGLE_RENDERER_GL_TEXTUREGL_H_
#define LIBANGLE_RENDERER_GL_TEXTUREGL_H_
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/TextureImpl.h"
namespace rx
{
class FunctionsGL;
class StateManagerGL;
class TextureGL : public TextureImpl
{
public:
TextureGL();
TextureGL(GLenum type, const FunctionsGL *functions, StateManagerGL *stateManager);
~TextureGL() override;
void setUsage(GLenum usage) override;
......@@ -44,8 +48,19 @@ class TextureGL : public TextureImpl
void bindTexImage(egl::Surface *surface) override;
void releaseTexImage() override;
void syncSamplerState(const gl::SamplerState &samplerState) const;
GLuint getTextureID() const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureGL);
GLenum mTextureType;
const FunctionsGL *mFunctions;
StateManagerGL *mStateManager;
mutable gl::SamplerState mAppliedSamplerState;
GLuint mTextureID;
};
}
......
......@@ -18,6 +18,13 @@ namespace rx
namespace nativegl_gl
{
static GLint QuerySingleGLInt(const FunctionsGL *functions, GLenum name)
{
GLint result;
functions->getIntegerv(name, &result);
return result;
}
void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsMap *textureCapsMap,
gl::Extensions *extensions)
{
......@@ -25,10 +32,10 @@ void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsM
// Table 6.28, implementation dependent values
caps->maxElementIndex = static_cast<GLint64>(std::numeric_limits<unsigned int>::max());
caps->max3DTextureSize = 256;
caps->max2DTextureSize = 2048;
caps->maxCubeMapTextureSize = 2048;
caps->maxArrayTextureLayers = 256;
caps->max3DTextureSize = QuerySingleGLInt(functions, GL_MAX_3D_TEXTURE_SIZE);
caps->max2DTextureSize = QuerySingleGLInt(functions, GL_MAX_TEXTURE_SIZE);
caps->maxCubeMapTextureSize = QuerySingleGLInt(functions, GL_MAX_CUBE_MAP_TEXTURE_SIZE);
caps->maxArrayTextureLayers = QuerySingleGLInt(functions, GL_MAX_ARRAY_TEXTURE_LAYERS);
caps->maxLODBias = 2.0f;
caps->maxRenderbufferSize = 2048;
caps->maxDrawBuffers = 4;
......@@ -63,14 +70,14 @@ void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsM
caps->maxVertexUniformVectors = 256;
caps->maxVertexUniformBlocks = 12;
caps->maxVertexOutputComponents = 64;
caps->maxVertexTextureImageUnits = 16;
caps->maxVertexTextureImageUnits = QuerySingleGLInt(functions, GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS);
// Table 6.32, implementation dependent fragment shader limits
caps->maxFragmentUniformComponents = 896;
caps->maxFragmentUniformVectors = 224;
caps->maxFragmentUniformBlocks = 12;
caps->maxFragmentInputComponents = 60;
caps->maxTextureImageUnits = 16;
caps->maxTextureImageUnits = QuerySingleGLInt(functions, GL_MAX_TEXTURE_IMAGE_UNITS);
caps->minProgramTexelOffset = -8;
caps->maxProgramTexelOffset = 7;
......@@ -83,7 +90,7 @@ void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsM
caps->maxCombinedFragmentUniformComponents = (caps->maxFragmentUniformBlocks * (caps->maxUniformBlockSize / 4)) + caps->maxFragmentUniformComponents;
caps->maxVaryingComponents = 60;
caps->maxVaryingVectors = 15;
caps->maxCombinedTextureImageUnits = 32;
caps->maxCombinedTextureImageUnits = caps->maxVertexTextureImageUnits + caps->maxTextureImageUnits;
// Table 6.34, implementation dependent transform feedback limits
caps->maxTransformFeedbackInterleavedComponents = 64;
......
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