2012-07-23 17:47:54 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-11-27 02:15:17 +04:00
|
|
|
#include "OGLShaderProgram.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include <stdint.h> // for uint32_t
|
|
|
|
#include "gfxRect.h" // for gfxRect
|
|
|
|
#include "mozilla/DebugOnly.h" // for DebugOnly
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr
|
|
|
|
#include "nsString.h" // for nsAutoCString
|
|
|
|
#include "prenv.h" // for PR_GetEnv
|
2013-11-27 02:15:17 +04:00
|
|
|
#include "OGLShaders.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "Layers.h"
|
2012-11-27 02:23:27 +04:00
|
|
|
#include "GLContext.h"
|
|
|
|
|
2013-08-12 03:17:23 +04:00
|
|
|
struct gfxRGBA;
|
|
|
|
|
2012-07-23 17:47:54 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
typedef ProgramProfileOGL::Argument Argument;
|
|
|
|
|
2014-01-30 02:53:37 +04:00
|
|
|
void
|
|
|
|
AddUniforms(ProgramProfileOGL& aProfile)
|
|
|
|
{
|
|
|
|
static const char *sKnownUniformNames[] = {
|
|
|
|
"uLayerTransform",
|
|
|
|
"uMaskQuadTransform",
|
|
|
|
"uLayerQuadTransform",
|
|
|
|
"uMatrixProj",
|
|
|
|
"uTextureTransform",
|
|
|
|
"uRenderTargetOffset",
|
|
|
|
"uLayerOpacity",
|
|
|
|
"uTexture",
|
|
|
|
"uYTexture",
|
|
|
|
"uCbTexture",
|
|
|
|
"uCrTexture",
|
|
|
|
"uBlackTexture",
|
|
|
|
"uWhiteTexture",
|
|
|
|
"uMaskTexture",
|
|
|
|
"uRenderColor",
|
|
|
|
"uTexCoordMultiplier",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; sKnownUniformNames[i] != nullptr; ++i) {
|
|
|
|
aProfile.mUniforms[i].mNameString = sKnownUniformNames[i];
|
|
|
|
aProfile.mUniforms[i].mName = (KnownUniform::KnownUniformName) i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-23 17:47:54 +04:00
|
|
|
void
|
|
|
|
AddCommonArgs(ProgramProfileOGL& aProfile)
|
|
|
|
{
|
|
|
|
aProfile.mAttributes.AppendElement(Argument("aVertexCoord"));
|
|
|
|
}
|
|
|
|
void
|
|
|
|
AddCommonTextureArgs(ProgramProfileOGL& aProfile)
|
|
|
|
{
|
|
|
|
aProfile.mAttributes.AppendElement(Argument("aTexCoord"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ ProgramProfileOGL
|
2013-07-04 21:25:50 +04:00
|
|
|
ProgramProfileOGL::GetProfileFor(ShaderProgramType aType,
|
2012-07-23 17:47:54 +04:00
|
|
|
MaskType aMask)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(ProgramExists(aType, aMask), "Invalid program type.");
|
|
|
|
ProgramProfileOGL result;
|
|
|
|
|
2014-01-30 02:53:37 +04:00
|
|
|
AddUniforms(result);
|
|
|
|
|
2012-07-23 17:47:54 +04:00
|
|
|
switch (aType) {
|
2013-07-04 21:25:50 +04:00
|
|
|
case RGBALayerProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask3d) {
|
|
|
|
result.mVertexShaderString = sLayerMask3DVS;
|
|
|
|
result.mFragmentShaderString = sRGBATextureLayerMask3DFS;
|
|
|
|
} else if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sRGBATextureLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sRGBATextureLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
AddCommonTextureArgs(result);
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case BGRALayerProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sBGRATextureLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sBGRATextureLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
AddCommonTextureArgs(result);
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case RGBXLayerProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sRGBXTextureLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sRGBXTextureLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
AddCommonTextureArgs(result);
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case BGRXLayerProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sBGRXTextureLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sBGRXTextureLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
AddCommonTextureArgs(result);
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case RGBARectLayerProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask3d) {
|
|
|
|
result.mVertexShaderString = sLayerMask3DVS;
|
|
|
|
result.mFragmentShaderString = sRGBARectTextureLayerMask3DFS;
|
|
|
|
} else if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sRGBARectTextureLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sRGBARectTextureLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
AddCommonTextureArgs(result);
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-18 07:24:15 +04:00
|
|
|
case RGBXRectLayerProgramType:
|
|
|
|
if (aMask == Mask3d) {
|
|
|
|
result.mVertexShaderString = sLayerMask3DVS;
|
|
|
|
result.mFragmentShaderString = sRGBXRectTextureLayerMask3DFS;
|
|
|
|
} else if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sRGBXRectTextureLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sRGBXRectTextureLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
AddCommonTextureArgs(result);
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-09 08:21:05 +04:00
|
|
|
case BGRARectLayerProgramType:
|
|
|
|
MOZ_ASSERT(aMask == MaskNone, "BGRARectLayerProgramType can't handle masks.");
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sBGRARectTextureLayerFS;
|
|
|
|
AddCommonArgs(result);
|
|
|
|
AddCommonTextureArgs(result);
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case RGBAExternalLayerProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask3d) {
|
|
|
|
result.mVertexShaderString = sLayerMask3DVS;
|
|
|
|
result.mFragmentShaderString = sRGBAExternalTextureLayerMask3DFS;
|
|
|
|
} else if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sRGBAExternalTextureLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sRGBAExternalTextureLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
AddCommonTextureArgs(result);
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case ColorLayerProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sSolidColorLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sSolidColorLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
break;
|
2013-11-01 19:51:32 +04:00
|
|
|
case YCbCrLayerProgramType:
|
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sYCbCrTextureLayerMaskFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sYCbCrTextureLayerFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
result.mAttributes.AppendElement(Argument("aTexCoord"));
|
|
|
|
result.mTextureCount = 3;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case ComponentAlphaPass1ProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sComponentPassMask1FS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sComponentPass1FS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
result.mAttributes.AppendElement(Argument("aTexCoord"));
|
|
|
|
result.mTextureCount = 2;
|
|
|
|
break;
|
2013-07-09 18:13:33 +04:00
|
|
|
case ComponentAlphaPass1RGBProgramType:
|
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sComponentPassMask1RGBFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sComponentPass1RGBFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
|
|
|
result.mAttributes.AppendElement(Argument("aTexCoord"));
|
|
|
|
result.mTextureCount = 2;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case ComponentAlphaPass2ProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sComponentPassMask2FS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sComponentPass2FS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
2013-07-09 18:13:33 +04:00
|
|
|
result.mAttributes.AppendElement(Argument("aTexCoord"));
|
|
|
|
result.mTextureCount = 2;
|
|
|
|
break;
|
|
|
|
case ComponentAlphaPass2RGBProgramType:
|
|
|
|
if (aMask == Mask2d) {
|
|
|
|
result.mVertexShaderString = sLayerMaskVS;
|
|
|
|
result.mFragmentShaderString = sComponentPassMask2RGBFS;
|
|
|
|
} else {
|
|
|
|
result.mVertexShaderString = sLayerVS;
|
|
|
|
result.mFragmentShaderString = sComponentPass2RGBFS;
|
|
|
|
}
|
|
|
|
AddCommonArgs(result);
|
2012-07-23 17:47:54 +04:00
|
|
|
result.mAttributes.AppendElement(Argument("aTexCoord"));
|
|
|
|
result.mTextureCount = 2;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case Copy2DProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
NS_ASSERTION(!aMask, "Program does not have masked variant.");
|
|
|
|
result.mVertexShaderString = sCopyVS;
|
|
|
|
result.mFragmentShaderString = sCopy2DFS;
|
|
|
|
result.mAttributes.AppendElement(Argument("aVertexCoord"));
|
|
|
|
result.mAttributes.AppendElement(Argument("aTexCoord"));
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
2013-07-04 21:25:50 +04:00
|
|
|
case Copy2DRectProgramType:
|
2012-07-23 17:47:54 +04:00
|
|
|
NS_ASSERTION(!aMask, "Program does not have masked variant.");
|
|
|
|
result.mVertexShaderString = sCopyVS;
|
|
|
|
result.mFragmentShaderString = sCopy2DRectFS;
|
|
|
|
result.mAttributes.AppendElement(Argument("aVertexCoord"));
|
|
|
|
result.mAttributes.AppendElement(Argument("aTexCoord"));
|
|
|
|
result.mTextureCount = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown shader program type.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMask > MaskNone) {
|
|
|
|
result.mTextureCount += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* const ShaderProgramOGL::VertexCoordAttrib = "aVertexCoord";
|
|
|
|
const char* const ShaderProgramOGL::TexCoordAttrib = "aTexCoord";
|
|
|
|
|
2012-11-27 02:23:27 +04:00
|
|
|
ShaderProgramOGL::ShaderProgramOGL(GLContext* aGL, const ProgramProfileOGL& aProfile)
|
2013-11-01 19:51:32 +04:00
|
|
|
: mIsProjectionMatrixStale(false)
|
|
|
|
, mGL(aGL)
|
2012-11-27 02:23:27 +04:00
|
|
|
, mProgram(0)
|
|
|
|
, mProfile(aProfile)
|
|
|
|
, mProgramState(STATE_NEW)
|
2014-01-30 02:53:37 +04:00
|
|
|
{
|
|
|
|
}
|
2012-11-27 02:23:27 +04:00
|
|
|
|
|
|
|
ShaderProgramOGL::~ShaderProgramOGL()
|
|
|
|
{
|
|
|
|
if (mProgram <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<GLContext> ctx = mGL->GetSharedContext();
|
|
|
|
if (!ctx) {
|
|
|
|
ctx = mGL;
|
|
|
|
}
|
|
|
|
ctx->MakeCurrent();
|
|
|
|
ctx->fDeleteProgram(mProgram);
|
|
|
|
}
|
|
|
|
|
2012-07-23 17:47:54 +04:00
|
|
|
bool
|
|
|
|
ShaderProgramOGL::Initialize()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mProgramState == STATE_NEW, "Shader program has already been initialised");
|
|
|
|
|
2013-11-01 19:51:32 +04:00
|
|
|
if (!CreateProgram(mProfile.mVertexShaderString,
|
|
|
|
mProfile.mFragmentShaderString)) {
|
2012-07-23 17:47:54 +04:00
|
|
|
mProgramState = STATE_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProgramState = STATE_OK;
|
|
|
|
|
2014-01-30 02:53:37 +04:00
|
|
|
for (uint32_t i = 0; i < KnownUniform::KnownUniformCount; ++i) {
|
2012-07-23 17:47:54 +04:00
|
|
|
mProfile.mUniforms[i].mLocation =
|
2014-01-30 02:53:37 +04:00
|
|
|
mGL->fGetUniformLocation(mProgram, mProfile.mUniforms[i].mNameString);
|
2012-07-23 17:47:54 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mProfile.mAttributes.Length(); ++i) {
|
2012-07-23 17:47:54 +04:00
|
|
|
mProfile.mAttributes[i].mLocation =
|
|
|
|
mGL->fGetAttribLocation(mProgram, mProfile.mAttributes[i].mName);
|
|
|
|
NS_ASSERTION(mProfile.mAttributes[i].mLocation >= 0, "Bad attribute location.");
|
|
|
|
}
|
|
|
|
|
2014-01-30 02:53:38 +04:00
|
|
|
mProfile.mHasMatrixProj = mProfile.mUniforms[KnownUniform::MatrixProj].mLocation != -1;
|
|
|
|
|
2012-07-23 17:47:54 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLint
|
|
|
|
ShaderProgramOGL::CreateShader(GLenum aShaderType, const char *aShaderSource)
|
|
|
|
{
|
|
|
|
GLint success, len = 0;
|
|
|
|
|
|
|
|
GLint sh = mGL->fCreateShader(aShaderType);
|
2013-07-20 12:48:55 +04:00
|
|
|
mGL->fShaderSource(sh, 1, (const GLchar**)&aShaderSource, nullptr);
|
2012-07-23 17:47:54 +04:00
|
|
|
mGL->fCompileShader(sh);
|
|
|
|
mGL->fGetShaderiv(sh, LOCAL_GL_COMPILE_STATUS, &success);
|
|
|
|
mGL->fGetShaderiv(sh, LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
|
|
|
|
/* Even if compiling is successful, there may still be warnings. Print them
|
|
|
|
* in a debug build. The > 10 is to catch silly compilers that might put
|
|
|
|
* some whitespace in the log but otherwise leave it empty.
|
|
|
|
*/
|
|
|
|
if (!success
|
|
|
|
#ifdef DEBUG
|
|
|
|
|| (len > 10 && PR_GetEnv("MOZ_DEBUG_SHADERS"))
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString log;
|
2012-07-23 17:47:54 +04:00
|
|
|
log.SetCapacity(len);
|
|
|
|
mGL->fGetShaderInfoLog(sh, len, (GLint*) &len, (char*) log.BeginWriting());
|
|
|
|
log.SetLength(len);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
printf_stderr("=== SHADER COMPILATION FAILED ===\n");
|
|
|
|
} else {
|
|
|
|
printf_stderr("=== SHADER COMPILATION WARNINGS ===\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf_stderr("=== Source:\n%s\n", aShaderSource);
|
|
|
|
printf_stderr("=== Log:\n%s\n", log.get());
|
|
|
|
printf_stderr("============\n");
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
mGL->fDeleteShader(sh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sh;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ShaderProgramOGL::CreateProgram(const char *aVertexShaderString,
|
|
|
|
const char *aFragmentShaderString)
|
|
|
|
{
|
|
|
|
GLuint vertexShader = CreateShader(LOCAL_GL_VERTEX_SHADER, aVertexShaderString);
|
|
|
|
GLuint fragmentShader = CreateShader(LOCAL_GL_FRAGMENT_SHADER, aFragmentShaderString);
|
|
|
|
|
|
|
|
if (!vertexShader || !fragmentShader)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
GLint result = mGL->fCreateProgram();
|
|
|
|
mGL->fAttachShader(result, vertexShader);
|
|
|
|
mGL->fAttachShader(result, fragmentShader);
|
|
|
|
|
|
|
|
mGL->fLinkProgram(result);
|
|
|
|
|
|
|
|
GLint success, len;
|
|
|
|
mGL->fGetProgramiv(result, LOCAL_GL_LINK_STATUS, &success);
|
|
|
|
mGL->fGetProgramiv(result, LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
|
|
|
|
/* Even if linking is successful, there may still be warnings. Print them
|
|
|
|
* in a debug build. The > 10 is to catch silly compilers that might put
|
|
|
|
* some whitespace in the log but otherwise leave it empty.
|
|
|
|
*/
|
|
|
|
if (!success
|
|
|
|
#ifdef DEBUG
|
|
|
|
|| (len > 10 && PR_GetEnv("MOZ_DEBUG_SHADERS"))
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString log;
|
2012-07-23 17:47:54 +04:00
|
|
|
log.SetCapacity(len);
|
|
|
|
mGL->fGetProgramInfoLog(result, len, (GLint*) &len, (char*) log.BeginWriting());
|
|
|
|
log.SetLength(len);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
printf_stderr("=== PROGRAM LINKING FAILED ===\n");
|
|
|
|
} else {
|
|
|
|
printf_stderr("=== PROGRAM LINKING WARNINGS ===\n");
|
|
|
|
}
|
|
|
|
printf_stderr("=== Log:\n%s\n", log.get());
|
|
|
|
printf_stderr("============\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can mark the shaders for deletion; they're attached to the program
|
|
|
|
// and will remain attached.
|
|
|
|
mGL->fDeleteShader(vertexShader);
|
|
|
|
mGL->fDeleteShader(fragmentShader);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
mGL->fDeleteProgram(result);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProgram = result;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-27 02:23:27 +04:00
|
|
|
void
|
|
|
|
ShaderProgramOGL::Activate()
|
|
|
|
{
|
|
|
|
if (mProgramState == STATE_NEW) {
|
|
|
|
if (!Initialize()) {
|
|
|
|
NS_WARNING("Shader could not be initialised");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(HasInitialized(), "Attempting to activate a program that's not in use!");
|
|
|
|
mGL->fUseProgram(mProgram);
|
2013-12-06 19:23:16 +04:00
|
|
|
|
2014-01-30 02:53:38 +04:00
|
|
|
// check if we need to set the projection matrix
|
2013-11-01 19:51:32 +04:00
|
|
|
if (mIsProjectionMatrixStale) {
|
|
|
|
SetProjectionMatrix(mProjectionMatrix);
|
|
|
|
}
|
2012-11-27 02:23:27 +04:00
|
|
|
}
|
|
|
|
|
2012-07-23 17:47:54 +04:00
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|