Fix FBO/Texture/renderbuffer class hierarchy issues

TRAC #14744 Issue=51/52 Delegated format queries to RenderbufferStorage. Eliminated TextureColorbufferProxy by merging it into Colorbuffer. Abstracted texture colorbuffer queries. Moved some conversion functions to the right namespace. Fixed line-endings in Texture.cpp Signed-off-by: Daniel Koch Author: Nicolas Capens <nicolas@transgaming.com> git-svn-id: https://angleproject.googlecode.com/svn/trunk@553 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 7cfb2cff
...@@ -2378,7 +2378,7 @@ void Context::clear(GLbitfield mask) ...@@ -2378,7 +2378,7 @@ void Context::clear(GLbitfield mask)
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
depthStencil->GetDesc(&desc); depthStencil->GetDesc(&desc);
unsigned int stencilSize = es2dx::GetStencilSize(desc.Format); unsigned int stencilSize = dx2es::GetStencilSize(desc.Format);
stencilUnmasked = (0x1 << stencilSize) - 1; stencilUnmasked = (0x1 << stencilSize) - 1;
if (stencilUnmasked != 0x0) if (stencilUnmasked != 0x0)
...@@ -2415,7 +2415,7 @@ void Context::clear(GLbitfield mask) ...@@ -2415,7 +2415,7 @@ void Context::clear(GLbitfield mask)
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
renderTarget->GetDesc(&desc); renderTarget->GetDesc(&desc);
bool alphaUnmasked = (es2dx::GetAlphaSize(desc.Format) == 0) || mState.colorMaskAlpha; bool alphaUnmasked = (dx2es::GetAlphaSize(desc.Format) == 0) || mState.colorMaskAlpha;
const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) && const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) &&
(mState.stencilWritemask & stencilUnmasked) != stencilUnmasked; (mState.stencilWritemask & stencilUnmasked) != stencilUnmasked;
......
...@@ -46,7 +46,7 @@ Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle) const ...@@ -46,7 +46,7 @@ Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle) const
} }
else if (IsTextureTarget(type)) else if (IsTextureTarget(type))
{ {
buffer = context->getTexture(handle)->getColorbuffer(type); buffer = context->getTexture(handle)->getRenderbuffer(type);
} }
else else
{ {
...@@ -307,14 +307,14 @@ GLenum Framebuffer::completeness() ...@@ -307,14 +307,14 @@ GLenum Framebuffer::completeness()
if (mColorbufferType == GL_RENDERBUFFER) if (mColorbufferType == GL_RENDERBUFFER)
{ {
if (!gl::IsColorRenderable(colorbuffer->getFormat())) if (!gl::IsColorRenderable(colorbuffer->getInternalFormat()))
{ {
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
} }
} }
else if (IsTextureTarget(mColorbufferType)) else if (IsTextureTarget(mColorbufferType))
{ {
if (IsCompressed(colorbuffer->getFormat())) if (IsCompressed(colorbuffer->getInternalFormat()))
{ {
return GL_FRAMEBUFFER_UNSUPPORTED; return GL_FRAMEBUFFER_UNSUPPORTED;
} }
...@@ -325,7 +325,7 @@ GLenum Framebuffer::completeness() ...@@ -325,7 +325,7 @@ GLenum Framebuffer::completeness()
return GL_FRAMEBUFFER_UNSUPPORTED; return GL_FRAMEBUFFER_UNSUPPORTED;
} }
if (colorbuffer->getFormat() == GL_LUMINANCE || colorbuffer->getFormat() == GL_LUMINANCE_ALPHA) if (colorbuffer->getInternalFormat() == GL_LUMINANCE || colorbuffer->getInternalFormat() == GL_LUMINANCE_ALPHA)
{ {
return GL_FRAMEBUFFER_UNSUPPORTED; return GL_FRAMEBUFFER_UNSUPPORTED;
} }
...@@ -424,8 +424,8 @@ GLenum Framebuffer::completeness() ...@@ -424,8 +424,8 @@ GLenum Framebuffer::completeness()
if (mDepthbufferType == GL_RENDERBUFFER && mStencilbufferType == GL_RENDERBUFFER) if (mDepthbufferType == GL_RENDERBUFFER && mStencilbufferType == GL_RENDERBUFFER)
{ {
if (depthbuffer->getFormat() != GL_DEPTH24_STENCIL8_OES || if (depthbuffer->getInternalFormat() != GL_DEPTH24_STENCIL8_OES ||
stencilbuffer->getFormat() != GL_DEPTH24_STENCIL8_OES || stencilbuffer->getInternalFormat() != GL_DEPTH24_STENCIL8_OES ||
depthbuffer->getSerial() != stencilbuffer->getSerial()) depthbuffer->getSerial() != stencilbuffer->getSerial())
{ {
return GL_FRAMEBUFFER_UNSUPPORTED; return GL_FRAMEBUFFER_UNSUPPORTED;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace gl namespace gl
{ {
class Texture; class Texture;
// A class derived from RenderbufferStorage is created whenever glRenderbufferStorage // A class derived from RenderbufferStorage is created whenever glRenderbufferStorage
// is called. The specific concrete type depends on whether the internal format is // is called. The specific concrete type depends on whether the internal format is
...@@ -40,34 +40,40 @@ class RenderbufferStorage ...@@ -40,34 +40,40 @@ class RenderbufferStorage
virtual IDirect3DSurface9 *getRenderTarget(); virtual IDirect3DSurface9 *getRenderTarget();
virtual IDirect3DSurface9 *getDepthStencil(); virtual IDirect3DSurface9 *getDepthStencil();
virtual int getWidth() const; virtual GLsizei getWidth() const;
virtual int getHeight() const; virtual GLsizei getHeight() const;
virtual GLenum getFormat() const; virtual GLenum getInternalFormat() const;
virtual bool isFloatingPoint() const; GLuint getRedSize() const;
D3DFORMAT getD3DFormat() const; GLuint getGreenSize() const;
GLsizei getSamples() const; GLuint getBlueSize() const;
unsigned int getSerial() const; GLuint getAlphaSize() const;
GLuint getDepthSize() const;
GLuint getStencilSize() const;
virtual GLsizei getSamples() const;
static unsigned int issueSerial(); virtual D3DFORMAT getD3DFormat() const;
unsigned int getSerial() const;
protected: protected:
void setSize(int width, int height); GLsizei mWidth;
GLenum mFormat; GLsizei mHeight;
GLenum mInternalFormat;
D3DFORMAT mD3DFormat; D3DFORMAT mD3DFormat;
GLsizei mSamples; GLsizei mSamples;
const unsigned int mSerial;
private: private:
DISALLOW_COPY_AND_ASSIGN(RenderbufferStorage); DISALLOW_COPY_AND_ASSIGN(RenderbufferStorage);
static unsigned int mCurrentSerial; static unsigned int issueSerial();
const unsigned int mSerial;
int mWidth; static unsigned int mCurrentSerial;
int mHeight;
}; };
// Renderbuffer implements the GL renderbuffer object. // Renderbuffer implements the GL renderbuffer object.
// It's only a wrapper for a RenderbufferStorage, but the internal object // It's only a proxy for a RenderbufferStorage instance; the internal object
// can change whenever glRenderbufferStorage is called. // can change whenever glRenderbufferStorage is called.
class Renderbuffer : public RefCountObject class Renderbuffer : public RefCountObject
{ {
...@@ -83,10 +89,18 @@ class Renderbuffer : public RefCountObject ...@@ -83,10 +89,18 @@ class Renderbuffer : public RefCountObject
IDirect3DSurface9 *getRenderTarget(); IDirect3DSurface9 *getRenderTarget();
IDirect3DSurface9 *getDepthStencil(); IDirect3DSurface9 *getDepthStencil();
int getWidth() const; GLsizei getWidth() const;
int getHeight() const; GLsizei getHeight() const;
GLenum getFormat() const; GLenum getInternalFormat() const;
D3DFORMAT getD3DFormat() const; D3DFORMAT getD3DFormat() const;
GLuint getRedSize() const;
GLuint getGreenSize() const;
GLuint getBlueSize() const;
GLuint getAlphaSize() const;
GLuint getDepthSize() const;
GLuint getStencilSize() const;
GLsizei getSamples() const;
unsigned int getSerial() const; unsigned int getSerial() const;
void setStorage(RenderbufferStorage *newStorage); void setStorage(RenderbufferStorage *newStorage);
...@@ -102,42 +116,43 @@ class Colorbuffer : public RenderbufferStorage ...@@ -102,42 +116,43 @@ class Colorbuffer : public RenderbufferStorage
{ {
public: public:
explicit Colorbuffer(IDirect3DSurface9 *renderTarget); explicit Colorbuffer(IDirect3DSurface9 *renderTarget);
explicit Colorbuffer(const Texture* texture); Colorbuffer(Texture *texture, GLenum target);
Colorbuffer(int width, int height, GLenum format, GLsizei samples); Colorbuffer(GLsizei width, GLsizei height, GLenum format, GLsizei samples);
~Colorbuffer(); virtual ~Colorbuffer();
bool isColorbuffer() const; virtual bool isColorbuffer() const;
GLuint getRedSize() const; virtual IDirect3DSurface9 *getRenderTarget();
GLuint getGreenSize() const;
GLuint getBlueSize() const;
GLuint getAlphaSize() const;
IDirect3DSurface9 *getRenderTarget(); virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getInternalFormat() const;
protected: virtual D3DFORMAT getD3DFormat() const;
IDirect3DSurface9 *mRenderTarget;
bool isFloatingPoint() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(Colorbuffer); DISALLOW_COPY_AND_ASSIGN(Colorbuffer);
IDirect3DSurface9 *mRenderTarget;
Texture *mTexture;
GLenum mTarget;
}; };
class DepthStencilbuffer : public RenderbufferStorage class DepthStencilbuffer : public RenderbufferStorage
{ {
public: public:
explicit DepthStencilbuffer(IDirect3DSurface9 *depthStencil); explicit DepthStencilbuffer(IDirect3DSurface9 *depthStencil);
DepthStencilbuffer(int width, int height, GLsizei samples); DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
~DepthStencilbuffer(); ~DepthStencilbuffer();
virtual bool isDepthbuffer() const; virtual bool isDepthbuffer() const;
virtual bool isStencilbuffer() const; virtual bool isStencilbuffer() const;
GLuint getDepthSize() const; virtual IDirect3DSurface9 *getDepthStencil();
GLuint getStencilSize() const;
IDirect3DSurface9 *getDepthStencil();
private: private:
DISALLOW_COPY_AND_ASSIGN(DepthStencilbuffer); DISALLOW_COPY_AND_ASSIGN(DepthStencilbuffer);
...@@ -148,12 +163,12 @@ class Depthbuffer : public DepthStencilbuffer ...@@ -148,12 +163,12 @@ class Depthbuffer : public DepthStencilbuffer
{ {
public: public:
explicit Depthbuffer(IDirect3DSurface9 *depthStencil); explicit Depthbuffer(IDirect3DSurface9 *depthStencil);
Depthbuffer(int width, int height, GLsizei samples); Depthbuffer(GLsizei width, GLsizei height, GLsizei samples);
~Depthbuffer(); virtual ~Depthbuffer();
bool isDepthbuffer() const; virtual bool isDepthbuffer() const;
bool isStencilbuffer() const; virtual bool isStencilbuffer() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(Depthbuffer); DISALLOW_COPY_AND_ASSIGN(Depthbuffer);
...@@ -163,12 +178,12 @@ class Stencilbuffer : public DepthStencilbuffer ...@@ -163,12 +178,12 @@ class Stencilbuffer : public DepthStencilbuffer
{ {
public: public:
explicit Stencilbuffer(IDirect3DSurface9 *depthStencil); explicit Stencilbuffer(IDirect3DSurface9 *depthStencil);
Stencilbuffer(int width, int height, GLsizei samples); Stencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
~Stencilbuffer(); virtual ~Stencilbuffer();
bool isDepthbuffer() const; virtual bool isDepthbuffer() const;
bool isStencilbuffer() const; virtual bool isStencilbuffer() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(Stencilbuffer); DISALLOW_COPY_AND_ASSIGN(Stencilbuffer);
......
...@@ -168,12 +168,12 @@ GLenum Texture::getWrapT() const ...@@ -168,12 +168,12 @@ GLenum Texture::getWrapT() const
return mWrapT; return mWrapT;
} }
GLuint Texture::getWidth() const GLsizei Texture::getWidth() const
{ {
return mWidth; return mWidth;
} }
GLuint Texture::getHeight() const GLsizei Texture::getHeight() const
{ {
return mHeight; return mHeight;
} }
...@@ -937,7 +937,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -937,7 +937,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
return false; return false;
} }
if (format != getFormat()) if (format != getInternalFormat())
{ {
error(GL_INVALID_OPERATION); error(GL_INVALID_OPERATION);
return false; return false;
...@@ -1147,7 +1147,7 @@ void Texture::copyNonRenderable(Image *image, GLenum internalFormat, GLint xoffs ...@@ -1147,7 +1147,7 @@ void Texture::copyNonRenderable(Image *image, GLenum internalFormat, GLint xoffs
D3DFORMAT Texture::getD3DFormat() const D3DFORMAT Texture::getD3DFormat() const
{ {
return selectFormat(getFormat(), mType); return selectFormat(getInternalFormat(), mType);
} }
IDirect3DBaseTexture9 *Texture::getTexture() IDirect3DBaseTexture9 *Texture::getTexture()
...@@ -1264,7 +1264,7 @@ GLenum Texture2D::getTarget() const ...@@ -1264,7 +1264,7 @@ GLenum Texture2D::getTarget() const
return GL_TEXTURE_2D; return GL_TEXTURE_2D;
} }
GLenum Texture2D::getFormat() const GLenum Texture2D::getInternalFormat() const
{ {
return mImageArray[0].format; return mImageArray[0].format;
} }
...@@ -1452,7 +1452,7 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo ...@@ -1452,7 +1452,7 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo
if (!isRenderableFormat()) if (!isRenderableFormat())
{ {
copyNonRenderable(&mImageArray[level], getFormat(), xoffset, yoffset, x, y, width, height, renderTarget); copyNonRenderable(&mImageArray[level], getInternalFormat(), xoffset, yoffset, x, y, width, height, renderTarget);
} }
else else
{ {
...@@ -1513,8 +1513,8 @@ bool Texture2D::isComplete() const ...@@ -1513,8 +1513,8 @@ bool Texture2D::isComplete() const
default: UNREACHABLE(); default: UNREACHABLE();
} }
if ((getFormat() == GL_FLOAT && !getContext()->supportsFloatLinearFilter()) || if ((getInternalFormat() == GL_FLOAT && !getContext()->supportsFloatLinearFilter()) ||
(getFormat() == GL_HALF_FLOAT_OES && !getContext()->supportsHalfFloatLinearFilter())) (getInternalFormat() == GL_HALF_FLOAT_OES && !getContext()->supportsHalfFloatLinearFilter()))
{ {
if (mMagFilter != GL_NEAREST || (mMinFilter != GL_NEAREST && mMinFilter != GL_NEAREST_MIPMAP_NEAREST)) if (mMagFilter != GL_NEAREST || (mMinFilter != GL_NEAREST && mMinFilter != GL_NEAREST_MIPMAP_NEAREST))
{ {
...@@ -1562,7 +1562,7 @@ bool Texture2D::isComplete() const ...@@ -1562,7 +1562,7 @@ bool Texture2D::isComplete() const
bool Texture2D::isCompressed() const bool Texture2D::isCompressed() const
{ {
return IsCompressed(getFormat()); return IsCompressed(getInternalFormat());
} }
// Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one // Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one
...@@ -1774,7 +1774,7 @@ void Texture2D::generateMipmaps() ...@@ -1774,7 +1774,7 @@ void Texture2D::generateMipmaps()
} }
} }
Renderbuffer *Texture2D::getColorbuffer(GLenum target) Renderbuffer *Texture2D::getRenderbuffer(GLenum target)
{ {
if (target != GL_TEXTURE_2D) if (target != GL_TEXTURE_2D)
{ {
...@@ -1783,7 +1783,7 @@ Renderbuffer *Texture2D::getColorbuffer(GLenum target) ...@@ -1783,7 +1783,7 @@ Renderbuffer *Texture2D::getColorbuffer(GLenum target)
if (mColorbufferProxy.get() == NULL) if (mColorbufferProxy.get() == NULL)
{ {
mColorbufferProxy.set(new Renderbuffer(id(), new TextureColorbufferProxy(this, target))); mColorbufferProxy.set(new Renderbuffer(id(), new Colorbuffer(this, target)));
} }
return mColorbufferProxy.get(); return mColorbufferProxy.get();
...@@ -1830,7 +1830,7 @@ GLenum TextureCubeMap::getTarget() const ...@@ -1830,7 +1830,7 @@ GLenum TextureCubeMap::getTarget() const
return GL_TEXTURE_CUBE_MAP; return GL_TEXTURE_CUBE_MAP;
} }
GLenum TextureCubeMap::getFormat() const GLenum TextureCubeMap::getInternalFormat() const
{ {
return mImageArray[0][0].format; return mImageArray[0][0].format;
} }
...@@ -1953,8 +1953,8 @@ bool TextureCubeMap::isComplete() const ...@@ -1953,8 +1953,8 @@ bool TextureCubeMap::isComplete() const
} }
} }
if ((getFormat() == GL_FLOAT && !getContext()->supportsFloatLinearFilter()) || if ((getInternalFormat() == GL_FLOAT && !getContext()->supportsFloatLinearFilter()) ||
(getFormat() == GL_HALF_FLOAT_OES && !getContext()->supportsHalfFloatLinearFilter())) (getInternalFormat() == GL_HALF_FLOAT_OES && !getContext()->supportsHalfFloatLinearFilter()))
{ {
if (mMagFilter != GL_NEAREST || (mMinFilter != GL_NEAREST && mMinFilter != GL_NEAREST_MIPMAP_NEAREST)) if (mMagFilter != GL_NEAREST || (mMinFilter != GL_NEAREST && mMinFilter != GL_NEAREST_MIPMAP_NEAREST))
{ {
...@@ -1995,7 +1995,7 @@ bool TextureCubeMap::isComplete() const ...@@ -1995,7 +1995,7 @@ bool TextureCubeMap::isComplete() const
bool TextureCubeMap::isCompressed() const bool TextureCubeMap::isCompressed() const
{ {
return IsCompressed(getFormat()); return IsCompressed(getInternalFormat());
} }
// Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one // Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one
...@@ -2300,7 +2300,7 @@ void TextureCubeMap::copySubImage(GLenum target, GLint level, GLint xoffset, GLi ...@@ -2300,7 +2300,7 @@ void TextureCubeMap::copySubImage(GLenum target, GLint level, GLint xoffset, GLi
if (!isRenderableFormat()) if (!isRenderableFormat())
{ {
copyNonRenderable(&mImageArray[faceindex][level], getFormat(), 0, 0, x, y, width, height, renderTarget); copyNonRenderable(&mImageArray[faceindex][level], getInternalFormat(), 0, 0, x, y, width, height, renderTarget);
} }
else else
{ {
...@@ -2427,7 +2427,7 @@ void TextureCubeMap::generateMipmaps() ...@@ -2427,7 +2427,7 @@ void TextureCubeMap::generateMipmaps()
} }
} }
Renderbuffer *TextureCubeMap::getColorbuffer(GLenum target) Renderbuffer *TextureCubeMap::getRenderbuffer(GLenum target)
{ {
if (!IsCubemapTextureTarget(target)) if (!IsCubemapTextureTarget(target))
{ {
...@@ -2438,7 +2438,7 @@ Renderbuffer *TextureCubeMap::getColorbuffer(GLenum target) ...@@ -2438,7 +2438,7 @@ Renderbuffer *TextureCubeMap::getColorbuffer(GLenum target)
if (mFaceProxies[face].get() == NULL) if (mFaceProxies[face].get() == NULL)
{ {
mFaceProxies[face].set(new Renderbuffer(id(), new TextureColorbufferProxy(this, target))); mFaceProxies[face].set(new Renderbuffer(id(), new Colorbuffer(this, target)));
} }
return mFaceProxies[face].get(); return mFaceProxies[face].get();
...@@ -2461,49 +2461,4 @@ IDirect3DSurface9 *TextureCubeMap::getRenderTarget(GLenum target) ...@@ -2461,49 +2461,4 @@ IDirect3DSurface9 *TextureCubeMap::getRenderTarget(GLenum target)
return renderTarget; return renderTarget;
} }
Texture::TextureColorbufferProxy::TextureColorbufferProxy(Texture *texture, GLenum target)
: Colorbuffer(texture), mTexture(texture), mTarget(target)
{
ASSERT(IsTextureTarget(target));
}
void Texture::TextureColorbufferProxy::addRef() const
{
mTexture->addRef();
}
void Texture::TextureColorbufferProxy::release() const
{
mTexture->release();
}
IDirect3DSurface9 *Texture::TextureColorbufferProxy::getRenderTarget()
{
if (mRenderTarget) mRenderTarget->Release();
mRenderTarget = mTexture->getRenderTarget(mTarget);
return mRenderTarget;
}
int Texture::TextureColorbufferProxy::getWidth() const
{
return mTexture->getWidth();
}
int Texture::TextureColorbufferProxy::getHeight() const
{
return mTexture->getHeight();
}
GLenum Texture::TextureColorbufferProxy::getFormat() const
{
return mTexture->getFormat();
}
bool Texture::TextureColorbufferProxy::isFloatingPoint() const
{
return mTexture->isFloatingPoint();
}
} }
...@@ -57,10 +57,10 @@ class Texture : public RefCountObject ...@@ -57,10 +57,10 @@ class Texture : public RefCountObject
GLenum getWrapS() const; GLenum getWrapS() const;
GLenum getWrapT() const; GLenum getWrapT() const;
GLuint getWidth() const; GLsizei getWidth() const;
GLuint getHeight() const; GLsizei getHeight() const;
virtual GLenum getFormat() const = 0; virtual GLenum getInternalFormat() const = 0;
virtual bool isComplete() const = 0; virtual bool isComplete() const = 0;
virtual bool isCompressed() const = 0; virtual bool isCompressed() const = 0;
bool isFloatingPoint() const; bool isFloatingPoint() const;
...@@ -68,7 +68,7 @@ class Texture : public RefCountObject ...@@ -68,7 +68,7 @@ class Texture : public RefCountObject
D3DFORMAT getD3DFormat() const; D3DFORMAT getD3DFormat() const;
IDirect3DBaseTexture9 *getTexture(); IDirect3DBaseTexture9 *getTexture();
virtual Renderbuffer *getColorbuffer(GLenum target) = 0; virtual Renderbuffer *getRenderbuffer(GLenum target) = 0;
virtual void generateMipmaps() = 0; virtual void generateMipmaps() = 0;
virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0; virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0;
...@@ -78,28 +78,7 @@ class Texture : public RefCountObject ...@@ -78,28 +78,7 @@ class Texture : public RefCountObject
static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1); // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager. static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1); // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager.
protected: protected:
class TextureColorbufferProxy; friend class Colorbuffer;
friend class TextureColorbufferProxy;
class TextureColorbufferProxy : public Colorbuffer
{
public:
TextureColorbufferProxy(Texture *texture, GLenum target);
// target is a 2D-like texture target (GL_TEXTURE_2D or one of the cube face targets)
virtual void addRef() const;
virtual void release() const;
virtual IDirect3DSurface9 *getRenderTarget();
virtual int getWidth() const;
virtual int getHeight() const;
virtual GLenum getFormat() const;
virtual bool isFloatingPoint() const;
private:
Texture *mTexture;
GLenum mTarget;
};
// Helper structure representing a single image layer // Helper structure representing a single image layer
struct Image struct Image
...@@ -147,8 +126,8 @@ class Texture : public RefCountObject ...@@ -147,8 +126,8 @@ class Texture : public RefCountObject
bool isRenderable() const; bool isRenderable() const;
unsigned int mWidth; GLsizei mWidth;
unsigned int mHeight; GLsizei mHeight;
GLenum mMinFilter; GLenum mMinFilter;
GLenum mMagFilter; GLenum mMagFilter;
GLenum mWrapS; GLenum mWrapS;
...@@ -218,7 +197,7 @@ class Texture2D : public Texture ...@@ -218,7 +197,7 @@ class Texture2D : public Texture
~Texture2D(); ~Texture2D();
GLenum getTarget() const; GLenum getTarget() const;
GLenum getFormat() const; GLenum getInternalFormat() const;
void setImage(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); void setImage(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setCompressedImage(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels); void setCompressedImage(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
...@@ -232,7 +211,7 @@ class Texture2D : public Texture ...@@ -232,7 +211,7 @@ class Texture2D : public Texture
virtual void generateMipmaps(); virtual void generateMipmaps();
virtual Renderbuffer *getColorbuffer(GLenum target); virtual Renderbuffer *getRenderbuffer(GLenum target);
private: private:
DISALLOW_COPY_AND_ASSIGN(Texture2D); DISALLOW_COPY_AND_ASSIGN(Texture2D);
...@@ -262,7 +241,7 @@ class TextureCubeMap : public Texture ...@@ -262,7 +241,7 @@ class TextureCubeMap : public Texture
~TextureCubeMap(); ~TextureCubeMap();
GLenum getTarget() const; GLenum getTarget() const;
GLenum getFormat() const; GLenum getInternalFormat() const;
void setImagePosX(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); void setImagePosX(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setImageNegX(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); void setImageNegX(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
...@@ -283,7 +262,7 @@ class TextureCubeMap : public Texture ...@@ -283,7 +262,7 @@ class TextureCubeMap : public Texture
virtual void generateMipmaps(); virtual void generateMipmaps();
virtual Renderbuffer *getColorbuffer(GLenum target); virtual Renderbuffer *getRenderbuffer(GLenum target);
private: private:
DISALLOW_COPY_AND_ASSIGN(TextureCubeMap); DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
......
...@@ -1044,7 +1044,7 @@ void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalforma ...@@ -1044,7 +1044,7 @@ void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalforma
} }
gl::Colorbuffer *source = framebuffer->getColorbuffer(); gl::Colorbuffer *source = framebuffer->getColorbuffer();
GLenum colorbufferFormat = source->getFormat(); GLenum colorbufferFormat = source->getInternalFormat();
// [OpenGL ES 2.0.24] table 3.9 // [OpenGL ES 2.0.24] table 3.9
switch (internalformat) switch (internalformat)
...@@ -1178,7 +1178,7 @@ void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GL ...@@ -1178,7 +1178,7 @@ void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GL
} }
gl::Colorbuffer *source = framebuffer->getColorbuffer(); gl::Colorbuffer *source = framebuffer->getColorbuffer();
GLenum colorbufferFormat = source->getFormat(); GLenum colorbufferFormat = source->getInternalFormat();
gl::Texture *texture = NULL; gl::Texture *texture = NULL;
if (target == GL_TEXTURE_2D) if (target == GL_TEXTURE_2D)
...@@ -1196,7 +1196,7 @@ void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GL ...@@ -1196,7 +1196,7 @@ void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GL
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
GLenum textureFormat = texture->getFormat(); GLenum textureFormat = texture->getInternalFormat();
// [OpenGL ES 2.0.24] table 3.9 // [OpenGL ES 2.0.24] table 3.9
switch (textureFormat) switch (textureFormat)
...@@ -2954,86 +2954,24 @@ void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* ...@@ -2954,86 +2954,24 @@ void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint*
switch (pname) switch (pname)
{ {
case GL_RENDERBUFFER_WIDTH: case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
*params = renderbuffer->getWidth(); case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
break; case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
case GL_RENDERBUFFER_HEIGHT: case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
*params = renderbuffer->getHeight(); case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
break; case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
case GL_RENDERBUFFER_INTERNAL_FORMAT: case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
*params = renderbuffer->getFormat(); case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
break; case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
case GL_RENDERBUFFER_RED_SIZE:
if (renderbuffer->isColorbuffer())
{
*params = static_cast<gl::Colorbuffer*>(renderbuffer->getStorage())->getRedSize();
}
else
{
*params = 0;
}
break;
case GL_RENDERBUFFER_GREEN_SIZE:
if (renderbuffer->isColorbuffer())
{
*params = static_cast<gl::Colorbuffer*>(renderbuffer->getStorage())->getGreenSize();
}
else
{
*params = 0;
}
break;
case GL_RENDERBUFFER_BLUE_SIZE:
if (renderbuffer->isColorbuffer())
{
*params = static_cast<gl::Colorbuffer*>(renderbuffer->getStorage())->getBlueSize();
}
else
{
*params = 0;
}
break;
case GL_RENDERBUFFER_ALPHA_SIZE:
if (renderbuffer->isColorbuffer())
{
*params = static_cast<gl::Colorbuffer*>(renderbuffer->getStorage())->getAlphaSize();
}
else
{
*params = 0;
}
break;
case GL_RENDERBUFFER_DEPTH_SIZE:
if (renderbuffer->isDepthbuffer())
{
*params = static_cast<gl::Depthbuffer*>(renderbuffer->getStorage())->getDepthSize();
}
else
{
*params = 0;
}
break;
case GL_RENDERBUFFER_STENCIL_SIZE:
if (renderbuffer->isStencilbuffer())
{
*params = static_cast<gl::Stencilbuffer*>(renderbuffer->getStorage())->getStencilSize();
}
else
{
*params = 0;
}
break;
case GL_RENDERBUFFER_SAMPLES_ANGLE: case GL_RENDERBUFFER_SAMPLES_ANGLE:
{
if (context->getMaxSupportedSamples() != 0) if (context->getMaxSupportedSamples() != 0)
{ {
*params = renderbuffer->getStorage()->getSamples(); *params = renderbuffer->getSamples();
} }
else else
{ {
return error(GL_INVALID_ENUM); return error(GL_INVALID_ENUM);
} }
}
break; break;
default: default:
return error(GL_INVALID_ENUM); return error(GL_INVALID_ENUM);
...@@ -4797,7 +4735,7 @@ void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint ...@@ -4797,7 +4735,7 @@ void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
if (format != texture->getFormat()) if (format != texture->getInternalFormat())
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
...@@ -4818,7 +4756,7 @@ void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint ...@@ -4818,7 +4756,7 @@ void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
if (format != texture->getFormat()) if (format != texture->getInternalFormat())
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
......
...@@ -608,6 +608,75 @@ void ConvertMinFilter(GLenum minFilter, D3DTEXTUREFILTERTYPE *d3dMinFilter, D3DT ...@@ -608,6 +608,75 @@ void ConvertMinFilter(GLenum minFilter, D3DTEXTUREFILTERTYPE *d3dMinFilter, D3DT
} }
} }
bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount,
D3DPRIMITIVETYPE *d3dPrimitiveType, int *d3dPrimitiveCount)
{
switch (primitiveType)
{
case GL_POINTS:
*d3dPrimitiveType = D3DPT_POINTLIST;
*d3dPrimitiveCount = elementCount;
break;
case GL_LINES:
*d3dPrimitiveType = D3DPT_LINELIST;
*d3dPrimitiveCount = elementCount / 2;
break;
case GL_LINE_LOOP:
*d3dPrimitiveType = D3DPT_LINESTRIP;
*d3dPrimitiveCount = elementCount - 1; // D3D doesn't support line loops, so we draw the last line separately
break;
case GL_LINE_STRIP:
*d3dPrimitiveType = D3DPT_LINESTRIP;
*d3dPrimitiveCount = elementCount - 1;
break;
case GL_TRIANGLES:
*d3dPrimitiveType = D3DPT_TRIANGLELIST;
*d3dPrimitiveCount = elementCount / 3;
break;
case GL_TRIANGLE_STRIP:
*d3dPrimitiveType = D3DPT_TRIANGLESTRIP;
*d3dPrimitiveCount = elementCount - 2;
break;
case GL_TRIANGLE_FAN:
*d3dPrimitiveType = D3DPT_TRIANGLEFAN;
*d3dPrimitiveCount = elementCount - 2;
break;
default:
return false;
}
return true;
}
D3DFORMAT ConvertRenderbufferFormat(GLenum format)
{
switch (format)
{
case GL_RGBA4:
case GL_RGB5_A1:
case GL_RGBA8_OES: return D3DFMT_A8R8G8B8;
case GL_RGB565: return D3DFMT_R5G6B5;
case GL_RGB8_OES: return D3DFMT_X8R8G8B8;
case GL_DEPTH_COMPONENT16:
case GL_STENCIL_INDEX8:
case GL_DEPTH24_STENCIL8_OES: return D3DFMT_D24S8;
default: UNREACHABLE(); return D3DFMT_A8R8G8B8;
}
}
D3DMULTISAMPLE_TYPE GetMultisampleTypeFromSamples(GLsizei samples)
{
if (samples <= 1)
return D3DMULTISAMPLE_NONE;
else
return (D3DMULTISAMPLE_TYPE)samples;
}
}
namespace dx2es
{
unsigned int GetStencilSize(D3DFORMAT stencilFormat) unsigned int GetStencilSize(D3DFORMAT stencilFormat)
{ {
switch(stencilFormat) switch(stencilFormat)
...@@ -625,8 +694,8 @@ unsigned int GetStencilSize(D3DFORMAT stencilFormat) ...@@ -625,8 +694,8 @@ unsigned int GetStencilSize(D3DFORMAT stencilFormat)
case D3DFMT_D32F_LOCKABLE: case D3DFMT_D32F_LOCKABLE:
case D3DFMT_D16: case D3DFMT_D16:
return 0; return 0;
// case D3DFMT_D32_LOCKABLE: return 0; // DirectX 9Ex only //case D3DFMT_D32_LOCKABLE: return 0; // DirectX 9Ex only
// case D3DFMT_S8_LOCKABLE: return 8; // DirectX 9Ex only //case D3DFMT_S8_LOCKABLE: return 8; // DirectX 9Ex only
default: UNREACHABLE(); default: UNREACHABLE();
} }
return 0; return 0;
...@@ -739,62 +808,6 @@ unsigned int GetDepthSize(D3DFORMAT depthFormat) ...@@ -739,62 +808,6 @@ unsigned int GetDepthSize(D3DFORMAT depthFormat)
return 0; return 0;
} }
bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount,
D3DPRIMITIVETYPE *d3dPrimitiveType, int *d3dPrimitiveCount)
{
switch (primitiveType)
{
case GL_POINTS:
*d3dPrimitiveType = D3DPT_POINTLIST;
*d3dPrimitiveCount = elementCount;
break;
case GL_LINES:
*d3dPrimitiveType = D3DPT_LINELIST;
*d3dPrimitiveCount = elementCount / 2;
break;
case GL_LINE_LOOP:
*d3dPrimitiveType = D3DPT_LINESTRIP;
*d3dPrimitiveCount = elementCount - 1; // D3D doesn't support line loops, so we draw the last line separately
break;
case GL_LINE_STRIP:
*d3dPrimitiveType = D3DPT_LINESTRIP;
*d3dPrimitiveCount = elementCount - 1;
break;
case GL_TRIANGLES:
*d3dPrimitiveType = D3DPT_TRIANGLELIST;
*d3dPrimitiveCount = elementCount / 3;
break;
case GL_TRIANGLE_STRIP:
*d3dPrimitiveType = D3DPT_TRIANGLESTRIP;
*d3dPrimitiveCount = elementCount - 2;
break;
case GL_TRIANGLE_FAN:
*d3dPrimitiveType = D3DPT_TRIANGLEFAN;
*d3dPrimitiveCount = elementCount - 2;
break;
default:
return false;
}
return true;
}
D3DFORMAT ConvertRenderbufferFormat(GLenum format)
{
switch (format)
{
case GL_RGBA4:
case GL_RGB5_A1:
case GL_RGBA8_OES: return D3DFMT_A8R8G8B8;
case GL_RGB565: return D3DFMT_R5G6B5;
case GL_RGB8_OES: return D3DFMT_X8R8G8B8;
case GL_DEPTH_COMPONENT16:
case GL_STENCIL_INDEX8:
case GL_DEPTH24_STENCIL8_OES: return D3DFMT_D24S8;
default: UNREACHABLE(); return D3DFMT_A8R8G8B8;
}
}
GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type) GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type)
{ {
if (type == D3DMULTISAMPLE_NONMASKABLE) if (type == D3DMULTISAMPLE_NONMASKABLE)
...@@ -803,19 +816,6 @@ GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type) ...@@ -803,19 +816,6 @@ GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type)
return type; return type;
} }
D3DMULTISAMPLE_TYPE GetMultisampleTypeFromSamples(GLsizei samples)
{
if (samples <= 1)
return D3DMULTISAMPLE_NONE;
else
return (D3DMULTISAMPLE_TYPE)samples;
}
}
namespace dx2es
{
GLenum ConvertBackBufferFormat(D3DFORMAT format) GLenum ConvertBackBufferFormat(D3DFORMAT format)
{ {
switch (format) switch (format)
......
...@@ -58,22 +58,23 @@ D3DCUBEMAP_FACES ConvertCubeFace(GLenum cubeFace); ...@@ -58,22 +58,23 @@ D3DCUBEMAP_FACES ConvertCubeFace(GLenum cubeFace);
DWORD ConvertColorMask(bool red, bool green, bool blue, bool alpha); DWORD ConvertColorMask(bool red, bool green, bool blue, bool alpha);
D3DTEXTUREFILTERTYPE ConvertMagFilter(GLenum magFilter); D3DTEXTUREFILTERTYPE ConvertMagFilter(GLenum magFilter);
void ConvertMinFilter(GLenum minFilter, D3DTEXTUREFILTERTYPE *d3dMinFilter, D3DTEXTUREFILTERTYPE *d3dMipFilter); void ConvertMinFilter(GLenum minFilter, D3DTEXTUREFILTERTYPE *d3dMinFilter, D3DTEXTUREFILTERTYPE *d3dMipFilter);
unsigned int GetAlphaSize(D3DFORMAT colorFormat);
unsigned int GetRedSize(D3DFORMAT colorFormat);
unsigned int GetGreenSize(D3DFORMAT colorFormat);
unsigned int GetBlueSize(D3DFORMAT colorFormat);
unsigned int GetDepthSize(D3DFORMAT depthFormat);
unsigned int GetStencilSize(D3DFORMAT stencilFormat);
bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount, bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount,
D3DPRIMITIVETYPE *d3dPrimitiveType, int *d3dPrimitiveCount); D3DPRIMITIVETYPE *d3dPrimitiveType, int *d3dPrimitiveCount);
D3DFORMAT ConvertRenderbufferFormat(GLenum format); D3DFORMAT ConvertRenderbufferFormat(GLenum format);
D3DMULTISAMPLE_TYPE GetMultisampleTypeFromSamples(GLsizei samples); D3DMULTISAMPLE_TYPE GetMultisampleTypeFromSamples(GLsizei samples);
GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type);
} }
namespace dx2es namespace dx2es
{ {
GLuint GetAlphaSize(D3DFORMAT colorFormat);
GLuint GetRedSize(D3DFORMAT colorFormat);
GLuint GetGreenSize(D3DFORMAT colorFormat);
GLuint GetBlueSize(D3DFORMAT colorFormat);
GLuint GetDepthSize(D3DFORMAT depthFormat);
GLuint GetStencilSize(D3DFORMAT stencilFormat);
GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type);
GLenum ConvertBackBufferFormat(D3DFORMAT format); GLenum ConvertBackBufferFormat(D3DFORMAT format);
GLenum ConvertDepthStencilFormat(D3DFORMAT format); GLenum ConvertDepthStencilFormat(D3DFORMAT format);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment