2014-06-12 21:48:04 -04:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "DirectXTK\SpriteBatch.h"
|
2014-06-23 16:38:01 -04:00
|
|
|
#include "DirectXTK\SpriteFont.h"
|
2014-06-19 17:06:00 -04:00
|
|
|
#include "../Core/IVideoDevice.h"
|
2014-07-06 19:54:47 -04:00
|
|
|
#include "../Core/IMessageManager.h"
|
2014-06-12 21:48:04 -04:00
|
|
|
|
|
|
|
using namespace DirectX;
|
|
|
|
|
|
|
|
namespace NES {
|
2014-06-23 20:00:51 -04:00
|
|
|
enum UIFlags
|
|
|
|
{
|
|
|
|
ShowFPS = 1,
|
|
|
|
ShowPauseScreen = 2,
|
|
|
|
};
|
|
|
|
|
2014-07-06 19:54:47 -04:00
|
|
|
class Renderer : public IVideoDevice, public IMessageManager
|
2014-06-12 21:48:04 -04:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
HWND _hWnd = nullptr;
|
|
|
|
|
|
|
|
D3D_DRIVER_TYPE _driverType = D3D_DRIVER_TYPE_NULL;
|
|
|
|
D3D_FEATURE_LEVEL _featureLevel = D3D_FEATURE_LEVEL_11_0;
|
|
|
|
ID3D11Device* _pd3dDevice = nullptr;
|
|
|
|
ID3D11Device1* _pd3dDevice1 = nullptr;
|
2014-06-23 20:00:51 -04:00
|
|
|
ID3D11DeviceContext* _pDeviceContext = nullptr;
|
|
|
|
ID3D11DeviceContext1* _pDeviceContext1 = nullptr;
|
2014-06-12 21:48:04 -04:00
|
|
|
IDXGISwapChain* _pSwapChain = nullptr;
|
|
|
|
ID3D11RenderTargetView* _pRenderTargetView = nullptr;
|
|
|
|
|
2014-06-23 16:38:01 -04:00
|
|
|
ID3D11SamplerState* _samplerState = nullptr;
|
|
|
|
|
|
|
|
ID3D11Texture2D* _pTexture = nullptr;
|
2014-06-26 16:24:15 -04:00
|
|
|
byte* _videoRAM = nullptr;
|
2014-06-28 22:52:49 -04:00
|
|
|
|
|
|
|
bool _frameChanged = true;
|
2014-06-26 16:24:15 -04:00
|
|
|
uint8_t* _nextFrameBuffer = nullptr;
|
2014-06-13 23:12:56 -04:00
|
|
|
|
2014-06-23 16:38:01 -04:00
|
|
|
unique_ptr<SpriteFont> _font;
|
|
|
|
ID3D11Texture2D* _overlayTexture = nullptr;
|
2014-06-26 16:24:15 -04:00
|
|
|
byte* _overlayBuffer = nullptr;
|
2014-07-01 12:44:01 -04:00
|
|
|
|
2014-06-23 20:00:51 -04:00
|
|
|
std::unique_ptr<SpriteBatch> _spriteBatch;
|
2014-07-06 19:54:47 -04:00
|
|
|
//ID3D11PixelShader* _pixelShader = nullptr;
|
2014-06-23 16:38:01 -04:00
|
|
|
|
2014-06-26 11:32:09 -04:00
|
|
|
uint32_t _screenWidth;
|
|
|
|
uint32_t _screenHeight;
|
|
|
|
uint32_t _bytesPerPixel;
|
|
|
|
uint32_t _hdScreenWidth;
|
|
|
|
uint32_t _hdScreenHeight;
|
|
|
|
uint32_t _screenBufferSize;
|
|
|
|
uint32_t _hdScreenBufferSize;
|
|
|
|
|
2014-06-23 20:00:51 -04:00
|
|
|
uint32_t _flags = 0;
|
2014-06-12 21:48:04 -04:00
|
|
|
|
2014-06-25 21:52:37 -04:00
|
|
|
wstring _displayMessage = L"";
|
|
|
|
uint32_t _displayTimestamp = 0;
|
|
|
|
|
2014-06-23 16:38:01 -04:00
|
|
|
HRESULT InitDevice();
|
|
|
|
void CleanupDevice();
|
2014-06-23 20:00:51 -04:00
|
|
|
|
2014-06-26 11:32:09 -04:00
|
|
|
void SetScreenSize(uint32_t screenWidth, uint32_t screenHeight);
|
|
|
|
|
2014-06-23 20:00:51 -04:00
|
|
|
ID3D11ShaderResourceView* GetShaderResourceView(ID3D11Texture2D* texture);
|
|
|
|
void DrawNESScreen();
|
|
|
|
void DrawPauseScreen();
|
2014-06-12 21:48:04 -04:00
|
|
|
|
2014-07-06 19:54:47 -04:00
|
|
|
//HRESULT CompileShader(wstring filename, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut);
|
2014-07-01 12:44:01 -04:00
|
|
|
|
2014-06-12 21:48:04 -04:00
|
|
|
public:
|
2014-06-23 19:02:09 -04:00
|
|
|
Renderer(HWND hWnd);
|
|
|
|
~Renderer();
|
2014-06-23 16:38:01 -04:00
|
|
|
|
2014-06-12 21:48:04 -04:00
|
|
|
void Render();
|
2014-06-25 21:52:37 -04:00
|
|
|
|
2014-07-06 19:54:47 -04:00
|
|
|
void DisplayMessage(wstring text);
|
2014-06-23 20:00:51 -04:00
|
|
|
|
|
|
|
void SetFlags(uint32_t flags)
|
|
|
|
{
|
|
|
|
_flags |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearFlags(uint32_t flags)
|
|
|
|
{
|
|
|
|
_flags &= ~flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckFlag(uint32_t flag)
|
|
|
|
{
|
|
|
|
return (_flags & flag) == flag;
|
|
|
|
}
|
2014-06-19 17:06:00 -04:00
|
|
|
|
|
|
|
void UpdateFrame(uint8_t* frameBuffer)
|
|
|
|
{
|
2014-06-28 22:52:49 -04:00
|
|
|
_frameChanged = true;
|
2014-06-19 17:06:00 -04:00
|
|
|
memcpy(_nextFrameBuffer, frameBuffer, 256 * 240 * 4);
|
|
|
|
}
|
2014-06-12 21:48:04 -04:00
|
|
|
};
|
|
|
|
}
|