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);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -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,38 +68,17 @@ class Texture : public RefCountObject ...@@ -68,38 +68,17 @@ 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;
bool isDirty() const; bool isDirty() const;
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,85 +2954,23 @@ void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* ...@@ -2954,85 +2954,23 @@ 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: case GL_RENDERBUFFER_SAMPLES_ANGLE:
if (renderbuffer->isColorbuffer()) if (context->getMaxSupportedSamples() != 0)
{
*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(); *params = renderbuffer->getSamples();
} }
else else
{ {
*params = 0; return error(GL_INVALID_ENUM);
}
break;
case GL_RENDERBUFFER_SAMPLES_ANGLE:
{
if (context->getMaxSupportedSamples() != 0)
{
*params = renderbuffer->getStorage()->getSamples();
}
else
{
return error(GL_INVALID_ENUM);
}
} }
break; break;
default: default:
...@@ -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)
...@@ -852,33 +852,33 @@ GLenum ConvertDepthStencilFormat(D3DFORMAT format) ...@@ -852,33 +852,33 @@ GLenum ConvertDepthStencilFormat(D3DFORMAT format)
std::string getTempPath() std::string getTempPath()
{ {
char path[MAX_PATH]; char path[MAX_PATH];
DWORD pathLen = GetTempPathA(sizeof(path) / sizeof(path[0]), path); DWORD pathLen = GetTempPathA(sizeof(path) / sizeof(path[0]), path);
if (pathLen == 0) if (pathLen == 0)
{ {
UNREACHABLE(); UNREACHABLE();
return std::string(); return std::string();
} }
UINT unique = GetTempFileNameA(path, "sh", 0, path); UINT unique = GetTempFileNameA(path, "sh", 0, path);
if (unique == 0) if (unique == 0)
{ {
UNREACHABLE(); UNREACHABLE();
return std::string(); return std::string();
} }
return path; return path;
} }
void writeFile(const char* path, const void* content, size_t size) void writeFile(const char* path, const void* content, size_t size)
{ {
FILE* file = fopen(path, "w"); FILE* file = fopen(path, "w");
if (!file) if (!file)
{ {
UNREACHABLE(); UNREACHABLE();
return; return;
} }
fwrite(content, sizeof(char), size, file); fwrite(content, sizeof(char), size, file);
fclose(file); fclose(file);
} }
...@@ -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