1 #include "precompiled.h" 2 // 3 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 // 7 8 // RenderTarget9.cpp: Implements a D3D9-specific wrapper for IDirect3DSurface9 9 // pointers retained by renderbuffers. 10 11 #include "libGLESv2/renderer/RenderTarget9.h" 12 #include "libGLESv2/renderer/Renderer9.h" 13 14 #include "libGLESv2/renderer/renderer9_utils.h" 15 #include "libGLESv2/main.h" 16 17 namespace rx 18 { 19 20 RenderTarget9::RenderTarget9(Renderer *renderer, IDirect3DSurface9 *surface) 21 { 22 mRenderer = Renderer9::makeRenderer9(renderer); 23 mRenderTarget = surface; 24 25 if (mRenderTarget) 26 { 27 D3DSURFACE_DESC description; 28 mRenderTarget->GetDesc(&description); 29 30 mWidth = description.Width; 31 mHeight = description.Height; 32 33 mInternalFormat = d3d9_gl::GetEquivalentFormat(description.Format); 34 mActualFormat = d3d9_gl::GetEquivalentFormat(description.Format); 35 mSamples = d3d9_gl::GetSamplesFromMultisampleType(description.MultiSampleType); 36 } 37 } 38 39 RenderTarget9::RenderTarget9(Renderer *renderer, GLsizei width, GLsizei height, GLenum format, GLsizei samples) 40 { 41 mRenderer = Renderer9::makeRenderer9(renderer); 42 mRenderTarget = NULL; 43 44 D3DFORMAT requestedFormat = gl_d3d9::ConvertRenderbufferFormat(format); 45 int supportedSamples = mRenderer->getNearestSupportedSamples(requestedFormat, samples); 46 47 if (supportedSamples == -1) 48 { 49 gl::error(GL_OUT_OF_MEMORY); 50 51 return; 52 } 53 54 HRESULT result = D3DERR_INVALIDCALL; 55 56 if (width > 0 && height > 0) 57 { 58 if (requestedFormat == D3DFMT_D24S8) 59 { 60 result = mRenderer->getDevice()->CreateDepthStencilSurface(width, height, requestedFormat, 61 gl_d3d9::GetMultisampleTypeFromSamples(supportedSamples), 62 0, FALSE, &mRenderTarget, NULL); 63 } 64 else 65 { 66 result = mRenderer->getDevice()->CreateRenderTarget(width, height, requestedFormat, 67 gl_d3d9::GetMultisampleTypeFromSamples(supportedSamples), 68 0, FALSE, &mRenderTarget, NULL); 69 } 70 71 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) 72 { 73 gl::error(GL_OUT_OF_MEMORY); 74 75 return; 76 } 77 78 ASSERT(SUCCEEDED(result)); 79 } 80 81 mWidth = width; 82 mHeight = height; 83 mInternalFormat = format; 84 mSamples = supportedSamples; 85 mActualFormat = d3d9_gl::GetEquivalentFormat(requestedFormat); 86 } 87 88 RenderTarget9::~RenderTarget9() 89 { 90 if (mRenderTarget) 91 { 92 mRenderTarget->Release(); 93 } 94 } 95 96 RenderTarget9 *RenderTarget9::makeRenderTarget9(RenderTarget *target) 97 { 98 ASSERT(HAS_DYNAMIC_TYPE(rx::RenderTarget9*, target)); 99 return static_cast<rx::RenderTarget9*>(target); 100 } 101 102 IDirect3DSurface9 *RenderTarget9::getSurface() 103 { 104 // Caller is responsible for releasing the returned surface reference. 105 if (mRenderTarget) 106 { 107 mRenderTarget->AddRef(); 108 } 109 110 return mRenderTarget; 111 } 112 113 }