Add a Renderer11 class for the d3d11 backend.
Trac #21925
Signed-off-by: Nicolas Capens
git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1396 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/libGLESv2.vcxproj b/src/libGLESv2/libGLESv2.vcxproj
index ba081a8..c78cd8f 100644
--- a/src/libGLESv2/libGLESv2.vcxproj
+++ b/src/libGLESv2/libGLESv2.vcxproj
@@ -245,6 +245,7 @@
<ClCompile Include="Query.cpp" />
<ClCompile Include="..\common\RefCountObject.cpp" />
<ClCompile Include="Renderbuffer.cpp" />
+ <ClCompile Include="renderer\Renderer11.cpp" />
<ClCompile Include="renderer\Renderer9.cpp" />
<ClCompile Include="renderer\Image.cpp" />
<ClCompile Include="renderer\renderer9_utils.cpp" />
@@ -280,6 +281,7 @@
<ClInclude Include="Renderbuffer.h" />
<ClInclude Include="renderer\Image.h" />
<ClInclude Include="renderer\Renderer.h" />
+ <ClInclude Include="renderer\Renderer11.h" />
<ClInclude Include="renderer\Renderer9.h" />
<ClInclude Include="renderer\renderer9_utils.h" />
<ClInclude Include="renderer\ShaderCache.h" />
diff --git a/src/libGLESv2/libGLESv2.vcxproj.filters b/src/libGLESv2/libGLESv2.vcxproj.filters
index 4d4106b..5b39fef 100644
--- a/src/libGLESv2/libGLESv2.vcxproj.filters
+++ b/src/libGLESv2/libGLESv2.vcxproj.filters
@@ -98,6 +98,9 @@
<ClCompile Include="renderer\renderer9_utils.cpp">
<Filter>Renderer</Filter>
</ClCompile>
+ <ClCompile Include="renderer\Renderer11.cpp">
+ <Filter>Renderer</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BinaryStream.h">
@@ -205,6 +208,9 @@
<ClInclude Include="renderer\renderer9_utils.h">
<Filter>Renderer</Filter>
</ClInclude>
+ <ClInclude Include="renderer\Renderer11.h">
+ <Filter>Renderer</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="libGLESv2.def">
diff --git a/src/libGLESv2/renderer/Renderer11.cpp b/src/libGLESv2/renderer/Renderer11.cpp
new file mode 100644
index 0000000..b464364
--- /dev/null
+++ b/src/libGLESv2/renderer/Renderer11.cpp
@@ -0,0 +1,398 @@
+//
+// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// Renderer11.cpp: Implements a back-end specific class for the D3D11 renderer.
+
+#include "common/debug.h"
+#include "libGLESv2/utilities.h"
+#include "libGLESv2/renderer/Renderer11.h"
+
+#include "libEGL/Config.h"
+#include "libEGL/Display.h"
+
+namespace rx
+{
+
+Renderer11::Renderer11(egl::Display *display, HDC hDc) : Renderer(display), mDc(hDc)
+{
+ mD3d11Module = NULL;
+ mDxgiModule = NULL;
+
+ mD3d11 = NULL;
+ mDeviceContext = NULL;
+}
+
+Renderer11::~Renderer11()
+{
+ releaseDeviceResources();
+
+ if (mDeviceContext)
+ {
+ mDeviceContext->Release();
+ mDeviceContext = NULL;
+ }
+
+ if (mD3d11)
+ {
+ mD3d11->Release();
+ mD3d11 = NULL;
+ }
+
+ if (mD3d11Module)
+ {
+ mD3d11Module = NULL;
+ }
+
+ if (mDxgiModule)
+ {
+ mDxgiModule = NULL;
+ }
+
+}
+
+EGLint Renderer11::initialize()
+{
+
+ mDxgiModule = GetModuleHandle(TEXT("dxgi.dll"));
+ mD3d11Module = GetModuleHandle(TEXT("d3d11.dll"));
+
+ if (mD3d11Module == NULL || mDxgiModule == NULL)
+ {
+ ERR("No D3D11 or DXGI module found - aborting!\n");
+ return EGL_NOT_INITIALIZED;
+ }
+
+ // TODO: device creation, any one-time setup.
+ UNIMPLEMENTED();
+
+ initializeDevice();
+
+ return EGL_SUCCESS;
+}
+
+// do any one-time device initialization
+// NOTE: this is also needed after a device lost/reset
+// to reset the scene status and ensure the default states are reset.
+void Renderer11::initializeDevice()
+{
+ // Permanent non-default states
+ // TODO
+ UNIMPLEMENTED();
+}
+
+
+int Renderer11::generateConfigs(ConfigDesc **configDescList)
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 0;
+}
+
+void Renderer11::deleteConfigs(ConfigDesc *configDescList)
+{
+ delete [] (configDescList);
+}
+
+void Renderer11::startScene()
+{
+ // TODO: nop in d3d11?
+}
+
+void Renderer11::endScene()
+{
+ // TODO: nop in d3d11?
+}
+
+void Renderer11::sync(bool block)
+{
+ // TODO
+ UNIMPLEMENTED();
+}
+
+void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
+{
+ // TODO
+ UNIMPLEMENTED();
+}
+
+void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture)
+{
+ // TODO
+ UNIMPLEMENTED();
+}
+
+
+void Renderer11::releaseDeviceResources()
+{
+ // TODO
+ UNIMPLEMENTED();
+}
+
+void Renderer11::markDeviceLost()
+{
+ mDeviceLost = true;
+}
+
+bool Renderer11::isDeviceLost()
+{
+ return mDeviceLost;
+}
+
+// set notify to true to broadcast a message to all contexts of the device loss
+bool Renderer11::testDeviceLost(bool notify)
+{
+ bool isLost = false;
+
+ // TODO
+ UNIMPLEMENTED();
+
+ if (isLost)
+ {
+ // ensure we note the device loss --
+ // we'll probably get this done again by markDeviceLost
+ // but best to remember it!
+ // Note that we don't want to clear the device loss status here
+ // -- this needs to be done by resetDevice
+ mDeviceLost = true;
+ if (notify)
+ {
+ mDisplay->notifyDeviceLost();
+ }
+ }
+
+ return isLost;
+}
+
+bool Renderer11::testDeviceResettable()
+{
+ HRESULT status = D3D_OK;
+
+ // TODO
+ UNIMPLEMENTED();
+
+ switch (status)
+ {
+ case D3DERR_DEVICENOTRESET:
+ case D3DERR_DEVICEHUNG:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool Renderer11::resetDevice()
+{
+ releaseDeviceResources();
+
+ // TODO
+ UNIMPLEMENTED();
+
+ // reset device defaults
+ initializeDevice();
+ mDeviceLost = false;
+
+ return true;
+}
+
+DWORD Renderer11::getAdapterVendor() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 0;
+}
+
+const char *Renderer11::getAdapterDescription() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return "UNIMPLEMENTED";
+}
+
+GUID Renderer11::getAdapterIdentifier() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ GUID foo = {};
+ return foo;
+}
+
+bool Renderer11::getDXT1TextureSupport()
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getDXT3TextureSupport()
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getDXT5TextureSupport()
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getDepthTextureSupport() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getFloat32TextureSupport(bool *filtering, bool *renderable)
+{
+ // TODO
+ UNIMPLEMENTED();
+
+ *filtering = false;
+ *renderable = false;
+ return false;
+}
+
+bool Renderer11::getFloat16TextureSupport(bool *filtering, bool *renderable)
+{
+ // TODO
+ UNIMPLEMENTED();
+
+ *filtering = false;
+ *renderable = false;
+ return false;
+}
+
+bool Renderer11::getLuminanceTextureSupport()
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getLuminanceAlphaTextureSupport()
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getTextureFilterAnisotropySupport() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+float Renderer11::getTextureMaxAnisotropy() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 1.0f;
+}
+
+bool Renderer11::getEventQuerySupport()
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getVertexTextureSupport() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getNonPower2TextureSupport() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getOcclusionQuerySupport() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getInstancingSupport() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return false;
+}
+
+bool Renderer11::getShareHandleSupport() const
+{
+ // TODO
+ UNIMPLEMENTED();
+
+ // PIX doesn't seem to support using share handles, so disable them.
+ return false && !gl::perfActive();
+}
+
+bool Renderer11::getShaderModel3Support() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return true;
+}
+
+float Renderer11::getMaxPointSize() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 1.0f;
+}
+
+int Renderer11::getMaxTextureWidth() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 1024;
+}
+
+int Renderer11::getMaxTextureHeight() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 1024;
+}
+
+bool Renderer11::get32BitIndexSupport() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return true;
+}
+
+int Renderer11::getMinSwapInterval() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 1;
+}
+
+int Renderer11::getMaxSwapInterval() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 1;
+}
+
+int Renderer11::getMaxSupportedSamples() const
+{
+ // TODO
+ UNIMPLEMENTED();
+ return 1;
+}
+
+}
\ No newline at end of file
diff --git a/src/libGLESv2/renderer/Renderer11.h b/src/libGLESv2/renderer/Renderer11.h
new file mode 100644
index 0000000..d0a88f3
--- /dev/null
+++ b/src/libGLESv2/renderer/Renderer11.h
@@ -0,0 +1,107 @@
+//
+// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// Renderer11.h: Defines a back-end specific class for the D3D11 renderer.
+
+#ifndef LIBGLESV2_RENDERER_RENDERER11_H_
+#define LIBGLESV2_RENDERER_RENDERER11_H_
+
+#define GL_APICALL
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#define EGLAPI
+#include <EGL/egl.h>
+
+#include <dxgi.h>
+#include <d3d11.h>
+
+#include "common/angleutils.h"
+
+#include "libGLESv2/renderer/Renderer.h"
+
+namespace rx
+{
+
+class Renderer11 : public Renderer
+{
+ public:
+ Renderer11(egl::Display *display, HDC hDc);
+ virtual ~Renderer11();
+
+ virtual EGLint initialize();
+ virtual bool resetDevice();
+
+ virtual int generateConfigs(ConfigDesc **configDescList);
+ virtual void deleteConfigs(ConfigDesc *configDescList);
+
+ virtual void startScene();
+ virtual void endScene();
+
+ virtual void sync(bool block);
+
+ virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
+ virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture);
+
+ // lost device
+ virtual void markDeviceLost();
+ virtual bool isDeviceLost();
+ virtual bool testDeviceLost(bool notify);
+ virtual bool testDeviceResettable();
+
+ // Renderer capabilities
+ virtual DWORD getAdapterVendor() const;
+ virtual const char *getAdapterDescription() const;
+ virtual GUID getAdapterIdentifier() const;
+
+ virtual bool getDXT1TextureSupport();
+ virtual bool getDXT3TextureSupport();
+ virtual bool getDXT5TextureSupport();
+ virtual bool getEventQuerySupport();
+ virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable);
+ virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable);
+ virtual bool getLuminanceTextureSupport();
+ virtual bool getLuminanceAlphaTextureSupport();
+ virtual bool getVertexTextureSupport() const;
+ virtual bool getNonPower2TextureSupport() const;
+ virtual bool getDepthTextureSupport() const;
+ virtual bool getOcclusionQuerySupport() const;
+ virtual bool getInstancingSupport() const;
+ virtual bool getTextureFilterAnisotropySupport() const;
+ virtual float getTextureMaxAnisotropy() const;
+ virtual bool getShareHandleSupport() const;
+
+ virtual bool getShaderModel3Support() const;
+ virtual float getMaxPointSize() const;
+ virtual int getMaxTextureWidth() const;
+ virtual int getMaxTextureHeight() const;
+ virtual bool get32BitIndexSupport() const;
+ virtual int getMinSwapInterval() const;
+ virtual int getMaxSwapInterval() const;
+
+ virtual GLsizei getMaxSupportedSamples() const;
+
+ // D3D11-renderer specific methods
+ ID3D11Device *getDevice() { return mD3d11; }
+ ID3D11DeviceContext *getDeviceContext() { return mDeviceContext; };
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Renderer11);
+
+ HMODULE mD3d11Module;
+ HMODULE mDxgiModule;
+ HDC mDc;
+
+ bool mDeviceLost;
+
+ void initializeDevice();
+ void releaseDeviceResources();
+
+ ID3D11Device *mD3d11;
+ ID3D11DeviceContext *mDeviceContext;
+};
+
+}
+#endif // LIBGLESV2_RENDERER_RENDERER11_H_
diff --git a/src/libGLESv2/renderer/Renderer9.cpp b/src/libGLESv2/renderer/Renderer9.cpp
index c34befb..7b306b5 100644
--- a/src/libGLESv2/renderer/Renderer9.cpp
+++ b/src/libGLESv2/renderer/Renderer9.cpp
@@ -4,8 +4,7 @@
// found in the LICENSE file.
//
-// Renderer.cpp: Implements a back-end specific class that hides the details of the
-// implementation-specific renderer.
+// Renderer9.cpp: Implements a back-end specific class for the D3D9 renderer.
#include "common/debug.h"
#include "libGLESv2/utilities.h"
diff --git a/src/libGLESv2/renderer/Renderer9.h b/src/libGLESv2/renderer/Renderer9.h
index 943b011..26db5b8 100644
--- a/src/libGLESv2/renderer/Renderer9.h
+++ b/src/libGLESv2/renderer/Renderer9.h
@@ -4,8 +4,7 @@
// found in the LICENSE file.
//
-// Renderer.h: Defines a back-end specific class that hides the details of the
-// implementation-specific renderer.
+// Renderer9.h: Defines a back-end specific class for the D3D9 renderer.
#ifndef LIBGLESV2_RENDERER_RENDERER9_H_
#define LIBGLESV2_RENDERER_RENDERER9_H_
@@ -20,7 +19,7 @@
#define EGLAPI
#include <EGL/egl.h>
-#include <d3d9.h> // D3D9_REPLACE
+#include <d3d9.h>
#include "common/angleutils.h"
#include "libGLESv2/renderer/ShaderCache.h"
@@ -76,7 +75,7 @@
virtual bool testDeviceResettable();
// Renderer capabilities
- IDirect3DDevice9 *getDevice() {return mDevice;}; // D3D9_REPLACE
+ IDirect3DDevice9 *getDevice() { return mDevice; }
virtual DWORD getAdapterVendor() const;
virtual const char *getAdapterDescription() const;
virtual GUID getAdapterIdentifier() const;