/*
Copyright (C) 2010, Heikki Salo
All rights reserved.
Distributed under the BSD license:
http://www.opensource.org/licenses/bsd-license.php
*/
#ifndef DP_DEVICE_HPP
#define DP_DEVICE_HPP
#include "stdafx.h"
class DPWindow;
class DPBuffer;
class DPEffect;
class DPInputLayout;
class DPView;
class DPDeviceState;
class DPTexture;
class DPDevice : boost::noncopyable {
public:
~DPDevice();
DPDevice(DPWindow*, UINT, UINT, UINT, UINT, python::object&);
DPDeviceState* createDepthStencilState(python::dict&);
DPDeviceState* createBlendState(python::dict&);
DPDeviceState* createRasterizerState(python::dict&);
DPDeviceState* createSamplerState(python::dict&);
void setState(DPDeviceState&);
DPDeviceState* getState();
void release();
void reset();
void setFullscreenState(bool, UINT, UINT);
void setInputLayout(DPInputLayout&);
void setVertexBuffers(python::object&);
void setIndexBuffer(DPBuffer&);
void setPrimitiveTopology(UINT);
void setRenderTargetsDefault(bool);
void setRenderTargets(python::object&, python::object&);
void drawAuto();
void draw(UINT, UINT);
void drawInstanced(UINT, UINT, UINT, UINT);
void drawIndexed(UINT, UINT, UINT);
void drawIndexedInstanced(UINT, UINT, UINT, int, UINT);
void flush() { mainContext->Flush(); }
void setStreamOutputTargets(python::object&);
UINT checkFormatSupport(UINT);
UINT checkMultisampleQualityLevels(UINT, UINT);
void present(UINT);
UINT getFeatureLevel() { return (UINT)device->GetFeatureLevel(); }
void dispatch(UINT, UINT, UINT);
void setViewports(python::object&);
python::list getViewports();
void setScissorRects(python::object&);
python::list getScissorRects();
ID3D11Device* getDevice() { return device; }
ID3D11DeviceContext* getContext() { return mainContext; }
IDXGISwapChain* getSwapChain() { return swapChain; }
//Misc
python::object getScreenInfo();
DPTexture* getDefaultRT();
DPView* getDefaultRTView();
DPTexture* getDefaultDS();
DPView* getDefaultDSView();
python::object getDisplayModes(UINT);
void restoreDepthStencilState() { mainContext->OMSetDepthStencilState(defaultDSState, 0); }
void restoreBlendState() { float zeros[4] = {0.0f}; mainContext->OMSetBlendState(defaultBlendState, zeros, 0xffffffff); }
void restoreRasterizerState() { mainContext->RSSetState(defaultRasterState); }
void restoreSamplerState() {
mainContext->CSSetSamplers(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - 1, 0);
mainContext->DSSetSamplers(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - 1, 0);
mainContext->GSSetSamplers(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - 1, 0);
mainContext->HSSetSamplers(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - 1, 0);
mainContext->PSSetSamplers(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - 1, 0);
mainContext->VSSetSamplers(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - 1, 0);
}
void setWindow(DPWindow* window) { associatedWindow = window; }
ULONG_PTR getDevicePy();
private:
ID3D11Device* device;
ID3D11DeviceContext* mainContext;
IDXGISwapChain* swapChain;
DPWindow* associatedWindow;
ID3D11Texture2D* renderTarget;
ID3D11RenderTargetView* renderTargetView;
ID3D11Texture2D* depthStencil;
ID3D11DepthStencilView* depthStencilView;
DXGI_FORMAT defaultDSFormat;
//States
ID3D11DepthStencilState* defaultDSState;
ID3D11BlendState* defaultBlendState;
ID3D11RasterizerState* defaultRasterState;
IDXGIAdapter* getAdapterAtIndex(UINT);
void initStates();
};
DPDevice* getDPDevice();
void DPEnableDebug();
bool DPIsDebugEnabled();
#endif