Hash :
d15250e6
Author :
Date :
2014-09-03T09:40:44
Move shader variables into the base impl. These variable types apply across shader types. Either we'll want a way to cache them after we query them, or we'll do a pre-parse pass similar to our current Chromium GLSL to GLSL pre-pass where we store the variables in ANGLE. In either case, they're shared across GL implementations so make sense as queries from gl::Shader. BUG=angle:731 Change-Id: I23f5541423abb4af87a2bc2fc1e9f4047fd2ff90 Reviewed-on: https://chromium-review.googlesource.com/214870 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@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
//
// Copyright (c) 2002-2014 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.
//
// Shader.cpp: Implements the gl::Shader class and its derived classes
// VertexShader and FragmentShader. Implements GL shader objects and related
// functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section 3.8 page 84.
#include "libGLESv2/Shader.h"
#include "libGLESv2/renderer/Renderer.h"
#include "libGLESv2/renderer/ShaderImpl.h"
#include "libGLESv2/Constants.h"
#include "libGLESv2/ResourceManager.h"
#include "common/utilities.h"
#include "GLSLANG/ShaderLang.h"
#include <sstream>
namespace gl
{
Shader::Shader(ResourceManager *manager, rx::ShaderImpl *impl, GLenum type, GLuint handle)
: mShader(impl),
mType(type),
mHandle(handle),
mResourceManager(manager),
mRefCount(0),
mDeleteStatus(false),
mCompiled(false)
{
ASSERT(impl);
}
Shader::~Shader()
{
}
GLuint Shader::getHandle() const
{
return mHandle;
}
void Shader::setSource(GLsizei count, const char *const *string, const GLint *length)
{
std::ostringstream stream;
for (int i = 0; i < count; i++)
{
stream << string[i];
}
mSource = stream.str();
}
int Shader::getInfoLogLength() const
{
return mShader->getInfoLog().empty() ? 0 : (mShader->getInfoLog().length() + 1);
}
void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const
{
int index = 0;
if (bufSize > 0)
{
index = std::min(bufSize - 1, static_cast<GLsizei>(mShader->getInfoLog().length()));
memcpy(infoLog, mShader->getInfoLog().c_str(), index);
infoLog[index] = '\0';
}
if (length)
{
*length = index;
}
}
int Shader::getSourceLength() const
{
return mSource.empty() ? 0 : (mSource.length() + 1);
}
int Shader::getTranslatedSourceLength() const
{
return mShader->getTranslatedSource().empty() ? 0 : (mShader->getTranslatedSource().length() + 1);
}
void Shader::getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei *length, char *buffer)
{
int index = 0;
if (bufSize > 0)
{
index = std::min(bufSize - 1, static_cast<GLsizei>(source.length()));
memcpy(buffer, source.c_str(), index);
buffer[index] = '\0';
}
if (length)
{
*length = index;
}
}
void Shader::getSource(GLsizei bufSize, GLsizei *length, char *buffer) const
{
getSourceImpl(mSource, bufSize, length, buffer);
}
void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const
{
getSourceImpl(mShader->getTranslatedSource(), bufSize, length, buffer);
}
void Shader::compile()
{
mCompiled = mShader->compile(mSource);
}
void Shader::addRef()
{
mRefCount++;
}
void Shader::release()
{
mRefCount--;
if (mRefCount == 0 && mDeleteStatus)
{
mResourceManager->deleteShader(mHandle);
}
}
unsigned int Shader::getRefCount() const
{
return mRefCount;
}
bool Shader::isFlaggedForDeletion() const
{
return mDeleteStatus;
}
void Shader::flagForDeletion()
{
mDeleteStatus = true;
}
const std::vector<gl::PackedVarying> &Shader::getVaryings() const
{
return mShader->getVaryings();
}
const std::vector<sh::Uniform> &Shader::getUniforms() const
{
return mShader->getUniforms();
}
const std::vector<sh::InterfaceBlock> &Shader::getInterfaceBlocks() const
{
return mShader->getInterfaceBlocks();
}
const std::vector<sh::Attribute> &Shader::getActiveAttributes() const
{
return mShader->getActiveAttributes();
}
const std::vector<sh::Attribute> &Shader::getActiveOutputVariables() const
{
return mShader->getActiveOutputVariables();
}
std::vector<gl::PackedVarying> &Shader::getVaryings()
{
return mShader->getVaryings();
}
std::vector<sh::Uniform> &Shader::getUniforms()
{
return mShader->getUniforms();
}
std::vector<sh::InterfaceBlock> &Shader::getInterfaceBlocks()
{
return mShader->getInterfaceBlocks();
}
std::vector<sh::Attribute> &Shader::getActiveAttributes()
{
return mShader->getActiveAttributes();
}
std::vector<sh::Attribute> &Shader::getActiveOutputVariables()
{
return mShader->getActiveOutputVariables();
}
}