michael@0: // michael@0: // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // Blit.cpp: Surface copy utility class. michael@0: michael@0: #ifndef LIBGLESV2_BLIT_H_ michael@0: #define LIBGLESV2_BLIT_H_ michael@0: michael@0: #include "common/angleutils.h" michael@0: michael@0: namespace gl michael@0: { michael@0: class Framebuffer; michael@0: } michael@0: michael@0: namespace rx michael@0: { michael@0: class Renderer9; michael@0: class TextureStorageInterface2D; michael@0: class TextureStorageInterfaceCube; michael@0: michael@0: class Blit michael@0: { michael@0: public: michael@0: explicit Blit(Renderer9 *renderer); michael@0: ~Blit(); michael@0: michael@0: // Copy from source surface to dest surface. michael@0: // sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left) michael@0: bool copy(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level); michael@0: bool copy(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level); michael@0: michael@0: // Copy from source surface to dest surface. michael@0: // sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left) michael@0: // source is interpreted as RGBA and destFormat specifies the desired result format. For example, if destFormat = GL_RGB, the alpha channel will be forced to 0. michael@0: bool formatConvert(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest); michael@0: michael@0: // 2x2 box filter sample from source to dest. michael@0: // Requires that source is RGB(A) and dest has the same format as source. michael@0: bool boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest); michael@0: michael@0: private: michael@0: rx::Renderer9 *mRenderer; michael@0: michael@0: IDirect3DVertexBuffer9 *mQuadVertexBuffer; michael@0: IDirect3DVertexDeclaration9 *mQuadVertexDeclaration; michael@0: michael@0: void initGeometry(); michael@0: michael@0: bool setFormatConvertShaders(GLenum destFormat); michael@0: michael@0: bool copy(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest); michael@0: IDirect3DTexture9 *copySurfaceToTexture(IDirect3DSurface9 *surface, const RECT &sourceRect); michael@0: void setViewport(const RECT &sourceRect, GLint xoffset, GLint yoffset); michael@0: void setCommonBlitState(); michael@0: RECT getSurfaceRect(IDirect3DSurface9 *surface) const; michael@0: michael@0: // This enum is used to index mCompiledShaders and mShaderSource. michael@0: enum ShaderId michael@0: { michael@0: SHADER_VS_STANDARD, michael@0: SHADER_VS_FLIPY, michael@0: SHADER_PS_PASSTHROUGH, michael@0: SHADER_PS_LUMINANCE, michael@0: SHADER_PS_COMPONENTMASK, michael@0: SHADER_COUNT michael@0: }; michael@0: michael@0: // This actually contains IDirect3DVertexShader9 or IDirect3DPixelShader9 casted to IUnknown. michael@0: IUnknown *mCompiledShaders[SHADER_COUNT]; michael@0: michael@0: template michael@0: bool setShader(ShaderId source, const char *profile, michael@0: D3DShaderType *(Renderer9::*createShader)(const DWORD *, size_t length), michael@0: HRESULT (WINAPI IDirect3DDevice9::*setShader)(D3DShaderType*)); michael@0: michael@0: bool setVertexShader(ShaderId shader); michael@0: bool setPixelShader(ShaderId shader); michael@0: void render(); michael@0: michael@0: void saveState(); michael@0: void restoreState(); michael@0: IDirect3DStateBlock9 *mSavedStateBlock; michael@0: IDirect3DSurface9 *mSavedRenderTarget; michael@0: IDirect3DSurface9 *mSavedDepthStencil; michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(Blit); michael@0: }; michael@0: } michael@0: michael@0: #endif // LIBGLESV2_BLIT_H_