Skip to content

Commit

Permalink
figure out how to add rotation to render
Browse files Browse the repository at this point in the history
  • Loading branch information
duchuule committed Jun 26, 2015
1 parent abd553a commit cc00b6c
Show file tree
Hide file tree
Showing 11 changed files with 2,361 additions and 1,583 deletions.
6 changes: 6 additions & 0 deletions Common/DeviceResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,10 @@ DXGI_MODE_ROTATION DX::DeviceResources::ComputeDisplayRotation()
break;
}
return rotation;
}

//output the orientation
DisplayOrientations DX::DeviceResources::GetOrientation()
{
return m_currentOrientation;
}
2 changes: 2 additions & 0 deletions Common/DeviceResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace DX
IWICImagingFactory2* GetWicImagingFactory() const { return m_wicFactory.Get(); }
D2D1::Matrix3x2F GetOrientationTransform2D() const { return m_orientationTransform2D; }

Windows::Graphics::Display::DisplayOrientations GetOrientation();

private:
void CreateDeviceIndependentResources();
void CreateDeviceResources();
Expand Down
26 changes: 25 additions & 1 deletion DXSpriteBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ namespace Engine

}

CD3D11_BUFFER_DESC onFrameDesc(
sizeof(OnFrameBuffer),
D3D11_BIND_CONSTANT_BUFFER,
D3D11_USAGE_DYNAMIC,
D3D11_CPU_ACCESS_WRITE);
ComPtr<ID3D11Buffer> tmpOnFrameBuffer;
if(FAILED(this->device->CreateBuffer(&onFrameDesc, nullptr, tmpOnFrameBuffer.GetAddressOf())))
{

}

this->onFrameBuffer = tmpOnFrameBuffer;
this->vertexBuffer = tmpVertexBuffer;
this->indexBuffer = tmpIndexBuffer;
this->onResizeBuffer = tmpOnResizeBuffer;
Expand Down Expand Up @@ -254,7 +266,7 @@ namespace Engine
this->customPS = (ID3D11PixelShader *) customPS;
}

void DXSpriteBatch::Begin(void)
void DXSpriteBatch::Begin(XMMATRIX &world)
{
if(beginCalled)
{
Expand All @@ -265,6 +277,17 @@ namespace Engine
this->batchedSprites = 0;

this->heapSort = HeapCompareBackToFront;

OnFrameBuffer onFrame;
onFrame.world = world;

D3D11_MAPPED_SUBRESOURCE mappedSubresource;
if(FAILED(this->context->Map(this->onFrameBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSubresource)))
{
}

*(OnFrameBuffer *)mappedSubresource.pData = onFrame;
this->context->Unmap(this->onFrameBuffer.Get(), 0);
}

void DXSpriteBatch::Draw(const Rectangle &targetArea, const Rectangle *sourceArea, ID3D11ShaderResourceView *textureSRV, ID3D11Texture2D *texture, float depth, float rotation, Color &color)
Expand Down Expand Up @@ -583,6 +606,7 @@ namespace Engine
this->context->IASetVertexBuffers(0, 1, this->vertexBuffer.GetAddressOf(), &stride, &offset);
this->context->IASetIndexBuffer(this->indexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0);
this->context->VSSetConstantBuffers(0, 1, this->onResizeBuffer.GetAddressOf());
this->context->VSSetConstantBuffers(1, 1, this->onFrameBuffer.GetAddressOf());

// Draw
this->context->DrawIndexed(
Expand Down
3 changes: 2 additions & 1 deletion DXSpriteBatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace Engine
ComPtr<ID3D11PixelShader> customPS;
ComPtr<ID3D11VertexShader> vs;
ComPtr<ID3D11InputLayout> inputLayout;
ComPtr<ID3D11Buffer> onFrameBuffer;
ComPtr<ID3D11Buffer> onResizeBuffer;
ComPtr<ID3D11Buffer> vertexBuffer;
ComPtr<ID3D11Buffer> indexBuffer;
Expand Down Expand Up @@ -80,7 +81,7 @@ namespace Engine
void OnResize(float width, float height);
void SetCustomPixelShader(void *customPS);

void Begin(void);
void Begin(XMMATRIX &world);
void Draw(const Rectangle &targetArea, const Rectangle *sourceArea, ID3D11ShaderResourceView *textureSRV, ID3D11Texture2D *texture, float depth, float rotation, Color &color);
void Draw(const Rectangle &target, const Rectangle *source, ID3D11ShaderResourceView *textureSRV, ID3D11Texture2D *texture, float depth, Color &color);
void Draw(const Rectangle &target, const Rectangle *source, ID3D11ShaderResourceView *textureSRV, ID3D11Texture2D *texture, Color &color);
Expand Down
39 changes: 33 additions & 6 deletions EmulatorRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define AUTOSAVE_INTERVAL 10.0f

using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;

HANDLE swapEvent = NULL;
HANDLE updateEvent = NULL;
Expand Down Expand Up @@ -438,16 +439,21 @@ namespace VBA10
}
}

int height = this->height; // *(GetImageScale() / 100.0f);
int height;
int width;
switch(GetAspectRatio())
RECT rect;


height = this->height; // *(GetImageScale() / 100.0f);
switch (GetAspectRatio())
{
default:
case AspectRatioMode::Original:
if(gbaROMLoaded)
if (gbaROMLoaded)
{
width = (int)(height * (240.0f / 160.0f));
}else
}
else
{
width = (int)(height * (160.0f / 144.0f));
}
Expand All @@ -473,12 +479,12 @@ namespace VBA10
}

int leftOffset = (this->width - width) / 2;
RECT rect;
rect.left = leftOffset;
rect.right = width + leftOffset;
rect.top = 0;
rect.bottom = height;


RECT source;
if(gbaROMLoaded)
{
Expand Down Expand Up @@ -512,7 +518,7 @@ namespace VBA10


// Render last frame to screen
this->dxSpriteBatch->Begin();
this->dxSpriteBatch->Begin(this->outputTransform);

Engine::Rectangle sourceRect(source.left, source.top, source.right - source.left, source.bottom - source.top);
Engine::Rectangle targetRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
Expand Down Expand Up @@ -627,6 +633,27 @@ namespace VBA10
}
}

void EmulatorRenderer::CreateTransformMatrix(void)
{
//this->outputTransform = XMMatrixIdentity();
this->outputTransform = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
10.0f, 10.0f, 0.0f, 1.0f };

//if (m_deviceResources->GetOrientation() == DisplayOrientations::Landscape)
//{
// this->outputTransform = XMMatrixMultiply(this->outputTransform, XMMatrixRotationZ(XM_PIDIV2));
// //this->outputTransform = XMMatrixMultiply(XMMatrixTranslation(-this->width / 2, -this->height / 2, 0.0f), XMMatrixRotationZ(XM_PI));
// //this->outputTransform = XMMatrixMultiply(this->outputTransform, XMMatrixTranslation(this->width / 2, this->height / 2, 0.0f));

//}
//else if (m_deviceResources->GetOrientation() == DisplayOrientations::LandscapeFlipped)
//{
// this->outputTransform = XMMatrixMultiply(this->outputTransform, XMMatrixRotationZ(XM_PIDIV2));
// this->outputTransform = XMMatrixMultiply(this->outputTransform, XMMatrixTranslation(this->height, 0.0f, 0.0f));
//}
}


}
Expand Down
18 changes: 4 additions & 14 deletions EmulatorRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,11 @@ namespace VBA10
GameTime ^GetGameTime(void);

void GetBackbufferData(uint8 **backbufferPtr, size_t *pitch, int *imageWidth, int *imageHeight);
void CreateTransformMatrix();
private:
// Cached pointer to device resources.
std::shared_ptr<DX::DeviceResources> m_deviceResources;

// Direct3D Objects, no longer defined here, we moved it out to Common/DeviceResources.h
//Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
//Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
//Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
//Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
//Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depthStencilView;

// Cached renderer properties, no longer defined here, we moved it to Common/DeviceResources.h
//D3D_FEATURE_LEVEL m_featureLevel;
//Windows::Foundation::Size m_renderTargetSize;
//Windows::Foundation::Rect m_windowBounds;
//Windows::UI::Core::CoreWindow ^m_window;
//Windows::Graphics::Display::DisplayOrientations m_orientation;

HANDLE waitEvent;

Expand Down Expand Up @@ -94,13 +82,15 @@ namespace VBA10
ComPtr<ID3D11ShaderResourceView> lButtonSRV;
ComPtr<ID3D11Resource> rButtonResource;
ComPtr<ID3D11ShaderResourceView> rButtonSRV;

XMMATRIX outputTransform;

void AutosaveAsync(void);
void *MapBuffer(int index, size_t *rowPitch);
void FPSCounter(void);
//void MeasureTime(void);
void Autosave(void);




Expand Down
Loading

0 comments on commit cc00b6c

Please sign in to comment.