mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 875232 - Make most of the GLContext helper functions take a texture target parameter so that we can support GL_TEXTURE_RECTANGLE. r=jgilbert
This commit is contained in:
parent
15b6cbf471
commit
cef59c4d1b
@ -1165,7 +1165,7 @@ GLContext::IsFramebufferComplete(GLuint fb, GLenum* pStatus)
|
||||
void
|
||||
GLContext::AttachBuffersToFB(GLuint colorTex, GLuint colorRB,
|
||||
GLuint depthRB, GLuint stencilRB,
|
||||
GLuint fb)
|
||||
GLuint fb, GLenum target)
|
||||
{
|
||||
MOZ_ASSERT(fb);
|
||||
MOZ_ASSERT( !(colorTex && colorRB) );
|
||||
@ -1175,9 +1175,11 @@ GLContext::AttachBuffersToFB(GLuint colorTex, GLuint colorRB,
|
||||
|
||||
if (colorTex) {
|
||||
MOZ_ASSERT(fIsTexture(colorTex));
|
||||
MOZ_ASSERT(target == LOCAL_GL_TEXTURE_2D ||
|
||||
target == LOCAL_GL_TEXTURE_RECTANGLE_ARB);
|
||||
fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
||||
LOCAL_GL_COLOR_ATTACHMENT0,
|
||||
LOCAL_GL_TEXTURE_2D,
|
||||
target,
|
||||
colorTex,
|
||||
0);
|
||||
} else if (colorRB) {
|
||||
|
@ -101,8 +101,10 @@ public:
|
||||
bool isOffscreen = false)
|
||||
: mTexBlit_Buffer(0),
|
||||
mTexBlit_VertShader(0),
|
||||
mTexBlit_FragShader(0),
|
||||
mTexBlit_Program(0),
|
||||
mTex2DBlit_FragShader(0),
|
||||
mTex2DRectBlit_FragShader(0),
|
||||
mTex2DBlit_Program(0),
|
||||
mTex2DRectBlit_Program(0),
|
||||
mTexBlit_UseDrawNotCopy(false),
|
||||
mInitialized(false),
|
||||
mIsOffscreen(isOffscreen),
|
||||
@ -380,12 +382,16 @@ public:
|
||||
protected:
|
||||
GLuint mTexBlit_Buffer;
|
||||
GLuint mTexBlit_VertShader;
|
||||
GLuint mTexBlit_FragShader;
|
||||
GLuint mTexBlit_Program;
|
||||
GLuint mTex2DBlit_FragShader;
|
||||
GLuint mTex2DRectBlit_FragShader;
|
||||
GLuint mTex2DBlit_Program;
|
||||
GLuint mTex2DRectBlit_Program;
|
||||
|
||||
bool mTexBlit_UseDrawNotCopy;
|
||||
|
||||
bool UseTexQuadProgram();
|
||||
bool UseTexQuadProgram(GLenum target = LOCAL_GL_TEXTURE_2D,
|
||||
const gfxIntSize& srcSize = gfxIntSize());
|
||||
bool InitTexQuadProgram(GLenum target = LOCAL_GL_TEXTURE_2D);
|
||||
void DeleteTexBlitProgram();
|
||||
|
||||
public:
|
||||
@ -401,13 +407,17 @@ public:
|
||||
const GLFormats& srcFormats);
|
||||
void BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
|
||||
const gfxIntSize& srcSize,
|
||||
const gfxIntSize& destSize);
|
||||
const gfxIntSize& destSize,
|
||||
GLenum srcTarget = LOCAL_GL_TEXTURE_2D);
|
||||
void BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
|
||||
const gfxIntSize& srcSize,
|
||||
const gfxIntSize& destSize);
|
||||
const gfxIntSize& destSize,
|
||||
GLenum destTarget = LOCAL_GL_TEXTURE_2D);
|
||||
void BlitTextureToTexture(GLuint srcTex, GLuint destTex,
|
||||
const gfxIntSize& srcSize,
|
||||
const gfxIntSize& destSize);
|
||||
const gfxIntSize& destSize,
|
||||
GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
|
||||
GLenum destTarget = LOCAL_GL_TEXTURE_2D);
|
||||
|
||||
/*
|
||||
* Resize the current offscreen buffer. Returns true on success.
|
||||
@ -1329,7 +1339,7 @@ public:
|
||||
// Does not check completeness.
|
||||
void AttachBuffersToFB(GLuint colorTex, GLuint colorRB,
|
||||
GLuint depthRB, GLuint stencilRB,
|
||||
GLuint fb);
|
||||
GLuint fb, GLenum target = LOCAL_GL_TEXTURE_2D);
|
||||
|
||||
// Passing null is fine if the value you'd get is 0.
|
||||
bool AssembleOffscreenFBs(const GLuint colorMSRB,
|
||||
@ -3146,32 +3156,21 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
struct ScopedBindTexture
|
||||
: public ScopedGLWrapper<ScopedBindTexture>
|
||||
struct ScopedBindTextureUnit
|
||||
: public ScopedGLWrapper<ScopedBindTextureUnit>
|
||||
{
|
||||
friend struct ScopedGLWrapper<ScopedBindTexture>;
|
||||
friend struct ScopedGLWrapper<ScopedBindTextureUnit>;
|
||||
|
||||
protected:
|
||||
GLuint mOldTex;
|
||||
|
||||
private:
|
||||
void Init() {
|
||||
mOldTex = 0;
|
||||
mGL->GetUIntegerv(LOCAL_GL_TEXTURE_BINDING_2D, &mOldTex);
|
||||
}
|
||||
GLenum mOldTexUnit;
|
||||
|
||||
public:
|
||||
explicit ScopedBindTexture(GLContext* gl)
|
||||
: ScopedGLWrapper<ScopedBindTexture>(gl)
|
||||
ScopedBindTextureUnit(GLContext* gl, GLenum texUnit)
|
||||
: ScopedGLWrapper<ScopedBindTextureUnit>(gl)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
ScopedBindTexture(GLContext* gl, GLuint newTex)
|
||||
: ScopedGLWrapper<ScopedBindTexture>(gl)
|
||||
{
|
||||
Init();
|
||||
mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, newTex);
|
||||
MOZ_ASSERT(texUnit >= LOCAL_GL_TEXTURE0);
|
||||
mGL->GetUIntegerv(LOCAL_GL_ACTIVE_TEXTURE, &mOldTexUnit);
|
||||
mGL->fActiveTexture(texUnit);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -3180,7 +3179,46 @@ protected:
|
||||
// the current context changed.
|
||||
MOZ_ASSERT(mGL->IsCurrent());
|
||||
|
||||
mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mOldTex);
|
||||
mGL->fActiveTexture(mOldTexUnit);
|
||||
}
|
||||
};
|
||||
|
||||
struct ScopedBindTexture
|
||||
: public ScopedGLWrapper<ScopedBindTexture>
|
||||
{
|
||||
friend struct ScopedGLWrapper<ScopedBindTexture>;
|
||||
|
||||
protected:
|
||||
GLuint mOldTex;
|
||||
GLenum mTarget;
|
||||
|
||||
private:
|
||||
void Init(GLenum target) {
|
||||
MOZ_ASSERT(target == LOCAL_GL_TEXTURE_2D ||
|
||||
target == LOCAL_GL_TEXTURE_RECTANGLE_ARB);
|
||||
mTarget = target;
|
||||
mOldTex = 0;
|
||||
GLenum bindingTarget = (target == LOCAL_GL_TEXTURE_2D) ?
|
||||
LOCAL_GL_TEXTURE_BINDING_2D :
|
||||
LOCAL_GL_TEXTURE_BINDING_RECTANGLE_ARB;
|
||||
mGL->GetUIntegerv(bindingTarget, &mOldTex);
|
||||
}
|
||||
|
||||
public:
|
||||
ScopedBindTexture(GLContext* gl, GLuint newTex, GLenum target = LOCAL_GL_TEXTURE_2D)
|
||||
: ScopedGLWrapper<ScopedBindTexture>(gl)
|
||||
{
|
||||
Init(target);
|
||||
mGL->fBindTexture(target, newTex);
|
||||
}
|
||||
|
||||
protected:
|
||||
void UnwrapImpl() {
|
||||
// Check that we're not falling out of scope after
|
||||
// the current context changed.
|
||||
MOZ_ASSERT(mGL->IsCurrent());
|
||||
|
||||
mGL->fBindTexture(mTarget, mOldTex);
|
||||
}
|
||||
};
|
||||
|
||||
@ -3233,7 +3271,8 @@ protected:
|
||||
GLuint mFB;
|
||||
|
||||
public:
|
||||
ScopedFramebufferForTexture(GLContext* gl, GLuint texture)
|
||||
ScopedFramebufferForTexture(GLContext* gl, GLuint texture,
|
||||
GLenum target = LOCAL_GL_TEXTURE_2D)
|
||||
: ScopedGLWrapper<ScopedFramebufferForTexture>(gl)
|
||||
, mComplete(false)
|
||||
, mFB(0)
|
||||
@ -3242,7 +3281,7 @@ public:
|
||||
ScopedBindFramebuffer autoFB(gl, mFB);
|
||||
mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
||||
LOCAL_GL_COLOR_ATTACHMENT0,
|
||||
LOCAL_GL_TEXTURE_2D,
|
||||
target,
|
||||
texture,
|
||||
0);
|
||||
|
||||
|
@ -26,7 +26,7 @@ void main(void) { \n\
|
||||
} \n\
|
||||
";
|
||||
|
||||
static const char kTexBlit_FragShaderSource[] = "\
|
||||
static const char kTex2DBlit_FragShaderSource[] = "\
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH \n\
|
||||
precision highp float; \n\
|
||||
#else \n\
|
||||
@ -42,67 +42,99 @@ void main(void) { \n\
|
||||
} \n\
|
||||
";
|
||||
|
||||
static const char kTex2DRectBlit_FragShaderSource[] = "\
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH \n\
|
||||
precision highp float; \n\
|
||||
#else \n\
|
||||
precision mediump float; \n\
|
||||
#endif \n\
|
||||
\n\
|
||||
uniform sampler2D uTexUnit; \n\
|
||||
uniform vec2 uTexCoordMult; \n\
|
||||
\n\
|
||||
varying vec2 vTexCoord; \n\
|
||||
\n\
|
||||
void main(void) { \n\
|
||||
gl_FragColor = texture2DRect(uTexUnit, \n\
|
||||
vTexCoord * uTexCoordMult); \n\
|
||||
} \n\
|
||||
";
|
||||
|
||||
// Allowed to be destructive of state we restore in functions below.
|
||||
bool
|
||||
GLContext::UseTexQuadProgram()
|
||||
GLContext::InitTexQuadProgram(GLenum target)
|
||||
{
|
||||
MOZ_ASSERT(target == LOCAL_GL_TEXTURE_2D ||
|
||||
target == LOCAL_GL_TEXTURE_RECTANGLE_ARB);
|
||||
bool success = false;
|
||||
|
||||
GLuint *programPtr;
|
||||
GLuint *fragShaderPtr;
|
||||
const char* fragShaderSource;
|
||||
if (target == LOCAL_GL_TEXTURE_2D) {
|
||||
programPtr = &mTex2DBlit_Program;
|
||||
fragShaderPtr = &mTex2DBlit_FragShader;
|
||||
fragShaderSource = kTex2DBlit_FragShaderSource;
|
||||
} else {
|
||||
programPtr = &mTex2DRectBlit_Program;
|
||||
fragShaderPtr = &mTex2DRectBlit_FragShader;
|
||||
fragShaderSource = kTex2DRectBlit_FragShaderSource;
|
||||
}
|
||||
|
||||
GLuint& program = *programPtr;
|
||||
GLuint& fragShader = *fragShaderPtr;
|
||||
|
||||
// Use do-while(false) to let us break on failure
|
||||
do {
|
||||
if (mTexBlit_Program) {
|
||||
if (program) {
|
||||
// Already have it...
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/* CCW tri-strip:
|
||||
* 2---3
|
||||
* | \ |
|
||||
* 0---1
|
||||
*/
|
||||
GLfloat verts[] = {
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f
|
||||
};
|
||||
if (!mTexBlit_Buffer) {
|
||||
|
||||
MOZ_ASSERT(!mTexBlit_Buffer);
|
||||
fGenBuffers(1, &mTexBlit_Buffer);
|
||||
fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mTexBlit_Buffer);
|
||||
/* CCW tri-strip:
|
||||
* 2---3
|
||||
* | \ |
|
||||
* 0---1
|
||||
*/
|
||||
GLfloat verts[] = {
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f
|
||||
};
|
||||
|
||||
const size_t vertsSize = sizeof(verts);
|
||||
MOZ_ASSERT(vertsSize >= 3 * sizeof(GLfloat)); // Make sure we have a sane size.
|
||||
fBufferData(LOCAL_GL_ARRAY_BUFFER, vertsSize, verts, LOCAL_GL_STATIC_DRAW);
|
||||
MOZ_ASSERT(!mTexBlit_Buffer);
|
||||
fGenBuffers(1, &mTexBlit_Buffer);
|
||||
fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mTexBlit_Buffer);
|
||||
|
||||
fEnableVertexAttribArray(0);
|
||||
fVertexAttribPointer(0,
|
||||
2,
|
||||
LOCAL_GL_FLOAT,
|
||||
false,
|
||||
0,
|
||||
nullptr);
|
||||
const size_t vertsSize = sizeof(verts);
|
||||
// Make sure we have a sane size.
|
||||
MOZ_ASSERT(vertsSize >= 3 * sizeof(GLfloat));
|
||||
fBufferData(LOCAL_GL_ARRAY_BUFFER, vertsSize, verts, LOCAL_GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!mTexBlit_VertShader);
|
||||
MOZ_ASSERT(!mTexBlit_FragShader);
|
||||
if (!mTexBlit_VertShader) {
|
||||
|
||||
const char* vertShaderSource = kTexBlit_VertShaderSource;
|
||||
const char* fragShaderSource = kTexBlit_FragShaderSource;
|
||||
const char* vertShaderSource = kTexBlit_VertShaderSource;
|
||||
|
||||
mTexBlit_VertShader = fCreateShader(LOCAL_GL_VERTEX_SHADER);
|
||||
fShaderSource(mTexBlit_VertShader, 1, &vertShaderSource, nullptr);
|
||||
fCompileShader(mTexBlit_VertShader);
|
||||
mTexBlit_VertShader = fCreateShader(LOCAL_GL_VERTEX_SHADER);
|
||||
fShaderSource(mTexBlit_VertShader, 1, &vertShaderSource, nullptr);
|
||||
fCompileShader(mTexBlit_VertShader);
|
||||
}
|
||||
|
||||
mTexBlit_FragShader = fCreateShader(LOCAL_GL_FRAGMENT_SHADER);
|
||||
fShaderSource(mTexBlit_FragShader, 1, &fragShaderSource, nullptr);
|
||||
fCompileShader(mTexBlit_FragShader);
|
||||
MOZ_ASSERT(!fragShader);
|
||||
fragShader = fCreateShader(LOCAL_GL_FRAGMENT_SHADER);
|
||||
fShaderSource(fragShader, 1, &fragShaderSource, nullptr);
|
||||
fCompileShader(fragShader);
|
||||
|
||||
mTexBlit_Program = fCreateProgram();
|
||||
fAttachShader(mTexBlit_Program, mTexBlit_VertShader);
|
||||
fAttachShader(mTexBlit_Program, mTexBlit_FragShader);
|
||||
fBindAttribLocation(mTexBlit_Program, 0, "aPosition");
|
||||
fLinkProgram(mTexBlit_Program);
|
||||
program = fCreateProgram();
|
||||
fAttachShader(program, mTexBlit_VertShader);
|
||||
fAttachShader(program, fragShader);
|
||||
fBindAttribLocation(program, 0, "aPosition");
|
||||
fLinkProgram(program);
|
||||
|
||||
if (DebugMode()) {
|
||||
GLint status = 0;
|
||||
@ -125,19 +157,19 @@ GLContext::UseTexQuadProgram()
|
||||
}
|
||||
|
||||
status = 0;
|
||||
fGetShaderiv(mTexBlit_FragShader, LOCAL_GL_COMPILE_STATUS, &status);
|
||||
fGetShaderiv(fragShader, LOCAL_GL_COMPILE_STATUS, &status);
|
||||
if (status != LOCAL_GL_TRUE) {
|
||||
NS_ERROR("Frag shader compilation failed.");
|
||||
|
||||
GLint length = 0;
|
||||
fGetShaderiv(mTexBlit_FragShader, LOCAL_GL_INFO_LOG_LENGTH, &length);
|
||||
fGetShaderiv(fragShader, LOCAL_GL_INFO_LOG_LENGTH, &length);
|
||||
if (!length) {
|
||||
printf_stderr("No shader info log available.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
nsAutoArrayPtr<char> buffer(new char[length]);
|
||||
fGetShaderInfoLog(mTexBlit_FragShader, length, nullptr, buffer);
|
||||
fGetShaderInfoLog(fragShader, length, nullptr, buffer);
|
||||
|
||||
printf_stderr("Shader info log (%d bytes): %s\n", length, buffer.get());
|
||||
break;
|
||||
@ -145,30 +177,31 @@ GLContext::UseTexQuadProgram()
|
||||
}
|
||||
|
||||
GLint status = 0;
|
||||
fGetProgramiv(mTexBlit_Program, LOCAL_GL_LINK_STATUS, &status);
|
||||
fGetProgramiv(program, LOCAL_GL_LINK_STATUS, &status);
|
||||
if (status != LOCAL_GL_TRUE) {
|
||||
if (DebugMode()) {
|
||||
NS_ERROR("Linking blit program failed.");
|
||||
GLint length = 0;
|
||||
fGetProgramiv(mTexBlit_Program, LOCAL_GL_INFO_LOG_LENGTH, &length);
|
||||
fGetProgramiv(program, LOCAL_GL_INFO_LOG_LENGTH, &length);
|
||||
if (!length) {
|
||||
printf_stderr("No program info log available.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
nsAutoArrayPtr<char> buffer(new char[length]);
|
||||
fGetProgramInfoLog(mTexBlit_Program, length, nullptr, buffer);
|
||||
fGetProgramInfoLog(program, length, nullptr, buffer);
|
||||
|
||||
printf_stderr("Program info log (%d bytes): %s\n", length, buffer.get());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(fGetAttribLocation(mTexBlit_Program, "aPosition") == 0);
|
||||
GLuint texUnitLoc = fGetUniformLocation(mTexBlit_Program, "uTexUnit");
|
||||
MOZ_ASSERT(fGetAttribLocation(program, "aPosition") == 0);
|
||||
GLint texUnitLoc = fGetUniformLocation(program, "uTexUnit");
|
||||
MOZ_ASSERT(texUnitLoc != -1, "uniform not found");
|
||||
|
||||
// Set uniforms here:
|
||||
fUseProgram(mTexBlit_Program);
|
||||
fUseProgram(program);
|
||||
fUniform1i(texUnitLoc, 0);
|
||||
|
||||
success = true;
|
||||
@ -182,7 +215,7 @@ GLContext::UseTexQuadProgram()
|
||||
return false;
|
||||
}
|
||||
|
||||
fUseProgram(mTexBlit_Program);
|
||||
fUseProgram(program);
|
||||
fEnableVertexAttribArray(0);
|
||||
fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mTexBlit_Buffer);
|
||||
fVertexAttribPointer(0,
|
||||
@ -194,6 +227,22 @@ GLContext::UseTexQuadProgram()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
GLContext::UseTexQuadProgram(GLenum target, const gfxIntSize& srcSize)
|
||||
{
|
||||
if (!InitTexQuadProgram(target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target == LOCAL_GL_TEXTURE_RECTANGLE_ARB) {
|
||||
GLint texCoordMultLoc = fGetUniformLocation(mTex2DRectBlit_Program, "uTexCoordMult");
|
||||
MOZ_ASSERT(texCoordMultLoc != -1, "uniform not found");
|
||||
fUniform2f(texCoordMultLoc, srcSize.width, srcSize.height);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
GLContext::DeleteTexBlitProgram()
|
||||
{
|
||||
@ -205,13 +254,21 @@ GLContext::DeleteTexBlitProgram()
|
||||
fDeleteShader(mTexBlit_VertShader);
|
||||
mTexBlit_VertShader = 0;
|
||||
}
|
||||
if (mTexBlit_FragShader) {
|
||||
fDeleteShader(mTexBlit_FragShader);
|
||||
mTexBlit_FragShader = 0;
|
||||
if (mTex2DBlit_FragShader) {
|
||||
fDeleteShader(mTex2DBlit_FragShader);
|
||||
mTex2DBlit_FragShader = 0;
|
||||
}
|
||||
if (mTexBlit_Program) {
|
||||
fDeleteProgram(mTexBlit_Program);
|
||||
mTexBlit_Program = 0;
|
||||
if (mTex2DRectBlit_FragShader) {
|
||||
fDeleteShader(mTex2DRectBlit_FragShader);
|
||||
mTex2DRectBlit_FragShader = 0;
|
||||
}
|
||||
if (mTex2DBlit_Program) {
|
||||
fDeleteProgram(mTex2DBlit_Program);
|
||||
mTex2DBlit_Program = 0;
|
||||
}
|
||||
if (mTex2DRectBlit_Program) {
|
||||
fDeleteProgram(mTex2DRectBlit_Program);
|
||||
mTex2DRectBlit_Program = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +324,8 @@ GLContext::BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
|
||||
void
|
||||
GLContext::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
|
||||
const gfxIntSize& srcSize,
|
||||
const gfxIntSize& destSize)
|
||||
const gfxIntSize& destSize,
|
||||
GLenum srcTarget)
|
||||
{
|
||||
MOZ_ASSERT(fIsTexture(srcTex));
|
||||
MOZ_ASSERT(!destFB || fIsFramebuffer(destFB));
|
||||
@ -275,7 +333,7 @@ GLContext::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
|
||||
if (IsExtensionSupported(EXT_framebuffer_blit) ||
|
||||
IsExtensionSupported(ANGLE_framebuffer_blit))
|
||||
{
|
||||
ScopedFramebufferForTexture srcWrapper(this, srcTex);
|
||||
ScopedFramebufferForTexture srcWrapper(this, srcTex, srcTarget);
|
||||
MOZ_ASSERT(srcWrapper.IsComplete());
|
||||
|
||||
BlitFramebufferToFramebuffer(srcWrapper.FB(), destFB,
|
||||
@ -285,14 +343,10 @@ GLContext::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
|
||||
|
||||
|
||||
ScopedBindFramebuffer boundFB(this, destFB);
|
||||
|
||||
GLuint boundTexUnit = 0;
|
||||
GetUIntegerv(LOCAL_GL_ACTIVE_TEXTURE, &boundTexUnit);
|
||||
fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
|
||||
GLuint boundTex = 0;
|
||||
GetUIntegerv(LOCAL_GL_TEXTURE_BINDING_2D, &boundTex);
|
||||
fBindTexture(LOCAL_GL_TEXTURE_2D, srcTex);
|
||||
// UseTexQuadProgram initializes a shader that reads
|
||||
// from texture unit 0.
|
||||
ScopedBindTextureUnit boundTU(this, LOCAL_GL_TEXTURE0);
|
||||
ScopedBindTexture boundTex(this, srcTex, srcTarget);
|
||||
|
||||
GLuint boundProgram = 0;
|
||||
GetUIntegerv(LOCAL_GL_CURRENT_PROGRAM, &boundProgram);
|
||||
@ -355,7 +409,7 @@ GLContext::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
|
||||
fViewport(0, 0, destSize.width, destSize.height);
|
||||
|
||||
// Does destructive things to (only!) what we just saved above.
|
||||
bool good = UseTexQuadProgram();
|
||||
bool good = UseTexQuadProgram(srcTarget, srcSize);
|
||||
if (!good) {
|
||||
// We're up against the wall, so bail.
|
||||
// This should really be MOZ_CRASH(why) or MOZ_RUNTIME_ASSERT(good).
|
||||
@ -387,14 +441,13 @@ GLContext::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
|
||||
fBindBuffer(LOCAL_GL_ARRAY_BUFFER, boundBuffer);
|
||||
|
||||
fUseProgram(boundProgram);
|
||||
fBindTexture(LOCAL_GL_TEXTURE_2D, boundTex);
|
||||
fActiveTexture(boundTexUnit);
|
||||
}
|
||||
|
||||
void
|
||||
GLContext::BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
|
||||
const gfxIntSize& srcSize,
|
||||
const gfxIntSize& destSize)
|
||||
const gfxIntSize& destSize,
|
||||
GLenum destTarget)
|
||||
{
|
||||
MOZ_ASSERT(!srcFB || fIsFramebuffer(srcFB));
|
||||
MOZ_ASSERT(fIsTexture(destTex));
|
||||
@ -402,18 +455,18 @@ GLContext::BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
|
||||
if (IsExtensionSupported(EXT_framebuffer_blit) ||
|
||||
IsExtensionSupported(ANGLE_framebuffer_blit))
|
||||
{
|
||||
ScopedFramebufferForTexture destWrapper(this, destTex);
|
||||
ScopedFramebufferForTexture destWrapper(this, destTex, destTarget);
|
||||
|
||||
BlitFramebufferToFramebuffer(srcFB, destWrapper.FB(),
|
||||
srcSize, destSize);
|
||||
return;
|
||||
}
|
||||
|
||||
ScopedBindTexture autoTex(this, destTex);
|
||||
ScopedBindTexture autoTex(this, destTex, destTarget);
|
||||
ScopedBindFramebuffer boundFB(this, srcFB);
|
||||
ScopedGLState scissor(this, LOCAL_GL_SCISSOR_TEST, false);
|
||||
|
||||
fCopyTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0,
|
||||
fCopyTexSubImage2D(destTarget, 0,
|
||||
0, 0,
|
||||
0, 0,
|
||||
srcSize.width, srcSize.height);
|
||||
@ -422,25 +475,26 @@ GLContext::BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
|
||||
void
|
||||
GLContext::BlitTextureToTexture(GLuint srcTex, GLuint destTex,
|
||||
const gfxIntSize& srcSize,
|
||||
const gfxIntSize& destSize)
|
||||
const gfxIntSize& destSize,
|
||||
GLenum srcTarget, GLenum destTarget)
|
||||
{
|
||||
MOZ_ASSERT(fIsTexture(srcTex));
|
||||
MOZ_ASSERT(fIsTexture(destTex));
|
||||
|
||||
if (mTexBlit_UseDrawNotCopy) {
|
||||
// Draw is texture->framebuffer
|
||||
ScopedFramebufferForTexture destWrapper(this, destTex);
|
||||
ScopedFramebufferForTexture destWrapper(this, destTex, destTarget);
|
||||
|
||||
BlitTextureToFramebuffer(srcTex, destWrapper.FB(),
|
||||
srcSize, destSize);
|
||||
srcSize, destSize, srcTarget);
|
||||
return;
|
||||
}
|
||||
|
||||
// Generally, just use the CopyTexSubImage path
|
||||
ScopedFramebufferForTexture srcWrapper(this, srcTex);
|
||||
ScopedFramebufferForTexture srcWrapper(this, srcTex, srcTarget);
|
||||
|
||||
BlitFramebufferToTexture(srcWrapper.FB(), destTex,
|
||||
srcSize, destSize);
|
||||
srcSize, destSize, destTarget);
|
||||
}
|
||||
|
||||
uint32_t GetBitsPerTexel(GLenum format, GLenum type)
|
||||
|
@ -565,10 +565,12 @@ ReadBuffer::Create(GLContext* gl,
|
||||
|
||||
GLuint colorTex = 0;
|
||||
GLuint colorRB = 0;
|
||||
GLenum target = 0;
|
||||
|
||||
switch (surf->AttachType()) {
|
||||
case AttachmentType::GLTexture:
|
||||
colorTex = surf->Texture();
|
||||
target = surf->TextureTarget();
|
||||
break;
|
||||
case AttachmentType::GLRenderbuffer:
|
||||
colorRB = surf->Renderbuffer();
|
||||
@ -580,7 +582,7 @@ ReadBuffer::Create(GLContext* gl,
|
||||
|
||||
GLuint fb = 0;
|
||||
gl->fGenFramebuffers(1, &fb);
|
||||
gl->AttachBuffersToFB(colorTex, colorRB, depthRB, stencilRB, fb);
|
||||
gl->AttachBuffersToFB(colorTex, colorRB, depthRB, stencilRB, fb, target);
|
||||
|
||||
MOZ_ASSERT(gl->IsFramebufferComplete(fb));
|
||||
|
||||
@ -614,10 +616,12 @@ ReadBuffer::Attach(SharedSurface_GL* surf)
|
||||
if (surf->AttachType() != AttachmentType::Screen) {
|
||||
GLuint colorTex = 0;
|
||||
GLuint colorRB = 0;
|
||||
GLenum target = 0;
|
||||
|
||||
switch (surf->AttachType()) {
|
||||
case AttachmentType::GLTexture:
|
||||
colorTex = surf->Texture();
|
||||
target = surf->TextureTarget();
|
||||
break;
|
||||
case AttachmentType::GLRenderbuffer:
|
||||
colorRB = surf->Renderbuffer();
|
||||
@ -626,7 +630,7 @@ ReadBuffer::Attach(SharedSurface_GL* surf)
|
||||
MOZ_CRASH("Unknown attachment type?");
|
||||
}
|
||||
|
||||
mGL->AttachBuffersToFB(colorTex, colorRB, 0, 0, mFB);
|
||||
mGL->AttachBuffersToFB(colorTex, colorRB, 0, 0, mFB, target);
|
||||
MOZ_ASSERT(mGL->IsFramebufferComplete(mFB));
|
||||
}
|
||||
|
||||
|
@ -108,6 +108,10 @@ public:
|
||||
MOZ_CRASH("Did you forget to override this function?");
|
||||
}
|
||||
|
||||
virtual GLenum TextureTarget() const {
|
||||
return Texture() ? LOCAL_GL_TEXTURE_2D : 0;
|
||||
}
|
||||
|
||||
virtual GLuint Renderbuffer() const {
|
||||
MOZ_ASSERT(AttachType() == AttachmentType::GLRenderbuffer);
|
||||
MOZ_CRASH("Did you forget to override this function?");
|
||||
|
@ -52,8 +52,9 @@ SharedSurface_GL::Copy(SharedSurface_GL* src, SharedSurface_GL* dest,
|
||||
|
||||
if (dest->AttachType() == AttachmentType::GLTexture) {
|
||||
GLuint destTex = dest->Texture();
|
||||
GLenum destTarget = dest->TextureTarget();
|
||||
|
||||
gl->BlitFramebufferToTexture(0, destTex, src->Size(), dest->Size());
|
||||
gl->BlitFramebufferToTexture(0, destTex, src->Size(), dest->Size(), destTarget);
|
||||
} else if (dest->AttachType() == AttachmentType::GLRenderbuffer) {
|
||||
GLuint destRB = dest->Renderbuffer();
|
||||
ScopedFramebufferForRenderbuffer destWrapper(gl, destRB);
|
||||
@ -89,8 +90,9 @@ SharedSurface_GL::Copy(SharedSurface_GL* src, SharedSurface_GL* dest,
|
||||
|
||||
if (src->AttachType() == AttachmentType::GLTexture) {
|
||||
GLuint srcTex = src->Texture();
|
||||
GLenum srcTarget = src->TextureTarget();
|
||||
|
||||
gl->BlitTextureToFramebuffer(srcTex, 0, src->Size(), dest->Size());
|
||||
gl->BlitTextureToFramebuffer(srcTex, 0, src->Size(), dest->Size(), srcTarget);
|
||||
} else if (src->AttachType() == AttachmentType::GLRenderbuffer) {
|
||||
GLuint srcRB = src->Renderbuffer();
|
||||
ScopedFramebufferForRenderbuffer srcWrapper(gl, srcRB);
|
||||
@ -115,12 +117,15 @@ SharedSurface_GL::Copy(SharedSurface_GL* src, SharedSurface_GL* dest,
|
||||
|
||||
if (src->AttachType() == AttachmentType::GLTexture) {
|
||||
GLuint srcTex = src->Texture();
|
||||
GLenum srcTarget = src->TextureTarget();
|
||||
|
||||
if (dest->AttachType() == AttachmentType::GLTexture) {
|
||||
GLuint destTex = dest->Texture();
|
||||
GLenum destTarget = dest->TextureTarget();
|
||||
|
||||
gl->BlitTextureToTexture(srcTex, destTex,
|
||||
src->Size(), dest->Size());
|
||||
src->Size(), dest->Size(),
|
||||
srcTarget, destTarget);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -130,7 +135,7 @@ SharedSurface_GL::Copy(SharedSurface_GL* src, SharedSurface_GL* dest,
|
||||
ScopedFramebufferForRenderbuffer destWrapper(gl, destRB);
|
||||
|
||||
gl->BlitTextureToFramebuffer(srcTex, destWrapper.FB(),
|
||||
src->Size(), dest->Size());
|
||||
src->Size(), dest->Size(), srcTarget);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -144,9 +149,10 @@ SharedSurface_GL::Copy(SharedSurface_GL* src, SharedSurface_GL* dest,
|
||||
|
||||
if (dest->AttachType() == AttachmentType::GLTexture) {
|
||||
GLuint destTex = dest->Texture();
|
||||
GLenum destTarget = dest->TextureTarget();
|
||||
|
||||
gl->BlitFramebufferToTexture(srcWrapper.FB(), destTex,
|
||||
src->Size(), dest->Size());
|
||||
src->Size(), dest->Size(), destTarget);
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user