mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-10 17:24:29 +00:00
Bug 1149728. Move CreateXForOffscreen functions. r=jrmuizel
This commit is contained in:
parent
dda611f73d
commit
41fcf39971
@ -35,119 +35,6 @@ using mozilla::layers::PlanarYCbCrData;
|
||||
namespace mozilla {
|
||||
namespace gl {
|
||||
|
||||
static void
|
||||
RenderbufferStorageBySamples(GLContext* aGL, GLsizei aSamples,
|
||||
GLenum aInternalFormat, const gfx::IntSize& 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 gfx::IntSize& aSize, bool linear)
|
||||
{
|
||||
GLuint tex = 0;
|
||||
aGL->fGenTextures(1, &tex);
|
||||
ScopedBindTexture autoTex(aGL, tex);
|
||||
|
||||
aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D,
|
||||
LOCAL_GL_TEXTURE_MIN_FILTER, linear ? LOCAL_GL_LINEAR
|
||||
: LOCAL_GL_NEAREST);
|
||||
aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D,
|
||||
LOCAL_GL_TEXTURE_MAG_FILTER, linear ? LOCAL_GL_LINEAR
|
||||
: LOCAL_GL_NEAREST);
|
||||
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 gfx::IntSize& 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 gfx::IntSize& 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 gfx::IntSize& 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)
|
||||
|
@ -28,48 +28,6 @@ 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 gfx::IntSize& 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 gfx::IntSize& aSize, bool linear = true);
|
||||
|
||||
/**
|
||||
* 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 gfx::IntSize& 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 gfx::IntSize& aSize, bool aMultisample,
|
||||
GLuint* aColorMSRB, GLuint* aDepthRB,
|
||||
GLuint* aStencilRB);
|
||||
|
||||
|
||||
/** Buffer blitting helper */
|
||||
class GLBlitHelper final
|
||||
{
|
||||
|
@ -2937,5 +2937,52 @@ GLContext::IsDrawingToDefaultFramebuffer()
|
||||
return Screen()->IsDrawFramebufferDefault();
|
||||
}
|
||||
|
||||
GLuint
|
||||
CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat,
|
||||
GLenum aType, const gfx::IntSize& aSize, bool linear)
|
||||
{
|
||||
GLuint tex = 0;
|
||||
aGL->fGenTextures(1, &tex);
|
||||
ScopedBindTexture autoTex(aGL, tex);
|
||||
|
||||
aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D,
|
||||
LOCAL_GL_TEXTURE_MIN_FILTER, linear ? LOCAL_GL_LINEAR
|
||||
: LOCAL_GL_NEAREST);
|
||||
aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D,
|
||||
LOCAL_GL_TEXTURE_MAG_FILTER, linear ? LOCAL_GL_LINEAR
|
||||
: LOCAL_GL_NEAREST);
|
||||
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 gfx::IntSize& 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);
|
||||
}
|
||||
|
||||
|
||||
} /* namespace gl */
|
||||
} /* namespace mozilla */
|
||||
|
@ -3652,6 +3652,28 @@ MarkBitfieldByStrings(const std::vector<nsCString>& strList,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 gfx::IntSize& 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 gfx::IntSize& aSize, bool linear = true);
|
||||
|
||||
} /* namespace gl */
|
||||
} /* namespace mozilla */
|
||||
|
||||
|
@ -618,6 +618,73 @@ GLScreenBuffer::IsReadFramebufferDefault() const
|
||||
return SharedSurf()->mAttachType == AttachmentType::Screen;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Utils
|
||||
|
||||
static void
|
||||
RenderbufferStorageBySamples(GLContext* aGL, GLsizei aSamples,
|
||||
GLenum aInternalFormat, const gfx::IntSize& 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);
|
||||
}
|
||||
}
|
||||
|
||||
static GLuint
|
||||
CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples,
|
||||
const gfx::IntSize& aSize)
|
||||
{
|
||||
GLuint rb = 0;
|
||||
aGL->fGenRenderbuffers(1, &rb);
|
||||
ScopedBindRenderbuffer autoRB(aGL, rb);
|
||||
|
||||
RenderbufferStorageBySamples(aGL, aSamples, aFormat, aSize);
|
||||
|
||||
return rb;
|
||||
}
|
||||
|
||||
static void
|
||||
CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats,
|
||||
const gfx::IntSize& 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// DrawBuffer
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user