Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

WinRT: got SDL_UpdateWindowSurface working, rudimentarily

  • Loading branch information
DavidLudwig committed Nov 22, 2012
1 parent 782ccaa commit c253734790a760ca12101020103147c282e3910d
@@ -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 @@ 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;
@@ -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.
}
}
@@ -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;
@@ -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);
@@ -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;
@@ -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(
@@ -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(),
@@ -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;

0 comments on commit c253734

Please sign in to comment.