WinRT: got SDL_UpdateWindowSurface working, rudimentarily
authorDavid Ludwig <dludwig@pobox.com>
Wed, 21 Nov 2012 23:44:58 -0500
changeset 8350 ecc8c88ed82e
parent 8349 020b8b65bcfc
child 8351 021d5b7dae39
WinRT: got SDL_UpdateWindowSurface working, rudimentarily
src/video/windowsrt/Direct3DBase.h
src/video/windowsrt/SDL_WinRTApp.cpp
src/video/windowsrt/SDL_winrtframebuffer.cpp
src/video/windowsrt/SDL_winrtrenderer.cpp
src/video/windowsrt/SDL_winrtrenderer.h
--- a/src/video/windowsrt/Direct3DBase.h	Wed Nov 21 17:38:17 2012 -0500
+++ b/src/video/windowsrt/Direct3DBase.h	Wed Nov 21 23:44:58 2012 -0500
@@ -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
@@ -14,10 +15,12 @@
 	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;
--- a/src/video/windowsrt/SDL_WinRTApp.cpp	Wed Nov 21 17:38:17 2012 -0500
+++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Wed Nov 21 23:44:58 2012 -0500
@@ -127,7 +127,7 @@
 {
     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.
 	}
 }
--- a/src/video/windowsrt/SDL_winrtframebuffer.cpp	Wed Nov 21 17:38:17 2012 -0500
+++ b/src/video/windowsrt/SDL_winrtframebuffer.cpp	Wed Nov 21 23:44:58 2012 -0500
@@ -34,7 +34,7 @@
 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;
--- a/src/video/windowsrt/SDL_winrtrenderer.cpp	Wed Nov 21 17:38:17 2012 -0500
+++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Wed Nov 21 23:44:58 2012 -0500
@@ -60,10 +60,10 @@
 	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);
@@ -96,14 +96,8 @@
 		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;
@@ -157,12 +151,12 @@
 	});
 }
 
-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(
@@ -189,14 +183,10 @@
 			&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(),
--- a/src/video/windowsrt/SDL_winrtrenderer.h	Wed Nov 21 17:38:17 2012 -0500
+++ b/src/video/windowsrt/SDL_winrtrenderer.h	Wed Nov 21 23:44:58 2012 -0500
@@ -16,7 +16,9 @@
 
 	// 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;