Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: got SDL_UpdateWindowSurface working, rudimentarily
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLudwig committed Nov 22, 2012
1 parent 782ccaa commit c253734
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
5 changes: 4 additions & 1 deletion src/video/windowsrt/Direct3DBase.h
@@ -1,6 +1,7 @@
#pragma once

#include "DirectXHelper.h"
#include "SDL.h"

// Helper class that initializes DirectX APIs for 3D rendering.
ref class Direct3DBase abstract
Expand All @@ -14,10 +15,12 @@ ref class Direct3DBase abstract
virtual void CreateDeviceResources();
virtual void CreateWindowSizeDependentResources();
virtual void UpdateForWindowSizeChange();
virtual void Render() = 0;
virtual void Present();
virtual float ConvertDipsToPixels(float dips);

internal:
virtual void Render(SDL_Surface * surface, SDL_Rect * rects, int numrects) = 0;

protected private:
// Direct3D Objects.
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
Expand Down
2 changes: 1 addition & 1 deletion src/video/windowsrt/SDL_WinRTApp.cpp
Expand Up @@ -127,7 +127,7 @@ void SDL_WinRTApp::UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rec
{
if (!m_windowClosed && m_windowVisible)
{
m_renderer->Render();
m_renderer->Render(surface, rects, numrects);
m_renderer->Present(); // This call is synchronized to the display frame rate.
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/video/windowsrt/SDL_winrtframebuffer.cpp
Expand Up @@ -34,7 +34,7 @@ extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
int SDL_WINRT_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{
SDL_Surface *surface;
const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
const Uint32 surface_format = SDL_PIXELFORMAT_ARGB8888;
int w, h;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
Expand Down
36 changes: 13 additions & 23 deletions src/video/windowsrt/SDL_winrtrenderer.cpp
Expand Up @@ -60,10 +60,10 @@ void SDL_winrtrenderer::CreateDeviceResources()
auto createCubeTask = (createPSTask && createVSTask).then([this] () {
VertexPositionColor cubeVertices[] =
{
{XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f)},
{XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 1.0f)},
{XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f)},
{XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f)},
{XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT2(0.0f, 1.0f)},
{XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f)},
{XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f)},
{XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f)},
};

m_vertexCount = ARRAYSIZE(cubeVertices);
Expand Down Expand Up @@ -96,14 +96,8 @@ void SDL_winrtrenderer::CreateDeviceResources()
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
textureDesc.MiscFlags = 0;

int numPixels = (int)m_windowBounds.Width * (int)m_windowBounds.Height;
std::vector<uint8> initialTexturePixels(numPixels * 4);
for (int i = 0; i < (numPixels * 4); i += 4) {
initialTexturePixels[i+0] = 0xFF;
initialTexturePixels[i+1] = 0x00;
initialTexturePixels[i+2] = 0x00;
initialTexturePixels[i+3] = 0xFF;
}
const int numPixels = (int)m_windowBounds.Width * (int)m_windowBounds.Height;
std::vector<uint8> initialTexturePixels(numPixels * 4, 0x00);
D3D11_SUBRESOURCE_DATA initialTextureData = {0};
initialTextureData.pSysMem = (void *)&(initialTexturePixels[0]);
initialTextureData.SysMemPitch = (int)m_windowBounds.Width * 4;
Expand Down Expand Up @@ -157,12 +151,12 @@ void SDL_winrtrenderer::CreateDeviceResources()
});
}

void SDL_winrtrenderer::Render()
void SDL_winrtrenderer::Render(SDL_Surface * surface, SDL_Rect * rects, int numrects)
{
const float midnightBlue[] = { 0.098f, 0.098f, 0.439f, 1.000f };
const float blackColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
m_d3dContext->ClearRenderTargetView(
m_renderTargetView.Get(),
midnightBlue
blackColor
);

m_d3dContext->ClearDepthStencilView(
Expand All @@ -189,14 +183,10 @@ void SDL_winrtrenderer::Render()
&textureMemory)
);

const int max = (int)m_windowBounds.Width * (int)m_windowBounds.Height * 4;
uint8 * buf = (uint8 *)textureMemory.pData;
for (int i = 0; i < max; i += 4) {
buf[i+0] = 0x00;
buf[i+1] = 0xFF;
buf[i+2] = 0x00;
buf[i+3] = 0xFF;
}
// TODO, WinRT: only copy over the requested rects (via SDL_BlitSurface, perhaps?)
// TODO, WinRT: do a sanity check on the src and dest data when updating the window surface
const unsigned int numBytes = (int)m_windowBounds.Width * (int)m_windowBounds.Height * 4;
memcpy(textureMemory.pData, surface->pixels, numBytes);

m_d3dContext->Unmap(
m_mainTexture.Get(),
Expand Down
4 changes: 3 additions & 1 deletion src/video/windowsrt/SDL_winrtrenderer.h
Expand Up @@ -16,7 +16,9 @@ ref class SDL_winrtrenderer sealed : public Direct3DBase

// Direct3DBase methods.
virtual void CreateDeviceResources() override;
virtual void Render() override;

internal:
virtual void Render(SDL_Surface * surface, SDL_Rect * rects, int numrects) override;

private:
bool m_loadingComplete;
Expand Down

0 comments on commit c253734

Please sign in to comment.