Bug 945023 - Extract CreateTextureXXX and CreateRenderbufferXXX from GLContext. r=bjacob

This commit is contained in:
Dan Glastonbury 2013-12-06 10:36:13 -05:00
parent 5995475f5b
commit c419c71b21
7 changed files with 166 additions and 127 deletions

View File

@ -12,6 +12,115 @@
namespace mozilla {
namespace gl {
static void
RenderbufferStorageBySamples(GLContext* aGL, GLsizei aSamples,
GLenum aInternalFormat, const gfxIntSize& aSize)
{
if (aSamples) {
aGL->fRenderbufferStorageMultisample(LOCAL_GL_RENDERBUFFER,
aSamples,
aInternalFormat,
aSize.width, aSize.height);
} else {
aGL->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER,
aInternalFormat,
aSize.width, aSize.height);
}
}
GLuint
CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat,
GLenum aType, const gfxIntSize& aSize)
{
GLuint tex = 0;
aGL->fGenTextures(1, &tex);
ScopedBindTexture autoTex(aGL, tex);
aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
aGL->fTexImage2D(LOCAL_GL_TEXTURE_2D,
0,
aInternalFormat,
aSize.width, aSize.height,
0,
aFormat,
aType,
nullptr);
return tex;
}
GLuint
CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats,
const gfxIntSize& aSize)
{
MOZ_ASSERT(aFormats.color_texInternalFormat);
MOZ_ASSERT(aFormats.color_texFormat);
MOZ_ASSERT(aFormats.color_texType);
return CreateTexture(aGL,
aFormats.color_texInternalFormat,
aFormats.color_texFormat,
aFormats.color_texType,
aSize);
}
GLuint
CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples,
const gfxIntSize& aSize)
{
GLuint rb = 0;
aGL->fGenRenderbuffers(1, &rb);
ScopedBindRenderbuffer autoRB(aGL, rb);
RenderbufferStorageBySamples(aGL, aSamples, aFormat, aSize);
return rb;
}
void
CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats,
const gfxIntSize& aSize, bool aMultisample,
GLuint* aColorMSRB, GLuint* aDepthRB,
GLuint* aStencilRB)
{
GLsizei samples = aMultisample ? aFormats.samples : 0;
if (aColorMSRB) {
MOZ_ASSERT(aFormats.samples > 0);
MOZ_ASSERT(aFormats.color_rbFormat);
*aColorMSRB = CreateRenderbuffer(aGL, aFormats.color_rbFormat, samples, aSize);
}
if (aDepthRB &&
aStencilRB &&
aFormats.depthStencil)
{
*aDepthRB = CreateRenderbuffer(aGL, aFormats.depthStencil, samples, aSize);
*aStencilRB = *aDepthRB;
} else {
if (aDepthRB) {
MOZ_ASSERT(aFormats.depth);
*aDepthRB = CreateRenderbuffer(aGL, aFormats.depth, samples, aSize);
}
if (aStencilRB) {
MOZ_ASSERT(aFormats.stencil);
*aStencilRB = CreateRenderbuffer(aGL, aFormats.stencil, samples, aSize);
}
}
}
GLBlitHelper::GLBlitHelper(GLContext* gl)
: mGL(gl)
, mTexBlit_Buffer(0)
@ -323,7 +432,7 @@ GLBlitHelper::BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
return;
}
GLuint tex = mGL->CreateTextureForOffscreen(srcFormats, srcSize);
GLuint tex = CreateTextureForOffscreen(mGL, srcFormats, srcSize);
MOZ_ASSERT(tex);
BlitFramebufferToTexture(srcFB, tex, srcSize, srcSize);

View File

@ -9,6 +9,7 @@
#include "GLContextTypes.h"
#include "GLConsts.h"
#include "nsSize.h"
#include "mozilla/Attributes.h"
struct nsIntSize;
@ -18,6 +19,49 @@ namespace gl {
class GLContext;
/**
* Helper function that creates a 2D texture aSize.width x aSize.height with
* storage type specified by aFormats. Returns GL texture object id.
*
* See mozilla::gl::CreateTexture.
*/
GLuint CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats,
const gfxIntSize& aSize);
/**
* Helper function that creates a 2D texture aSize.width x aSize.height with
* storage type aInternalFormat. Returns GL texture object id.
*
* Initialize textyre parameters to:
* GL_TEXTURE_MIN_FILTER = GL_LINEAR
* GL_TEXTURE_MAG_FILTER = GL_LINEAR
* GL_TEXTURE_WRAP_S = GL_CLAMP_TO_EDGE
* GL_TEXTURE_WRAP_T = GL_CLAMP_TO_EDGE
*/
GLuint CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat,
GLenum aType, const gfxIntSize& aSize);
/**
* Helper function to create, potentially, multisample render buffers suitable
* for offscreen rendering. Buffers of size aSize.width x aSize.height with
* storage specified by aFormat. returns GL render buffer object id.
*/
GLuint CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples,
const gfxIntSize& aSize);
/**
* Helper function to create, potentially, multisample render buffers suitable
* for offscreen rendering. Buffers of size aSize.width x aSize.height with
* storage specified by aFormats. GL render buffer object ids are returned via
* aColorMSRB, aDepthRB, and aStencilRB
*/
void CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats,
const gfxIntSize& aSize, bool aMultisample,
GLuint* aColorMSRB, GLuint* aDepthRB,
GLuint* aStencilRB);
/** Buffer blitting helper */
class GLBlitHelper MOZ_FINAL
{
// The GLContext is the sole owner of the GLBlitHelper.

View File

@ -1345,104 +1345,6 @@ GLContext::ChooseGLFormats(const SurfaceCaps& caps) const
return formats;
}
GLuint
GLContext::CreateTextureForOffscreen(const GLFormats& formats, const gfxIntSize& size)
{
MOZ_ASSERT(formats.color_texInternalFormat);
MOZ_ASSERT(formats.color_texFormat);
MOZ_ASSERT(formats.color_texType);
return CreateTexture(formats.color_texInternalFormat,
formats.color_texFormat,
formats.color_texType,
size);
}
GLuint
GLContext::CreateTexture(GLenum internalFormat, GLenum format, GLenum type, const gfxIntSize& size)
{
GLuint tex = 0;
fGenTextures(1, &tex);
ScopedBindTexture autoTex(this, tex);
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
fTexImage2D(LOCAL_GL_TEXTURE_2D,
0,
internalFormat,
size.width, size.height,
0,
format,
type,
nullptr);
return tex;
}
static inline void
RenderbufferStorageBySamples(GLContext* gl, GLsizei samples, GLenum internalFormat, const gfxIntSize& size)
{
if (samples) {
gl->fRenderbufferStorageMultisample(LOCAL_GL_RENDERBUFFER,
samples,
internalFormat,
size.width, size.height);
} else {
gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER,
internalFormat,
size.width, size.height);
}
}
GLuint
GLContext::CreateRenderbuffer(GLenum format, GLsizei samples, const gfxIntSize& size)
{
GLuint rb = 0;
fGenRenderbuffers(1, &rb);
ScopedBindRenderbuffer autoRB(this, rb);
RenderbufferStorageBySamples(this, samples, format, size);
return rb;
}
void
GLContext::CreateRenderbuffersForOffscreen(const GLFormats& formats, const gfxIntSize& size,
bool multisample,
GLuint* colorMSRB, GLuint* depthRB, GLuint* stencilRB)
{
GLsizei samples = multisample ? formats.samples : 0;
if (colorMSRB) {
MOZ_ASSERT(formats.samples > 0);
MOZ_ASSERT(formats.color_rbFormat);
*colorMSRB = CreateRenderbuffer(formats.color_rbFormat, samples, size);
}
if (depthRB &&
stencilRB &&
formats.depthStencil)
{
*depthRB = CreateRenderbuffer(formats.depthStencil, samples, size);
*stencilRB = *depthRB;
} else {
if (depthRB) {
MOZ_ASSERT(formats.depth);
*depthRB = CreateRenderbuffer(formats.depth, samples, size);
}
if (stencilRB) {
MOZ_ASSERT(formats.stencil);
*stencilRB = CreateRenderbuffer(formats.stencil, samples, size);
}
}
}
bool
GLContext::IsFramebufferComplete(GLuint fb, GLenum* pStatus)
{

View File

@ -2812,25 +2812,8 @@ public:
return *mPixelFormat;
}
GLuint CreateTextureForOffscreen(const GLFormats& formats,
const gfxIntSize& size);
GLuint CreateTexture(GLenum internalFormat,
GLenum format, GLenum type,
const gfxIntSize& size);
GLuint CreateRenderbuffer(GLenum format,
GLsizei samples,
const gfxIntSize& size);
bool IsFramebufferComplete(GLuint fb, GLenum* status = nullptr);
// Pass null to an RB arg to disable its creation.
void CreateRenderbuffersForOffscreen(const GLFormats& formats,
const gfxIntSize& size,
bool multisample,
GLuint* colorMSRB,
GLuint* depthRB,
GLuint* stencilRB);
// Does not check completeness.
void AttachBuffersToFB(GLuint colorTex, GLuint colorRB,
GLuint depthRB, GLuint stencilRB,

View File

@ -8,6 +8,7 @@
#include <cstring>
#include "gfxImageSurface.h"
#include "GLContext.h"
#include "GLBlitHelper.h"
#include "SharedSurfaceGL.h"
#include "SurfaceStream.h"
#ifdef MOZ_WIDGET_GONK
@ -547,8 +548,8 @@ DrawBuffer::Create(GLContext* const gl,
pStencilRB = nullptr;
}
gl->CreateRenderbuffersForOffscreen(formats, size, caps.antialias,
pColorMSRB, pDepthRB, pStencilRB);
CreateRenderbuffersForOffscreen(gl, formats, size, caps.antialias,
pColorMSRB, pDepthRB, pStencilRB);
GLuint fb = 0;
gl->fGenFramebuffers(1, &fb);
@ -600,8 +601,8 @@ ReadBuffer::Create(GLContext* gl,
GLuint* pDepthRB = caps.depth ? &depthRB : nullptr;
GLuint* pStencilRB = caps.stencil ? &stencilRB : nullptr;
gl->CreateRenderbuffersForOffscreen(formats, surf->Size(), caps.antialias,
nullptr, pDepthRB, pStencilRB);
CreateRenderbuffersForOffscreen(gl, formats, surf->Size(), caps.antialias,
nullptr, pDepthRB, pStencilRB);
GLuint colorTex = 0;
GLuint colorRB = 0;

View File

@ -32,7 +32,7 @@ SharedSurface_EGLImage::Create(GLContext* prodGL,
return nullptr;
MOZ_ALWAYS_TRUE(prodGL->MakeCurrent());
GLuint prodTex = prodGL->CreateTextureForOffscreen(formats, size);
GLuint prodTex = CreateTextureForOffscreen(prodGL, formats, size);
if (!prodTex)
return nullptr;
@ -130,7 +130,7 @@ CreateTexturePipe(GLLibraryEGL* const egl, GLContext* const gl,
*out_tex = 0;
*out_image = 0;
GLuint tex = gl->CreateTextureForOffscreen(formats, size);
GLuint tex = CreateTextureForOffscreen(gl, formats, size);
if (!tex)
return false;

View File

@ -247,10 +247,10 @@ SharedSurface_Basic::Create(GLContext* gl,
bool hasAlpha)
{
gl->MakeCurrent();
GLuint tex = gl->CreateTexture(formats.color_texInternalFormat,
formats.color_texFormat,
formats.color_texType,
size);
GLuint tex = CreateTexture(gl, formats.color_texInternalFormat,
formats.color_texFormat,
formats.color_texType,
size);
gfxImageFormat format = gfxImageFormatRGB24;
switch (formats.color_texInternalFormat) {
@ -319,7 +319,7 @@ SharedSurface_GLTexture::Create(GLContext* prodGL,
MOZ_ASSERT(!consGL || prodGL->SharesWith(consGL));
prodGL->MakeCurrent();
GLuint tex = prodGL->CreateTextureForOffscreen(formats, size);
GLuint tex = CreateTextureForOffscreen(prodGL, formats, size);
return new SharedSurface_GLTexture(prodGL, consGL, size, hasAlpha, tex);
}