1 // 2 // Copyright 2015 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // StateManager9.h: Defines a class for caching D3D9 state 8 9 #ifndef LIBANGLE_RENDERER_D3D9_STATEMANAGER9_H_ 10 #define LIBANGLE_RENDERER_D3D9_STATEMANAGER9_H_ 11 12 #include "libANGLE/State.h" 13 #include "libANGLE/angletypes.h" 14 #include "libANGLE/renderer/d3d/RendererD3D.h" 15 16 namespace rx 17 { 18 19 class Renderer9; 20 21 struct dx_VertexConstants9 22 { 23 float depthRange[4]; 24 float viewAdjust[4]; 25 float viewCoords[4]; 26 }; 27 28 struct dx_PixelConstants9 29 { 30 float depthRange[4]; 31 float viewCoords[4]; 32 float depthFront[4]; 33 }; 34 35 class StateManager9 final : angle::NonCopyable 36 { 37 public: 38 StateManager9(Renderer9 *renderer9); 39 ~StateManager9(); 40 41 void initialize(); 42 43 void syncState(const gl::State &state, 44 const gl::state::DirtyBits &dirtyBits, 45 const gl::state::ExtendedDirtyBits &extendedDirtyBits); 46 47 void setBlendDepthRasterStates(const gl::State &glState, unsigned int sampleMask); 48 void setScissorState(const gl::Rectangle &scissor, bool enabled); 49 void setViewportState(const gl::Rectangle &viewport, 50 float zNear, 51 float zFar, 52 gl::PrimitiveMode drawMode, 53 GLenum frontFace, 54 bool ignoreViewport); 55 56 void setShaderConstants(); 57 58 void forceSetBlendState(); 59 void forceSetRasterState(); 60 void forceSetDepthStencilState(); 61 void forceSetScissorState(); 62 void forceSetViewportState(); 63 void forceSetDXUniformsState(); 64 65 void updateDepthSizeIfChanged(bool depthStencilInitialized, unsigned int depthSize); 66 void updateStencilSizeIfChanged(bool depthStencilInitialized, unsigned int stencilSize); 67 68 void setRenderTargetBounds(size_t width, size_t height); 69 getRenderTargetWidth()70 int getRenderTargetWidth() const { return mRenderTargetBounds.width; } getRenderTargetHeight()71 int getRenderTargetHeight() const { return mRenderTargetBounds.height; } 72 setAllDirtyBits()73 void setAllDirtyBits() { mDirtyBits.set(); } resetDirtyBits()74 void resetDirtyBits() { mDirtyBits.reset(); } 75 76 private: 77 // Blend state functions 78 void setBlendEnabled(bool enabled); 79 void setBlendColor(const gl::BlendState &blendState, const gl::ColorF &blendColor); 80 void setBlendFuncsEquations(const gl::BlendState &blendState); 81 void setColorMask(const gl::Framebuffer *framebuffer, 82 bool red, 83 bool blue, 84 bool green, 85 bool alpha); 86 void setSampleAlphaToCoverage(bool enabled); 87 void setDither(bool dither); 88 void setSampleMask(unsigned int sampleMask); 89 90 // Current raster state functions 91 void setCullMode(bool cullFace, gl::CullFaceMode cullMode, GLenum frontFace); 92 void setDepthBias(bool polygonOffsetFill, 93 GLfloat polygonOffsetFactor, 94 GLfloat polygonOffsetUnits); 95 96 // Depth stencil state functions 97 void setStencilOpsFront(GLenum stencilFail, 98 GLenum stencilPassDepthFail, 99 GLenum stencilPassDepthPass, 100 bool frontFaceCCW); 101 void setStencilOpsBack(GLenum stencilBackFail, 102 GLenum stencilBackPassDepthFail, 103 GLenum stencilBackPassDepthPass, 104 bool frontFaceCCW); 105 void setStencilBackWriteMask(GLuint stencilBackWriteMask, bool frontFaceCCW); 106 void setDepthFunc(bool depthTest, GLenum depthFunc); 107 void setStencilTestEnabled(bool enabled); 108 void setDepthMask(bool depthMask); 109 void setStencilFuncsFront(GLenum stencilFunc, 110 GLuint stencilMask, 111 GLint stencilRef, 112 bool frontFaceCCW, 113 unsigned int maxStencil); 114 void setStencilFuncsBack(GLenum stencilBackFunc, 115 GLuint stencilBackMask, 116 GLint stencilBackRef, 117 bool frontFaceCCW, 118 unsigned int maxStencil); 119 void setStencilWriteMask(GLuint stencilWriteMask, bool frontFaceCCW); 120 121 void setScissorEnabled(bool scissorEnabled); 122 void setScissorRect(const gl::Rectangle &scissor, bool enabled); 123 124 enum DirtyBitType 125 { 126 // Blend dirty bits 127 DIRTY_BIT_BLEND_ENABLED, 128 DIRTY_BIT_BLEND_COLOR, 129 DIRTY_BIT_BLEND_FUNCS_EQUATIONS, 130 DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE, 131 DIRTY_BIT_COLOR_MASK, 132 DIRTY_BIT_DITHER, 133 DIRTY_BIT_SAMPLE_MASK, 134 135 // Rasterizer dirty bits 136 DIRTY_BIT_CULL_MODE, 137 DIRTY_BIT_DEPTH_BIAS, 138 139 // Depth stencil dirty bits 140 DIRTY_BIT_STENCIL_DEPTH_MASK, 141 DIRTY_BIT_STENCIL_DEPTH_FUNC, 142 DIRTY_BIT_STENCIL_TEST_ENABLED, 143 DIRTY_BIT_STENCIL_FUNCS_FRONT, 144 DIRTY_BIT_STENCIL_FUNCS_BACK, 145 DIRTY_BIT_STENCIL_WRITEMASK_FRONT, 146 DIRTY_BIT_STENCIL_WRITEMASK_BACK, 147 DIRTY_BIT_STENCIL_OPS_FRONT, 148 DIRTY_BIT_STENCIL_OPS_BACK, 149 150 // Scissor dirty bits 151 DIRTY_BIT_SCISSOR_ENABLED, 152 DIRTY_BIT_SCISSOR_RECT, 153 154 // Viewport dirty bits 155 DIRTY_BIT_VIEWPORT, 156 157 DIRTY_BIT_MAX 158 }; 159 160 using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>; 161 162 bool mUsingZeroColorMaskWorkaround; 163 164 bool mCurSampleAlphaToCoverage; 165 166 // Currently applied blend state 167 gl::BlendState mCurBlendState; 168 gl::ColorF mCurBlendColor; 169 unsigned int mCurSampleMask; 170 DirtyBits mBlendStateDirtyBits; 171 172 // Currently applied raster state 173 gl::RasterizerState mCurRasterState; 174 unsigned int mCurDepthSize; 175 DirtyBits mRasterizerStateDirtyBits; 176 177 // Currently applied depth stencil state 178 gl::DepthStencilState mCurDepthStencilState; 179 int mCurStencilRef; 180 int mCurStencilBackRef; 181 bool mCurFrontFaceCCW; 182 unsigned int mCurStencilSize; 183 DirtyBits mDepthStencilStateDirtyBits; 184 185 // Currently applied scissor states 186 gl::Rectangle mCurScissorRect; 187 bool mCurScissorEnabled; 188 gl::Extents mRenderTargetBounds; 189 DirtyBits mScissorStateDirtyBits; 190 191 // Currently applied viewport states 192 bool mForceSetViewport; 193 gl::Rectangle mCurViewport; 194 float mCurNear; 195 float mCurFar; 196 float mCurDepthFront; 197 bool mCurIgnoreViewport; 198 199 dx_VertexConstants9 mVertexConstants; 200 dx_PixelConstants9 mPixelConstants; 201 bool mDxUniformsDirty; 202 203 // FIXME: Unsupported by D3D9 204 static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF; 205 static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK; 206 static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK; 207 208 Renderer9 *mRenderer9; 209 DirtyBits mDirtyBits; 210 }; 211 212 } // namespace rx 213 #endif // LIBANGLE_RENDERER_D3D9_STATEMANAGER9_H_ 214