Eliminate getDisplay() and getDevice() calls within the Context.

TRAC #18399 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@805 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 22152117
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 804 #define BUILD_REVISION 805
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -40,6 +40,9 @@ namespace gl ...@@ -40,6 +40,9 @@ namespace gl
{ {
Context::Context(const egl::Config *config, const gl::Context *shareContext) : mConfig(config) Context::Context(const egl::Config *config, const gl::Context *shareContext) : mConfig(config)
{ {
mDisplay = NULL;
mDevice = NULL;
mFenceHandleAllocator.setBaseHandle(0); mFenceHandleAllocator.setBaseHandle(0);
setClearColor(0.0f, 0.0f, 0.0f, 0.0f); setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
...@@ -234,19 +237,20 @@ Context::~Context() ...@@ -234,19 +237,20 @@ Context::~Context()
void Context::makeCurrent(egl::Display *display, egl::Surface *surface) void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
{ {
IDirect3DDevice9 *device = display->getDevice(); mDisplay = display;
mDevice = mDisplay->getDevice();
if (!mHasBeenCurrent) if (!mHasBeenCurrent)
{ {
mDeviceCaps = display->getDeviceCaps(); mDeviceCaps = mDisplay->getDeviceCaps();
mVertexDataManager = new VertexDataManager(this, device); mVertexDataManager = new VertexDataManager(this, mDevice);
mIndexDataManager = new IndexDataManager(this, device); mIndexDataManager = new IndexDataManager(this, mDevice);
mBlit = new Blit(this); mBlit = new Blit(this);
mSupportsShaderModel3 = mDeviceCaps.PixelShaderVersion == D3DPS_VERSION(3, 0); mSupportsShaderModel3 = mDeviceCaps.PixelShaderVersion == D3DPS_VERSION(3, 0);
mSupportsVertexTexture = display->getVertexTextureSupport(); mSupportsVertexTexture = mDisplay->getVertexTextureSupport();
mSupportsNonPower2Texture = display->getNonPower2TextureSupport(); mSupportsNonPower2Texture = mDisplay->getNonPower2TextureSupport();
mMaxTextureDimension = std::min(std::min((int)mDeviceCaps.MaxTextureWidth, (int)mDeviceCaps.MaxTextureHeight), mMaxTextureDimension = std::min(std::min((int)mDeviceCaps.MaxTextureWidth, (int)mDeviceCaps.MaxTextureHeight),
(int)gl::IMPLEMENTATION_MAX_TEXTURE_SIZE); (int)gl::IMPLEMENTATION_MAX_TEXTURE_SIZE);
...@@ -268,7 +272,7 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface) ...@@ -268,7 +272,7 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
for (int i = 0; i < sizeof(renderBufferFormats) / sizeof(D3DFORMAT); ++i) for (int i = 0; i < sizeof(renderBufferFormats) / sizeof(D3DFORMAT); ++i)
{ {
bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1]; bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1];
display->getMultiSampleSupport(renderBufferFormats[i], multisampleArray); mDisplay->getMultiSampleSupport(renderBufferFormats[i], multisampleArray);
mMultiSampleSupport[renderBufferFormats[i]] = multisampleArray; mMultiSampleSupport[renderBufferFormats[i]] = multisampleArray;
for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j) for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j)
...@@ -282,14 +286,14 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface) ...@@ -282,14 +286,14 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
mMaxSupportedSamples = max; mMaxSupportedSamples = max;
mSupportsEventQueries = display->getEventQuerySupport(); mSupportsEventQueries = mDisplay->getEventQuerySupport();
mSupportsDXT1Textures = display->getDXT1TextureSupport(); mSupportsDXT1Textures = mDisplay->getDXT1TextureSupport();
mSupportsDXT3Textures = display->getDXT3TextureSupport(); mSupportsDXT3Textures = mDisplay->getDXT3TextureSupport();
mSupportsDXT5Textures = display->getDXT5TextureSupport(); mSupportsDXT5Textures = mDisplay->getDXT5TextureSupport();
mSupportsFloatTextures = display->getFloatTextureSupport(&mSupportsFloatLinearFilter, &mSupportsFloatRenderableTextures); mSupportsFloatTextures = mDisplay->getFloatTextureSupport(&mSupportsFloatLinearFilter, &mSupportsFloatRenderableTextures);
mSupportsHalfFloatTextures = display->getHalfFloatTextureSupport(&mSupportsHalfFloatLinearFilter, &mSupportsHalfFloatRenderableTextures); mSupportsHalfFloatTextures = mDisplay->getHalfFloatTextureSupport(&mSupportsHalfFloatLinearFilter, &mSupportsHalfFloatRenderableTextures);
mSupportsLuminanceTextures = display->getLuminanceTextureSupport(); mSupportsLuminanceTextures = mDisplay->getLuminanceTextureSupport();
mSupportsLuminanceAlphaTextures = display->getLuminanceAlphaTextureSupport(); mSupportsLuminanceAlphaTextures = mDisplay->getLuminanceAlphaTextureSupport();
mSupports32bitIndices = mDeviceCaps.MaxVertexIndex >= (1 << 16); mSupports32bitIndices = mDeviceCaps.MaxVertexIndex >= (1 << 16);
...@@ -1620,8 +1624,6 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu ...@@ -1620,8 +1624,6 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
// scissor rectangle to the Direct3D 9 device // scissor rectangle to the Direct3D 9 device
bool Context::applyRenderTarget(bool ignoreViewport) bool Context::applyRenderTarget(bool ignoreViewport)
{ {
IDirect3DDevice9 *device = getDevice();
Framebuffer *framebufferObject = getDrawFramebuffer(); Framebuffer *framebufferObject = getDrawFramebuffer();
if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
...@@ -1642,7 +1644,7 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1642,7 +1644,7 @@ bool Context::applyRenderTarget(bool ignoreViewport)
{ {
return false; // Context must be lost return false; // Context must be lost
} }
device->SetRenderTarget(0, renderTarget); mDevice->SetRenderTarget(0, renderTarget);
mAppliedRenderTargetSerial = renderTargetSerial; mAppliedRenderTargetSerial = renderTargetSerial;
mScissorStateDirty = true; // Scissor area must be clamped to render target's size-- this is different for different render targets. mScissorStateDirty = true; // Scissor area must be clamped to render target's size-- this is different for different render targets.
renderTargetChanged = true; renderTargetChanged = true;
...@@ -1677,7 +1679,7 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1677,7 +1679,7 @@ bool Context::applyRenderTarget(bool ignoreViewport)
stencilbufferSerial != mAppliedStencilbufferSerial || stencilbufferSerial != mAppliedStencilbufferSerial ||
!mDepthStencilInitialized) !mDepthStencilInitialized)
{ {
device->SetDepthStencilSurface(depthStencil); mDevice->SetDepthStencilSurface(depthStencil);
mAppliedDepthbufferSerial = depthbufferSerial; mAppliedDepthbufferSerial = depthbufferSerial;
mAppliedStencilbufferSerial = stencilbufferSerial; mAppliedStencilbufferSerial = stencilbufferSerial;
mDepthStencilInitialized = true; mDepthStencilInitialized = true;
...@@ -1730,7 +1732,7 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1730,7 +1732,7 @@ bool Context::applyRenderTarget(bool ignoreViewport)
if (!mViewportInitialized || memcmp(&viewport, &mSetViewport, sizeof mSetViewport) != 0) if (!mViewportInitialized || memcmp(&viewport, &mSetViewport, sizeof mSetViewport) != 0)
{ {
device->SetViewport(&viewport); mDevice->SetViewport(&viewport);
mSetViewport = viewport; mSetViewport = viewport;
mViewportInitialized = true; mViewportInitialized = true;
mDxUniformsDirty = true; mDxUniformsDirty = true;
...@@ -1745,12 +1747,12 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1745,12 +1747,12 @@ bool Context::applyRenderTarget(bool ignoreViewport)
rect.top = clamp(rect.top, 0L, static_cast<LONG>(mRenderTargetDesc.Height)); rect.top = clamp(rect.top, 0L, static_cast<LONG>(mRenderTargetDesc.Height));
rect.right = clamp(rect.right, 0L, static_cast<LONG>(mRenderTargetDesc.Width)); rect.right = clamp(rect.right, 0L, static_cast<LONG>(mRenderTargetDesc.Width));
rect.bottom = clamp(rect.bottom, 0L, static_cast<LONG>(mRenderTargetDesc.Height)); rect.bottom = clamp(rect.bottom, 0L, static_cast<LONG>(mRenderTargetDesc.Height));
device->SetScissorRect(&rect); mDevice->SetScissorRect(&rect);
device->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE); mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
} }
else else
{ {
device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
} }
mScissorStateDirty = false; mScissorStateDirty = false;
...@@ -1786,7 +1788,6 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1786,7 +1788,6 @@ bool Context::applyRenderTarget(bool ignoreViewport)
// Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device // Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device
void Context::applyState(GLenum drawMode) void Context::applyState(GLenum drawMode)
{ {
IDirect3DDevice9 *device = getDevice();
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
Framebuffer *framebufferObject = getDrawFramebuffer(); Framebuffer *framebufferObject = getDrawFramebuffer();
...@@ -1801,8 +1802,7 @@ void Context::applyState(GLenum drawMode) ...@@ -1801,8 +1802,7 @@ void Context::applyState(GLenum drawMode)
GLint alwaysFront = !isTriangleMode(drawMode); GLint alwaysFront = !isTriangleMode(drawMode);
programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront); programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront);
egl::Display *display = getDisplay(); D3DADAPTER_IDENTIFIER9 *identifier = mDisplay->getAdapterIdentifier();
D3DADAPTER_IDENTIFIER9 *identifier = display->getAdapterIdentifier();
bool zeroColorMaskAllowed = identifier->VendorId != 0x1002; bool zeroColorMaskAllowed = identifier->VendorId != 0x1002;
// Apparently some ATI cards have a bug where a draw with a zero color // Apparently some ATI cards have a bug where a draw with a zero color
// write mask can cause later draws to have incorrect results. Instead, // write mask can cause later draws to have incorrect results. Instead,
...@@ -1814,11 +1814,11 @@ void Context::applyState(GLenum drawMode) ...@@ -1814,11 +1814,11 @@ void Context::applyState(GLenum drawMode)
{ {
if (mState.cullFace) if (mState.cullFace)
{ {
device->SetRenderState(D3DRS_CULLMODE, es2dx::ConvertCullMode(mState.cullMode, adjustedFrontFace)); mDevice->SetRenderState(D3DRS_CULLMODE, es2dx::ConvertCullMode(mState.cullMode, adjustedFrontFace));
} }
else else
{ {
device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
} }
mCullStateDirty = false; mCullStateDirty = false;
...@@ -1828,12 +1828,12 @@ void Context::applyState(GLenum drawMode) ...@@ -1828,12 +1828,12 @@ void Context::applyState(GLenum drawMode)
{ {
if (mState.depthTest) if (mState.depthTest)
{ {
device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
device->SetRenderState(D3DRS_ZFUNC, es2dx::ConvertComparison(mState.depthFunc)); mDevice->SetRenderState(D3DRS_ZFUNC, es2dx::ConvertComparison(mState.depthFunc));
} }
else else
{ {
device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
} }
mDepthStateDirty = false; mDepthStateDirty = false;
...@@ -1849,43 +1849,43 @@ void Context::applyState(GLenum drawMode) ...@@ -1849,43 +1849,43 @@ void Context::applyState(GLenum drawMode)
{ {
if (mState.blend) if (mState.blend)
{ {
device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
if (mState.sourceBlendRGB != GL_CONSTANT_ALPHA && mState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA && if (mState.sourceBlendRGB != GL_CONSTANT_ALPHA && mState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA &&
mState.destBlendRGB != GL_CONSTANT_ALPHA && mState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA) mState.destBlendRGB != GL_CONSTANT_ALPHA && mState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA)
{ {
device->SetRenderState(D3DRS_BLENDFACTOR, es2dx::ConvertColor(mState.blendColor)); mDevice->SetRenderState(D3DRS_BLENDFACTOR, es2dx::ConvertColor(mState.blendColor));
} }
else else
{ {
device->SetRenderState(D3DRS_BLENDFACTOR, D3DCOLOR_RGBA(unorm<8>(mState.blendColor.alpha), mDevice->SetRenderState(D3DRS_BLENDFACTOR, D3DCOLOR_RGBA(unorm<8>(mState.blendColor.alpha),
unorm<8>(mState.blendColor.alpha), unorm<8>(mState.blendColor.alpha),
unorm<8>(mState.blendColor.alpha), unorm<8>(mState.blendColor.alpha),
unorm<8>(mState.blendColor.alpha))); unorm<8>(mState.blendColor.alpha)));
} }
device->SetRenderState(D3DRS_SRCBLEND, es2dx::ConvertBlendFunc(mState.sourceBlendRGB)); mDevice->SetRenderState(D3DRS_SRCBLEND, es2dx::ConvertBlendFunc(mState.sourceBlendRGB));
device->SetRenderState(D3DRS_DESTBLEND, es2dx::ConvertBlendFunc(mState.destBlendRGB)); mDevice->SetRenderState(D3DRS_DESTBLEND, es2dx::ConvertBlendFunc(mState.destBlendRGB));
device->SetRenderState(D3DRS_BLENDOP, es2dx::ConvertBlendOp(mState.blendEquationRGB)); mDevice->SetRenderState(D3DRS_BLENDOP, es2dx::ConvertBlendOp(mState.blendEquationRGB));
if (mState.sourceBlendRGB != mState.sourceBlendAlpha || if (mState.sourceBlendRGB != mState.sourceBlendAlpha ||
mState.destBlendRGB != mState.destBlendAlpha || mState.destBlendRGB != mState.destBlendAlpha ||
mState.blendEquationRGB != mState.blendEquationAlpha) mState.blendEquationRGB != mState.blendEquationAlpha)
{ {
device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
device->SetRenderState(D3DRS_SRCBLENDALPHA, es2dx::ConvertBlendFunc(mState.sourceBlendAlpha)); mDevice->SetRenderState(D3DRS_SRCBLENDALPHA, es2dx::ConvertBlendFunc(mState.sourceBlendAlpha));
device->SetRenderState(D3DRS_DESTBLENDALPHA, es2dx::ConvertBlendFunc(mState.destBlendAlpha)); mDevice->SetRenderState(D3DRS_DESTBLENDALPHA, es2dx::ConvertBlendFunc(mState.destBlendAlpha));
device->SetRenderState(D3DRS_BLENDOPALPHA, es2dx::ConvertBlendOp(mState.blendEquationAlpha)); mDevice->SetRenderState(D3DRS_BLENDOPALPHA, es2dx::ConvertBlendOp(mState.blendEquationAlpha));
} }
else else
{ {
device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE); mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE);
} }
} }
else else
{ {
device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
} }
mBlendStateDirty = false; mBlendStateDirty = false;
...@@ -1895,8 +1895,8 @@ void Context::applyState(GLenum drawMode) ...@@ -1895,8 +1895,8 @@ void Context::applyState(GLenum drawMode)
{ {
if (mState.stencilTest && framebufferObject->hasStencil()) if (mState.stencilTest && framebufferObject->hasStencil())
{ {
device->SetRenderState(D3DRS_STENCILENABLE, TRUE); mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
device->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE); mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE);
// FIXME: Unsupported by D3D9 // FIXME: Unsupported by D3D9
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF; const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF;
...@@ -1914,37 +1914,37 @@ void Context::applyState(GLenum drawMode) ...@@ -1914,37 +1914,37 @@ void Context::applyState(GLenum drawMode)
gl::DepthStencilbuffer *stencilbuffer = framebufferObject->getStencilbuffer(); gl::DepthStencilbuffer *stencilbuffer = framebufferObject->getStencilbuffer();
GLuint maxStencil = (1 << stencilbuffer->getStencilSize()) - 1; GLuint maxStencil = (1 << stencilbuffer->getStencilSize()) - 1;
device->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilWritemask); mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilWritemask);
device->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC, mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC,
es2dx::ConvertComparison(mState.stencilFunc)); es2dx::ConvertComparison(mState.stencilFunc));
device->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, (mState.stencilRef < (GLint)maxStencil) ? mState.stencilRef : maxStencil); mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, (mState.stencilRef < (GLint)maxStencil) ? mState.stencilRef : maxStencil);
device->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilMask); mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilMask);
device->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL, mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL,
es2dx::ConvertStencilOp(mState.stencilFail)); es2dx::ConvertStencilOp(mState.stencilFail));
device->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL, mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL,
es2dx::ConvertStencilOp(mState.stencilPassDepthFail)); es2dx::ConvertStencilOp(mState.stencilPassDepthFail));
device->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS, mDevice->SetRenderState(adjustedFrontFace == GL_CCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS,
es2dx::ConvertStencilOp(mState.stencilPassDepthPass)); es2dx::ConvertStencilOp(mState.stencilPassDepthPass));
device->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilBackWritemask); mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilBackWritemask);
device->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC, mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC,
es2dx::ConvertComparison(mState.stencilBackFunc)); es2dx::ConvertComparison(mState.stencilBackFunc));
device->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, (mState.stencilBackRef < (GLint)maxStencil) ? mState.stencilBackRef : maxStencil); mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, (mState.stencilBackRef < (GLint)maxStencil) ? mState.stencilBackRef : maxStencil);
device->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilBackMask); mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilBackMask);
device->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL, mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL,
es2dx::ConvertStencilOp(mState.stencilBackFail)); es2dx::ConvertStencilOp(mState.stencilBackFail));
device->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL, mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL,
es2dx::ConvertStencilOp(mState.stencilBackPassDepthFail)); es2dx::ConvertStencilOp(mState.stencilBackPassDepthFail));
device->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS, mDevice->SetRenderState(adjustedFrontFace == GL_CW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS,
es2dx::ConvertStencilOp(mState.stencilBackPassDepthPass)); es2dx::ConvertStencilOp(mState.stencilBackPassDepthPass));
} }
else else
{ {
device->SetRenderState(D3DRS_STENCILENABLE, FALSE); mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
} }
mStencilStateDirty = false; mStencilStateDirty = false;
...@@ -1958,18 +1958,18 @@ void Context::applyState(GLenum drawMode) ...@@ -1958,18 +1958,18 @@ void Context::applyState(GLenum drawMode)
if (colorMask == 0 && !zeroColorMaskAllowed) if (colorMask == 0 && !zeroColorMaskAllowed)
{ {
// Enable green channel, but set blending so nothing will be drawn. // Enable green channel, but set blending so nothing will be drawn.
device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_GREEN); mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_GREEN);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO); mDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); mDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); mDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
} }
else else
{ {
device->SetRenderState(D3DRS_COLORWRITEENABLE, colorMask); mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, colorMask);
} }
device->SetRenderState(D3DRS_ZWRITEENABLE, mState.depthMask ? TRUE : FALSE); mDevice->SetRenderState(D3DRS_ZWRITEENABLE, mState.depthMask ? TRUE : FALSE);
mMaskStateDirty = false; mMaskStateDirty = false;
} }
...@@ -1981,15 +1981,15 @@ void Context::applyState(GLenum drawMode) ...@@ -1981,15 +1981,15 @@ void Context::applyState(GLenum drawMode)
gl::DepthStencilbuffer *depthbuffer = framebufferObject->getDepthbuffer(); gl::DepthStencilbuffer *depthbuffer = framebufferObject->getDepthbuffer();
if (depthbuffer) if (depthbuffer)
{ {
device->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&mState.polygonOffsetFactor)); mDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&mState.polygonOffsetFactor));
float depthBias = ldexp(mState.polygonOffsetUnits, -(int)(depthbuffer->getDepthSize())); float depthBias = ldexp(mState.polygonOffsetUnits, -(int)(depthbuffer->getDepthSize()));
device->SetRenderState(D3DRS_DEPTHBIAS, *((DWORD*)&depthBias)); mDevice->SetRenderState(D3DRS_DEPTHBIAS, *((DWORD*)&depthBias));
} }
} }
else else
{ {
device->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, 0); mDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, 0);
device->SetRenderState(D3DRS_DEPTHBIAS, 0); mDevice->SetRenderState(D3DRS_DEPTHBIAS, 0);
} }
mPolygonOffsetStateDirty = false; mPolygonOffsetStateDirty = false;
...@@ -2002,7 +2002,7 @@ void Context::applyState(GLenum drawMode) ...@@ -2002,7 +2002,7 @@ void Context::applyState(GLenum drawMode)
FIXME("Sample alpha to coverage is unimplemented."); FIXME("Sample alpha to coverage is unimplemented.");
} }
device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE); mDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
if (mState.sampleCoverage) if (mState.sampleCoverage)
{ {
unsigned int mask = 0; unsigned int mask = 0;
...@@ -2027,11 +2027,11 @@ void Context::applyState(GLenum drawMode) ...@@ -2027,11 +2027,11 @@ void Context::applyState(GLenum drawMode)
mask = ~mask; mask = ~mask;
} }
device->SetRenderState(D3DRS_MULTISAMPLEMASK, mask); mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, mask);
} }
else else
{ {
device->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
} }
mSampleStateDirty = false; mSampleStateDirty = false;
...@@ -2039,7 +2039,7 @@ void Context::applyState(GLenum drawMode) ...@@ -2039,7 +2039,7 @@ void Context::applyState(GLenum drawMode)
if (mDitherStateDirty) if (mDitherStateDirty)
{ {
device->SetRenderState(D3DRS_DITHERENABLE, mState.dither ? TRUE : FALSE); mDevice->SetRenderState(D3DRS_DITHERENABLE, mState.dither ? TRUE : FALSE);
mDitherStateDirty = false; mDitherStateDirty = false;
} }
...@@ -2055,20 +2055,19 @@ GLenum Context::applyVertexBuffer(GLint first, GLsizei count) ...@@ -2055,20 +2055,19 @@ GLenum Context::applyVertexBuffer(GLint first, GLsizei count)
return err; return err;
} }
return mVertexDeclarationCache.applyDeclaration(attributes, getCurrentProgram()); return mVertexDeclarationCache.applyDeclaration(mDevice, attributes, getCurrentProgram());
} }
// Applies the indices and element array bindings to the Direct3D 9 device // Applies the indices and element array bindings to the Direct3D 9 device
GLenum Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) GLenum Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo)
{ {
IDirect3DDevice9 *device = getDevice();
GLenum err = mIndexDataManager->prepareIndexData(type, count, mState.elementArrayBuffer.get(), indices, indexInfo); GLenum err = mIndexDataManager->prepareIndexData(type, count, mState.elementArrayBuffer.get(), indices, indexInfo);
if (err == GL_NO_ERROR) if (err == GL_NO_ERROR)
{ {
if (indexInfo->serial != mAppliedIBSerial) if (indexInfo->serial != mAppliedIBSerial)
{ {
device->SetIndices(indexInfo->indexBuffer); mDevice->SetIndices(indexInfo->indexBuffer);
mAppliedIBSerial = indexInfo->serial; mAppliedIBSerial = indexInfo->serial;
} }
} }
...@@ -2079,15 +2078,14 @@ GLenum Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode ...@@ -2079,15 +2078,14 @@ GLenum Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode
// Applies the shaders and shader constants to the Direct3D 9 device // Applies the shaders and shader constants to the Direct3D 9 device
void Context::applyShaders() void Context::applyShaders()
{ {
IDirect3DDevice9 *device = getDevice();
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
if (programObject->getSerial() != mAppliedProgramSerial) if (programObject->getSerial() != mAppliedProgramSerial)
{ {
IDirect3DVertexShader9 *vertexShader = programObject->getVertexShader(); IDirect3DVertexShader9 *vertexShader = programObject->getVertexShader();
IDirect3DPixelShader9 *pixelShader = programObject->getPixelShader(); IDirect3DPixelShader9 *pixelShader = programObject->getPixelShader();
device->SetPixelShader(pixelShader); mDevice->SetPixelShader(pixelShader);
device->SetVertexShader(vertexShader); mDevice->SetVertexShader(vertexShader);
programObject->dirtyAllUniforms(); programObject->dirtyAllUniforms();
mAppliedProgramSerial = programObject->getSerial(); mAppliedProgramSerial = programObject->getSerial();
} }
...@@ -2111,7 +2109,6 @@ void Context::applyTextures() ...@@ -2111,7 +2109,6 @@ void Context::applyTextures()
// and sets the texture and its addressing/filtering state (or NULL when inactive). // and sets the texture and its addressing/filtering state (or NULL when inactive).
void Context::applyTextures(SamplerType type) void Context::applyTextures(SamplerType type)
{ {
IDirect3DDevice9 *device = getDevice();
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type
...@@ -2143,24 +2140,24 @@ void Context::applyTextures(SamplerType type) ...@@ -2143,24 +2140,24 @@ void Context::applyTextures(SamplerType type)
GLenum minFilter = texture->getMinFilter(); GLenum minFilter = texture->getMinFilter();
GLenum magFilter = texture->getMagFilter(); GLenum magFilter = texture->getMagFilter();
device->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, es2dx::ConvertTextureWrap(wrapS)); mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, es2dx::ConvertTextureWrap(wrapS));
device->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, es2dx::ConvertTextureWrap(wrapT)); mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, es2dx::ConvertTextureWrap(wrapT));
device->SetSamplerState(d3dSampler, D3DSAMP_MAGFILTER, es2dx::ConvertMagFilter(magFilter)); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAGFILTER, es2dx::ConvertMagFilter(magFilter));
D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter; D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter;
es2dx::ConvertMinFilter(minFilter, &d3dMinFilter, &d3dMipFilter); es2dx::ConvertMinFilter(minFilter, &d3dMinFilter, &d3dMipFilter);
device->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter);
device->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter);
} }
if (appliedTextureSerial[samplerIndex] != texture->getSerial() || texture->isDirtyImage()) if (appliedTextureSerial[samplerIndex] != texture->getSerial() || texture->isDirtyImage())
{ {
device->SetTexture(d3dSampler, d3dTexture); mDevice->SetTexture(d3dSampler, d3dTexture);
} }
} }
else else
{ {
device->SetTexture(d3dSampler, getIncompleteTexture(textureType)->getTexture()); mDevice->SetTexture(d3dSampler, getIncompleteTexture(textureType)->getTexture());
} }
appliedTextureSerial[samplerIndex] = texture->getSerial(); appliedTextureSerial[samplerIndex] = texture->getSerial();
...@@ -2171,7 +2168,7 @@ void Context::applyTextures(SamplerType type) ...@@ -2171,7 +2168,7 @@ void Context::applyTextures(SamplerType type)
{ {
if (appliedTextureSerial[samplerIndex] != 0) if (appliedTextureSerial[samplerIndex] != 0)
{ {
device->SetTexture(d3dSampler, NULL); mDevice->SetTexture(d3dSampler, NULL);
appliedTextureSerial[samplerIndex] = 0; appliedTextureSerial[samplerIndex] = 0;
} }
} }
...@@ -2208,13 +2205,11 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum ...@@ -2208,13 +2205,11 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
return; // Context must be lost, return silently return; // Context must be lost, return silently
} }
IDirect3DDevice9 *device = getDevice();
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
renderTarget->GetDesc(&desc); renderTarget->GetDesc(&desc);
IDirect3DSurface9 *systemSurface; IDirect3DSurface9 *systemSurface;
HRESULT result = device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &systemSurface, NULL); HRESULT result = mDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &systemSurface, NULL);
if (FAILED(result)) if (FAILED(result))
{ {
...@@ -2228,7 +2223,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum ...@@ -2228,7 +2223,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
} }
result = device->GetRenderTargetData(renderTarget, systemSurface); result = mDevice->GetRenderTargetData(renderTarget, systemSurface);
if (FAILED(result)) if (FAILED(result))
{ {
...@@ -2457,8 +2452,6 @@ void Context::clear(GLbitfield mask) ...@@ -2457,8 +2452,6 @@ void Context::clear(GLbitfield mask)
return error(GL_INVALID_FRAMEBUFFER_OPERATION); return error(GL_INVALID_FRAMEBUFFER_OPERATION);
} }
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice();
DWORD flags = 0; DWORD flags = 0;
if (mask & GL_COLOR_BUFFER_BIT) if (mask & GL_COLOR_BUFFER_BIT)
...@@ -2550,32 +2543,32 @@ void Context::clear(GLbitfield mask) ...@@ -2550,32 +2543,32 @@ void Context::clear(GLbitfield mask)
HRESULT hr; HRESULT hr;
if (mMaskedClearSavedState == NULL) if (mMaskedClearSavedState == NULL)
{ {
hr = device->BeginStateBlock(); hr = mDevice->BeginStateBlock();
ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY);
device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
device->SetRenderState(D3DRS_ZENABLE, FALSE); mDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
device->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
device->SetRenderState(D3DRS_COLORWRITEENABLE, 0); mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
device->SetRenderState(D3DRS_STENCILENABLE, FALSE); mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
device->SetPixelShader(NULL); mDevice->SetPixelShader(NULL);
device->SetVertexShader(NULL); mDevice->SetVertexShader(NULL);
device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); mDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
device->SetStreamSource(0, NULL, 0, 0); mDevice->SetStreamSource(0, NULL, 0, 0);
device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
device->SetRenderState(D3DRS_TEXTUREFACTOR, color); mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color);
device->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
hr = device->EndStateBlock(&mMaskedClearSavedState); hr = mDevice->EndStateBlock(&mMaskedClearSavedState);
ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY);
} }
...@@ -2587,51 +2580,51 @@ void Context::clear(GLbitfield mask) ...@@ -2587,51 +2580,51 @@ void Context::clear(GLbitfield mask)
ASSERT(SUCCEEDED(hr)); ASSERT(SUCCEEDED(hr));
} }
device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
device->SetRenderState(D3DRS_ZENABLE, FALSE); mDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
device->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
if (flags & D3DCLEAR_TARGET) if (flags & D3DCLEAR_TARGET)
{ {
device->SetRenderState(D3DRS_COLORWRITEENABLE, es2dx::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen, mState.colorMaskBlue, mState.colorMaskAlpha)); mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, es2dx::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen, mState.colorMaskBlue, mState.colorMaskAlpha));
} }
else else
{ {
device->SetRenderState(D3DRS_COLORWRITEENABLE, 0); mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
} }
if (stencilUnmasked != 0x0 && (flags & D3DCLEAR_STENCIL)) if (stencilUnmasked != 0x0 && (flags & D3DCLEAR_STENCIL))
{ {
device->SetRenderState(D3DRS_STENCILENABLE, TRUE); mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
device->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE); mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE);
device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); mDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
device->SetRenderState(D3DRS_STENCILREF, stencil); mDevice->SetRenderState(D3DRS_STENCILREF, stencil);
device->SetRenderState(D3DRS_STENCILWRITEMASK, mState.stencilWritemask); mDevice->SetRenderState(D3DRS_STENCILWRITEMASK, mState.stencilWritemask);
device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE); mDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE);
device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE); mDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE);
device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); mDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);
mStencilStateDirty = true; mStencilStateDirty = true;
} }
else else
{ {
device->SetRenderState(D3DRS_STENCILENABLE, FALSE); mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
} }
device->SetPixelShader(NULL); mDevice->SetPixelShader(NULL);
device->SetVertexShader(NULL); mDevice->SetVertexShader(NULL);
device->SetFVF(D3DFVF_XYZRHW); mDevice->SetFVF(D3DFVF_XYZRHW);
device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
device->SetRenderState(D3DRS_TEXTUREFACTOR, color); mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color);
device->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
float quad[4][4]; // A quadrilateral covering the target, aligned to match the edges float quad[4][4]; // A quadrilateral covering the target, aligned to match the edges
quad[0][0] = -0.5f; quad[0][0] = -0.5f;
...@@ -2654,14 +2647,14 @@ void Context::clear(GLbitfield mask) ...@@ -2654,14 +2647,14 @@ void Context::clear(GLbitfield mask)
quad[3][2] = 0.0f; quad[3][2] = 0.0f;
quad[3][3] = 1.0f; quad[3][3] = 1.0f;
display->startScene(); mDisplay->startScene();
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float[4])); mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float[4]));
if (flags & D3DCLEAR_ZBUFFER) if (flags & D3DCLEAR_ZBUFFER)
{ {
device->SetRenderState(D3DRS_ZENABLE, TRUE); mDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); mDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
device->Clear(0, NULL, D3DCLEAR_ZBUFFER, color, depth, stencil); mDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, color, depth, stencil);
} }
if (mMaskedClearSavedState != NULL) if (mMaskedClearSavedState != NULL)
...@@ -2671,7 +2664,7 @@ void Context::clear(GLbitfield mask) ...@@ -2671,7 +2664,7 @@ void Context::clear(GLbitfield mask)
} }
else if (flags) else if (flags)
{ {
device->Clear(0, NULL, flags, color, depth, stencil); mDevice->Clear(0, NULL, flags, color, depth, stencil);
} }
} }
...@@ -2682,8 +2675,6 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count) ...@@ -2682,8 +2675,6 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice();
D3DPRIMITIVETYPE primitiveType; D3DPRIMITIVETYPE primitiveType;
int primitiveCount; int primitiveCount;
...@@ -2718,9 +2709,9 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count) ...@@ -2718,9 +2709,9 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
if (!cullSkipsDraw(mode)) if (!cullSkipsDraw(mode))
{ {
display->startScene(); mDisplay->startScene();
device->DrawPrimitive(primitiveType, 0, primitiveCount); mDevice->DrawPrimitive(primitiveType, 0, primitiveCount);
if (mode == GL_LINE_LOOP) // Draw the last segment separately if (mode == GL_LINE_LOOP) // Draw the last segment separately
{ {
...@@ -2741,8 +2732,6 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void * ...@@ -2741,8 +2732,6 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice();
D3DPRIMITIVETYPE primitiveType; D3DPRIMITIVETYPE primitiveType;
int primitiveCount; int primitiveCount;
...@@ -2785,9 +2774,9 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void * ...@@ -2785,9 +2774,9 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *
if (!cullSkipsDraw(mode)) if (!cullSkipsDraw(mode))
{ {
display->startScene(); mDisplay->startScene();
device->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, vertexCount, indexInfo.startIndex, primitiveCount); mDevice->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, vertexCount, indexInfo.startIndex, primitiveCount);
if (mode == GL_LINE_LOOP) // Draw the last segment separately if (mode == GL_LINE_LOOP) // Draw the last segment separately
{ {
...@@ -2798,12 +2787,10 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void * ...@@ -2798,12 +2787,10 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *
void Context::finish() void Context::finish()
{ {
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice();
IDirect3DQuery9 *occlusionQuery = NULL; IDirect3DQuery9 *occlusionQuery = NULL;
HRESULT result; HRESULT result;
result = device->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery); result = mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery);
if (FAILED(result)) if (FAILED(result))
{ {
ERR("CreateQuery failed hr=%x\n", result); ERR("CreateQuery failed hr=%x\n", result);
...@@ -2816,7 +2803,7 @@ void Context::finish() ...@@ -2816,7 +2803,7 @@ void Context::finish()
} }
IDirect3DStateBlock9 *savedState = NULL; IDirect3DStateBlock9 *savedState = NULL;
result = device->CreateStateBlock(D3DSBT_ALL, &savedState); result = mDevice->CreateStateBlock(D3DSBT_ALL, &savedState);
if (FAILED(result)) if (FAILED(result))
{ {
ERR("CreateStateBlock failed hr=%x\n", result); ERR("CreateStateBlock failed hr=%x\n", result);
...@@ -2841,12 +2828,12 @@ void Context::finish() ...@@ -2841,12 +2828,12 @@ void Context::finish()
} }
// Render something outside the render target // Render something outside the render target
device->SetPixelShader(NULL); mDevice->SetPixelShader(NULL);
device->SetVertexShader(NULL); mDevice->SetVertexShader(NULL);
device->SetFVF(D3DFVF_XYZRHW); mDevice->SetFVF(D3DFVF_XYZRHW);
float data[4] = {-1.0f, -1.0f, -1.0f, 1.0f}; float data[4] = {-1.0f, -1.0f, -1.0f, 1.0f};
display->startScene(); mDisplay->startScene();
device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data)); mDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data));
result = occlusionQuery->Issue(D3DISSUE_END); result = occlusionQuery->Issue(D3DISSUE_END);
if (FAILED(result)) if (FAILED(result))
...@@ -2877,11 +2864,10 @@ void Context::finish() ...@@ -2877,11 +2864,10 @@ void Context::finish()
void Context::flush() void Context::flush()
{ {
IDirect3DDevice9 *device = getDevice();
IDirect3DQuery9 *eventQuery = NULL; IDirect3DQuery9 *eventQuery = NULL;
HRESULT result; HRESULT result;
result = device->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery); result = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery);
if (FAILED(result)) if (FAILED(result))
{ {
ERR("CreateQuery failed hr=%x\n", result); ERR("CreateQuery failed hr=%x\n", result);
...@@ -2913,7 +2899,6 @@ void Context::flush() ...@@ -2913,7 +2899,6 @@ void Context::flush()
void Context::drawClosingLine(unsigned int first, unsigned int last) void Context::drawClosingLine(unsigned int first, unsigned int last)
{ {
IDirect3DDevice9 *device = getDevice();
IDirect3DIndexBuffer9 *indexBuffer = NULL; IDirect3DIndexBuffer9 *indexBuffer = NULL;
bool succeeded = false; bool succeeded = false;
UINT offset; UINT offset;
...@@ -2924,7 +2909,7 @@ void Context::drawClosingLine(unsigned int first, unsigned int last) ...@@ -2924,7 +2909,7 @@ void Context::drawClosingLine(unsigned int first, unsigned int last)
if (!mClosingIB) if (!mClosingIB)
{ {
mClosingIB = new StreamingIndexBuffer(device, CLOSING_INDEX_BUFFER_SIZE, D3DFMT_INDEX32); mClosingIB = new StreamingIndexBuffer(mDevice, CLOSING_INDEX_BUFFER_SIZE, D3DFMT_INDEX32);
} }
mClosingIB->reserveSpace(spaceNeeded, GL_UNSIGNED_INT); mClosingIB->reserveSpace(spaceNeeded, GL_UNSIGNED_INT);
...@@ -2945,7 +2930,7 @@ void Context::drawClosingLine(unsigned int first, unsigned int last) ...@@ -2945,7 +2930,7 @@ void Context::drawClosingLine(unsigned int first, unsigned int last)
if (!mClosingIB) if (!mClosingIB)
{ {
mClosingIB = new StreamingIndexBuffer(device, CLOSING_INDEX_BUFFER_SIZE, D3DFMT_INDEX16); mClosingIB = new StreamingIndexBuffer(mDevice, CLOSING_INDEX_BUFFER_SIZE, D3DFMT_INDEX16);
} }
mClosingIB->reserveSpace(spaceNeeded, GL_UNSIGNED_SHORT); mClosingIB->reserveSpace(spaceNeeded, GL_UNSIGNED_SHORT);
...@@ -2963,10 +2948,10 @@ void Context::drawClosingLine(unsigned int first, unsigned int last) ...@@ -2963,10 +2948,10 @@ void Context::drawClosingLine(unsigned int first, unsigned int last)
if (succeeded) if (succeeded)
{ {
device->SetIndices(mClosingIB->getBuffer()); mDevice->SetIndices(mClosingIB->getBuffer());
mAppliedIBSerial = mClosingIB->getSerial(); mAppliedIBSerial = mClosingIB->getSerial();
device->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, last, offset, 1); mDevice->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, last, offset, 1);
} }
else else
{ {
...@@ -3493,8 +3478,7 @@ const char *Context::getExtensionString() const ...@@ -3493,8 +3478,7 @@ const char *Context::getExtensionString() const
void Context::initRendererString() void Context::initRendererString()
{ {
egl::Display *display = getDisplay(); D3DADAPTER_IDENTIFIER9 *identifier = mDisplay->getAdapterIdentifier();
D3DADAPTER_IDENTIFIER9 *identifier = display->getAdapterIdentifier();
mRendererString = "ANGLE ("; mRendererString = "ANGLE (";
mRendererString += identifier->Description; mRendererString += identifier->Description;
...@@ -3510,8 +3494,6 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3510,8 +3494,6 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
GLbitfield mask) GLbitfield mask)
{ {
IDirect3DDevice9 *device = getDevice();
Framebuffer *readFramebuffer = getReadFramebuffer(); Framebuffer *readFramebuffer = getReadFramebuffer();
Framebuffer *drawFramebuffer = getDrawFramebuffer(); Framebuffer *drawFramebuffer = getDrawFramebuffer();
...@@ -3752,12 +3734,11 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3752,12 +3734,11 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
if (blitRenderTarget || blitDepthStencil) if (blitRenderTarget || blitDepthStencil)
{ {
egl::Display *display = getDisplay(); mDisplay->endScene();
display->endScene();
if (blitRenderTarget) if (blitRenderTarget)
{ {
HRESULT result = device->StretchRect(readFramebuffer->getRenderTarget(), &sourceTrimmedRect, HRESULT result = mDevice->StretchRect(readFramebuffer->getRenderTarget(), &sourceTrimmedRect,
drawFramebuffer->getRenderTarget(), &destTrimmedRect, D3DTEXF_NONE); drawFramebuffer->getRenderTarget(), &destTrimmedRect, D3DTEXF_NONE);
if (FAILED(result)) if (FAILED(result))
...@@ -3769,7 +3750,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3769,7 +3750,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
if (blitDepthStencil) if (blitDepthStencil)
{ {
HRESULT result = device->StretchRect(readFramebuffer->getDepthStencil(), NULL, drawFramebuffer->getDepthStencil(), NULL, D3DTEXF_NONE); HRESULT result = mDevice->StretchRect(readFramebuffer->getDepthStencil(), NULL, drawFramebuffer->getDepthStencil(), NULL, D3DTEXF_NONE);
if (FAILED(result)) if (FAILED(result))
{ {
...@@ -3800,10 +3781,8 @@ VertexDeclarationCache::~VertexDeclarationCache() ...@@ -3800,10 +3781,8 @@ VertexDeclarationCache::~VertexDeclarationCache()
} }
} }
GLenum VertexDeclarationCache::applyDeclaration(TranslatedAttribute attributes[], Program *program) GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], Program *program)
{ {
IDirect3DDevice9 *device = getDevice();
D3DVERTEXELEMENT9 elements[MAX_VERTEX_ATTRIBS + 1]; D3DVERTEXELEMENT9 elements[MAX_VERTEX_ATTRIBS + 1];
D3DVERTEXELEMENT9 *element = &elements[0]; D3DVERTEXELEMENT9 *element = &elements[0];
......
...@@ -228,7 +228,7 @@ class VertexDeclarationCache ...@@ -228,7 +228,7 @@ class VertexDeclarationCache
VertexDeclarationCache(); VertexDeclarationCache();
~VertexDeclarationCache(); ~VertexDeclarationCache();
GLenum applyDeclaration(TranslatedAttribute attributes[], Program *program); GLenum applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], Program *program);
void markStateDirty(); void markStateDirty();
...@@ -497,6 +497,8 @@ class Context ...@@ -497,6 +497,8 @@ class Context
void initRendererString(); void initRendererString();
const egl::Config *const mConfig; const egl::Config *const mConfig;
egl::Display *mDisplay;
IDirect3DDevice9 *mDevice;
State mState; State mState;
......
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