annotate Engine/Graphics/RenderD3D11.cpp @ 2531:f6de3e15d4a5

for light in indoor
author Ritor1
date Sun, 23 Nov 2014 15:30:17 +0600
parents b1c516bf1102
children 400edd7b0407
rev   line source
2508
491f0babd563 use_music_folder
Ritor1
parents: 2506
diff changeset
1 #include <d3dcompiler.h>
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
2 #include <comdef.h> // _com_error
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
3
2499
68cdef6879a0 engine folder
Ritor1
parents: 2496
diff changeset
4 #include "../ErrorHandling.h"
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
5 #include "RenderD3D11.h"
2499
68cdef6879a0 engine folder
Ritor1
parents: 2496
diff changeset
6 #include "../mm7_data.h"
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
7 #include "Texture.h"
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
8 #include "../Log.h"
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
9 #include "Sprites.h"
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
10
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
11 #define ErrorD3D(x)\
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
12 {\
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
13 HRESULT hr = x;\
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
14 if (FAILED(hr))\
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
15 {\
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
16 _com_error com_error(hr);\
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
17 Error("HRESULT = %08X\n%S", hr, com_error.ErrorMessage());\
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
18 }\
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
19 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
20
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
21
2526
b1c516bf1102 IRender c-tor
a.parshin
parents: 2525
diff changeset
22 RenderD3D11::RenderD3D11(): IRender() {}
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
23 RenderD3D11::~RenderD3D11() {}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
24
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
25
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
26 bool CompileShader(ID3D11Device *d3dd, const wchar_t *pShaderSourceFile, D3D11_INPUT_ELEMENT_DESC *input_desc, int input_desc_size,
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
27 ID3D11VertexShader **vertex_out, ID3D11PixelShader **pixel_out, ID3D11InputLayout **layout_out);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
28
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
29
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
30 void RenderD3D11::ClearBlack() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
31 void RenderD3D11::SaveWinnersCertificate(const char *a1) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
32 void RenderD3D11::_49FD3A_fullscreen() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
33 bool RenderD3D11::InitializeFullscreen() {__debugbreak(); return 0;}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
34 void RenderD3D11::CreateZBuffer() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
35 void RenderD3D11::Release() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
36 void RenderD3D11::RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
37 void RenderD3D11::SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
38 bool RenderD3D11::LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags) {__debugbreak(); return 0;}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
39 void RenderD3D11::GetTargetPixelFormat(DDPIXELFORMAT *pOut) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
40 void RenderD3D11::LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
41 void RenderD3D11::UnlockBackBuffer() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
42 void RenderD3D11::LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
43 void RenderD3D11::UnlockFrontBuffer() {__debugbreak();}
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
44 void RenderD3D11::RestoreFrontBuffer() {}
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
45 void RenderD3D11::RestoreBackBuffer() {}
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
46 void RenderD3D11::BltToFront(RECT *pDstRect, IDirectDrawSurface *pSrcSurface, RECT *pSrcRect, unsigned int uBltFlags) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
47 void RenderD3D11::BltBackToFontFast(int a2, int a3, RECT *a4) {__debugbreak();}
2526
b1c516bf1102 IRender c-tor
a.parshin
parents: 2525
diff changeset
48 void RenderD3D11::BeginSceneD3D() {}
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
49 unsigned int RenderD3D11::GetActorTintColor(float a2, int tint, int a4, int a5, RenderBillboard *a6) {__debugbreak(); return 0;}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
50 void RenderD3D11::DrawPolygon(unsigned int uNumVertices, struct Polygon *a3, ODMFace *a4, IDirect3DTexture2 *pTexture) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
51 void RenderD3D11::DrawTerrainPolygon(unsigned int uNumVertices, struct Polygon *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
52 void RenderD3D11::DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, struct Texture *pTex, int uPackedID, unsigned int uColor, int a8) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
53 void RenderD3D11::MakeParticleBillboardAndPush_BLV(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
54 void RenderD3D11::MakeParticleBillboardAndPush_ODM(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
55 void RenderD3D11::DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
56 void RenderD3D11::DrawBillboard_Indoor(RenderBillboardTransform_local0 *pSoftBillboard, Sprite *pSprite, int dimming_level) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
57 void RenderD3D11::_4A4CC9_AddSomeBillboard(struct stru6_stru1_indoor_sw_billboard *a1, int diffuse) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
58 void RenderD3D11::TransformBillboardsAndSetPalettesODM() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
59 void RenderD3D11::DrawBillboardList_BLV() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
60 void RenderD3D11::DrawProjectile(float srcX, float srcY, float a3, float a4, float dstX, float dstY, float a7, float a8, IDirect3DTexture2 *a9) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
61 void RenderD3D11::ScreenFade(unsigned int color, float t) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
62 void RenderD3D11::CreditsTextureScroll(unsigned int pX, unsigned int pY, int move_X, int move_Y, RGBTexture *pTexture) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
63 void RenderD3D11::ZBuffer_Fill_2(signed int a2, signed int a3, struct Texture *pTexture, int a5) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
64 void RenderD3D11::DrawMaskToZBuffer(signed int uOutX, unsigned int uOutY, struct Texture *pTexture, int zVal) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
65 void RenderD3D11::DrawAura(unsigned int a2, unsigned int a3, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
66 void RenderD3D11::_4A65CC(unsigned int x, unsigned int y, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
67 void RenderD3D11::DrawTransparentRedShade(unsigned int a2, unsigned int a3, struct Texture *a4) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
68 void RenderD3D11::DrawTransparentGreenShade(signed int a2, signed int a3, struct Texture *pTexture) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
69 void RenderD3D11::DrawFansTransparent(const RenderVertexD3D3 *vertices, unsigned int num_vertices) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
70 void RenderD3D11::DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
71 void RenderD3D11::GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
72 void RenderD3D11::FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
73 void RenderD3D11::_4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, struct Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
74 void RenderD3D11::DrawTranslucent(unsigned int a2, unsigned int a3, struct Texture *a4) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
75 void RenderD3D11::DrawBuildingsD3D() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
76 void RenderD3D11::DrawIndoorSky(unsigned int uNumVertices, unsigned int uFaceID) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
77 void RenderD3D11::DrawOutdoorSkyD3D() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
78 void RenderD3D11::DrawOutdoorSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
79 void RenderD3D11::DrawIndoorSkyPolygon(signed int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
80 void RenderD3D11::PrepareDecorationsRenderList_ODM() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
81 void RenderD3D11::DrawSpriteObjects_ODM() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
82 void RenderD3D11::RenderTerrainD3D() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
83 void RenderD3D11::ChangeBetweenWinFullscreenModes() {__debugbreak();}
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
84 bool RenderD3D11::AreRenderSurfacesOk() {return true;}
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
85 void RenderD3D11::SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
86 void RenderD3D11::SavePCXScreenshot() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
87 int RenderD3D11::_46À6ÀÑ_GetActorsInViewport(int pDepth) {__debugbreak(); return 0;}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
88 void RenderD3D11::BeginLightmaps() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
89 void RenderD3D11::EndLightmaps() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
90 void RenderD3D11::BeginLightmaps2() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
91 void RenderD3D11::EndLightmaps2() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
92 bool RenderD3D11::DrawLightmap(struct Lightmap *pLightmap, struct Vec3_float_ *pColorMult, float z_bias) {__debugbreak(); return 0;}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
93 void RenderD3D11::BeginDecals() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
94 void RenderD3D11::EndDecals() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
95 void RenderD3D11::DrawDecal(struct Decal *pDecal, float z_bias) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
96 void RenderD3D11::do_draw_debug_line_d3d(const RenderVertexD3D3 *pLineBegin, signed int sDiffuseBegin, const RenderVertexD3D3 *pLineEnd, signed int sDiffuseEnd, float z_stuff) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
97 void RenderD3D11::DrawLines(const RenderVertexD3D3 *vertices, unsigned int num_vertices) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
98 void RenderD3D11::DrawSpecialEffectsQuad(const RenderVertexD3D3 *vertices, IDirect3DTexture2 *texture) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
99 void RenderD3D11::am_Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
100 void RenderD3D11::am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode) {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
101
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
102 void RenderD3D11::Sub01() {__debugbreak();}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
103
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
104
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
105
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
106
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
107 void RenderD3D11::PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size) {}
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
108
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
109 void RenderD3D11::SetUIClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
110 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
111 ui_clip_rect.left = uX;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
112 ui_clip_rect.top = uY;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
113 ui_clip_rect.right = uZ;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
114 ui_clip_rect.bottom = uW;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
115 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
116
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
117 void RenderD3D11::ResetUIClipRect()
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
118 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
119 ui_clip_rect.left = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
120 ui_clip_rect.top = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
121 ui_clip_rect.right = window->GetWidth();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
122 ui_clip_rect.bottom = window->GetHeight();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
123 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
124
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
125 void RenderD3D11::PresentBlackScreen()
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
126 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
127 ClearTarget(0xFF000000);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
128 ErrorD3D(pSwapChain->Present(0, 0));
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
129 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
130
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
131 void RenderD3D11::BeginScene() {}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
132 void RenderD3D11::EndScene() {}
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
133
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
134 void RenderD3D11::ClearTarget(unsigned int uColor)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
135 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
136 float clear_color[] =
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
137 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
138 ((uColor & 0x00FF0000) >> 16) / 255.0f,
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
139 ((uColor & 0x0000FF00) >> 8) / 255.0f,
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
140 ((uColor & 0x000000FF) >> 0) / 255.0f,
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
141 ((uColor & 0xFF000000) >> 24) / 255.0f
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
142 };
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
143 d3dc->ClearRenderTargetView(primary_srv, clear_color);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
144 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
145
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
146 void RenderD3D11::ClearZBuffer(int, int)
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
147 {
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
148 d3dc->ClearDepthStencilView(default_depth_srv, D3D11_CLEAR_DEPTH, 1.0f, 0);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
149 }
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
150
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
151
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
152 void RenderD3D11::DrawTextureIndexed(unsigned int uX, unsigned int uY, struct Texture *a4)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
153 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
154 PrepareTextureIndexed(a4);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
155 DrawTexture((float)uX / window->GetWidth(), (float)uY / window->GetHeight(), a4->uTextureWidth, a4->uTextureHeight, a4->d3d11_srv, ui_blend_solid);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
156 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
157
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
158 void RenderD3D11::DrawTextureIndexedAlpha(unsigned int uX, unsigned int uY, struct Texture *a4)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
159 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
160 PrepareTextureIndexed(a4);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
161 DrawTexture((float)uX / window->GetWidth(), (float)uY / window->GetHeight(), a4->uTextureWidth, a4->uTextureHeight, a4->d3d11_srv, ui_blend_alpha);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
162 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
163
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
164 void RenderD3D11::DrawTextureRGB(unsigned int uX, unsigned int uY, RGBTexture *a4)
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
165 {
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
166 PrepareTexture(a4);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
167 DrawTexture((float)uX / window->GetWidth(), (float)uY / window->GetHeight(), a4->uWidth, a4->uHeight, a4->d3d11_srv, ui_blend_solid);
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
168 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
169
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
170 void RenderD3D11::DrawTextureNew(float u, float v, Texture *tex)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
171 {
2521
a.parshin
parents: 2518
diff changeset
172 __debugbreak();
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
173 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
174
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
175 void RenderD3D11::DrawTextureNew(float u, float v, RGBTexture *tex)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
176 {
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
177 PrepareTexture(tex);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
178 DrawTexture(u, v, tex->uWidth, tex->uHeight, tex->d3d11_srv, ui_blend_solid);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
179 }
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
180
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
181 void RenderD3D11::DrawText(signed int uX, signed int uY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
182 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
183 auto srv = PrepareFontTexture(pFontPixels, uCharWidth, uCharHeight, pFontPalette, uFaceColor, uShadowColor);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
184 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
185 DrawTexture((float)uX / window->GetWidth(), (float)uY / window->GetHeight(), uCharWidth, uCharHeight, srv, ui_blend_alpha);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
186 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
187 srv->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
188 }
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
189
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
190 void RenderD3D11::DrawTextAlpha(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, bool present_time_transparency)
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
191 {
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
192 auto srv = PrepareFontTexture(font_pixels, a5, uFontHeight, pPalette);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
193 {
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
194 DrawTexture((float)x / window->GetWidth(), (float)y / window->GetHeight(), a5, uFontHeight, srv, ui_blend_alpha);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
195 }
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
196 srv->Release();
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
197 }
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
198
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
199 void RenderD3D11::DrawTexture(float u, float v, int texture_width, int texture_height, ID3D11ShaderResourceView *srv, ID3D11BlendState *blend)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
200 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
201 bool clipping = false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
202 if (ui_clip_rect.left != 0 || ui_clip_rect.top != 0
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
203 || ui_clip_rect.right != window->GetWidth() || ui_clip_rect.bottom != window->GetHeight())
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
204 clipping = true;
2521
a.parshin
parents: 2518
diff changeset
205
a.parshin
parents: 2518
diff changeset
206 float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
207 d3dc->OMSetRenderTargets(1, &primary_srv, default_depth_srv);
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
208 d3dc->OMSetBlendState(blend, blendFactor, 0xFFFFFFFF);
2521
a.parshin
parents: 2518
diff changeset
209 d3dc->OMSetDepthStencilState(ui_depthstencil, 1);
a.parshin
parents: 2518
diff changeset
210
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
211 {
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
212 struct cb_fast
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
213 {
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
214 float pos_x;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
215 float pos_y;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
216 float size_x;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
217 float size_y;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
218 };
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
219
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
220 D3D11_MAPPED_SUBRESOURCE map;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
221 d3dc->Map(ui_cb_fast, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
222 {
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
223 cb_fast data;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
224 {
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
225 data.pos_x = u;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
226 data.pos_y = v;
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
227 data.size_x = (float)texture_width / window->GetWidth();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
228 data.size_y = (float)texture_height / window->GetHeight();
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
229 }
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
230 memcpy(map.pData, &data, sizeof(data));
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
231 }
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
232 d3dc->Unmap(ui_cb_fast, 0);
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
233 }
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
234
2521
a.parshin
parents: 2518
diff changeset
235 d3dc->VSSetShader(ui_vs, nullptr, 0);
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
236 d3dc->VSSetConstantBuffers(0, 1, &ui_cb_fast);
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
237
2521
a.parshin
parents: 2518
diff changeset
238 d3dc->PSSetShader(ui_ps, nullptr, 0);
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
239 d3dc->PSSetConstantBuffers(0, 1, &ui_cb_fast);
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
240 d3dc->PSSetShaderResources(0, 1, &srv);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
241
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
242 if (clipping)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
243 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
244 d3dc->RSSetState(ui_rasterizer);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
245 d3dc->RSSetScissorRects(1, &ui_clip_rect);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
246 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
247 //d3dc->RSSetViewports(1, &ui_viewport);
2521
a.parshin
parents: 2518
diff changeset
248
a.parshin
parents: 2518
diff changeset
249 uint uOffset = 0;
a.parshin
parents: 2518
diff changeset
250 uint uStride = 4 * sizeof(float);
a.parshin
parents: 2518
diff changeset
251 d3dc->IASetVertexBuffers(0, 1, &ui_vb, &uStride, &uOffset);
a.parshin
parents: 2518
diff changeset
252 d3dc->IASetInputLayout(ui_layout);
a.parshin
parents: 2518
diff changeset
253 d3dc->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
a.parshin
parents: 2518
diff changeset
254
a.parshin
parents: 2518
diff changeset
255 d3dc->Draw(6, 0);
a.parshin
parents: 2518
diff changeset
256
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
257 if (clipping)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
258 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
259 d3dc->RSSetState(default_rasterizer);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
260 //d3dc->RSSetScissorRects(0, nullptr);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
261 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
262 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
263
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
264
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
265
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
266 void RenderD3D11::Present()
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
267 {
2521
a.parshin
parents: 2518
diff changeset
268 pSwapChain->Present(0, 0);
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
269 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
270
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
271 bool RenderD3D11::IsGammaSupported()
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
272 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
273 return false;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
274 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
275
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
276 struct
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
277 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
278 unsigned char restore_resolution;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
279 unsigned char _saved_screen_bpp;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
280 unsigned short _saved_screen_width;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
281 unsigned short _saved_screen_height;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
282 } on_exit;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
283
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
284 void ChangeResolution(int new_width, int new_height, int new_bpp)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
285 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
286 if (!on_exit.restore_resolution)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
287 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
288 on_exit.restore_resolution = true;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
289
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
290 auto hdc = GetDC(nullptr);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
291 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
292 on_exit._saved_screen_width = GetDeviceCaps(hdc, HORZRES);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
293 on_exit._saved_screen_height = GetDeviceCaps(hdc, VERTRES);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
294 on_exit._saved_screen_bpp = GetDeviceCaps(hdc, BITSPIXEL);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
295 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
296 ReleaseDC(nullptr, hdc);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
297 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
298
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
299 DEVMODEA dm;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
300 dm.dmSize = sizeof(dm);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
301 dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
302 dm.dmBitsPerPel = new_bpp;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
303 dm.dmPelsWidth = new_width;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
304 dm.dmPelsHeight = new_height;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
305
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
306 if (ChangeDisplaySettingsA(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
307 Error("ChangeDisplaySettingsA");
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
308 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
309
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
310 __declspec(noreturn) void ExitApp()
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
311 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
312 if (on_exit.restore_resolution)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
313 ChangeResolution(on_exit._saved_screen_width, on_exit._saved_screen_height, on_exit._saved_screen_bpp);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
314
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
315 ExitProcess(0);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
316 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
317
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
318
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
319
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
320 bool RenderD3D11::SwitchToWindow()
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
321 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
322 if (on_exit.restore_resolution)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
323 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
324 on_exit.restore_resolution = false;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
325 ChangeResolution(on_exit._saved_screen_width, on_exit._saved_screen_height, on_exit._saved_screen_bpp);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
326 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
327 return true;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
328 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
329
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
330
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
331
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
332
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
333 bool RenderD3D11::Initialize(OSWindow *window)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
334 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
335 this->window = window;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
336
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
337 auto d3d_lib = LoadLibraryW(L"d3d11.dll");
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
338 if (!d3d_lib)
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
339 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
340 Error("d3d11.dll is missing");
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
341 return false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
342 }
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
343
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
344
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
345 DXGI_SWAP_CHAIN_DESC swapChainDesc;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
346 memset(&swapChainDesc, 0, sizeof(swapChainDesc));
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
347 swapChainDesc.BufferDesc.Width = window->GetWidth();
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
348 swapChainDesc.BufferDesc.Height = window->GetHeight();
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
349 //swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
350 //swapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
351 swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
352 //swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
353 //swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
354 swapChainDesc.SampleDesc.Count = 1;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
355 //swapChainDesc.SampleDesc.Quality = 0;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
356 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
357 swapChainDesc.BufferCount = 2;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
358 swapChainDesc.OutputWindow = window->GetApiHandle();
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
359 swapChainDesc.Windowed = true;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
360 //swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
361 //swapChainDesc.Flags = 0;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
362
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
363
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
364 D3D_FEATURE_LEVEL requested_feature_level = D3D_FEATURE_LEVEL_11_0,
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
365 received_feature_level;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
366
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
367 unsigned int device_flags = 0;//D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
368 #ifndef NODEBUG
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
369 device_flags |= D3D11_CREATE_DEVICE_DEBUG;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
370 #endif
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
371
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
372 HRESULT (__stdcall *dll_D3D11CreateDeviceAndSwapChain)(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, CONST D3D_FEATURE_LEVEL* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, IDXGISwapChain** ppSwapChain, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
373 dll_D3D11CreateDeviceAndSwapChain = (decltype(dll_D3D11CreateDeviceAndSwapChain))GetProcAddress(d3d_lib, "D3D11CreateDeviceAndSwapChain");
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
374 ErrorD3D(dll_D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, device_flags, nullptr, 0, D3D11_SDK_VERSION, &swapChainDesc, &pSwapChain, &d3dd, &received_feature_level, &d3dc));
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
375
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
376 if (received_feature_level < D3D_FEATURE_LEVEL_10_0)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
377 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
378 MessageBoxA(nullptr, "Received Direct3D 9 or lower", "", 0);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
379 __debugbreak();
2508
491f0babd563 use_music_folder
Ritor1
parents: 2506
diff changeset
380 }
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
381 /*if (fullscreen)
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
382 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
383 extern void ChangeResolution(int new_dith, int new_height, int new_bpp);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
384 ChangeResolution(target_window->GetWidth(), target_window->GetHeight(), 32);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
385
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
386 target_window->SetPosition(0, 0);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
387 target_window->SetTopmost(true);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
388 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
389 ErrorD3D(pSwapChain->SetFullscreenState(fullscreen, nullptr));*/
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
390
2508
491f0babd563 use_music_folder
Ritor1
parents: 2506
diff changeset
391
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
392 ID3D11Texture2D *pSwapChainSurface;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
393 {
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
394 ErrorD3D(pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void **)&pSwapChainSurface));
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
395 ErrorD3D(d3dd->CreateRenderTargetView(pSwapChainSurface, nullptr, &primary_srv));
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
396 }
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
397 pSwapChainSurface->Release();
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
398
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
399
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
400 D3D11_TEXTURE2D_DESC z_desc;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
401 memset(&z_desc, 0, sizeof(z_desc));
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
402 z_desc.Width = window->GetWidth();
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
403 z_desc.Height = window->GetHeight();
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
404 z_desc.MipLevels = 1;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
405 z_desc.ArraySize = 1;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
406 z_desc.Format = DXGI_FORMAT_D32_FLOAT;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
407 z_desc.SampleDesc.Count = 1;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
408 //z_desc.SampleDesc.Quality = 0;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
409 //z_desc.Usage = D3D11_USAGE_DEFAULT;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
410 z_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
411 //z_desc.CPUAccessFlags = 0;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
412 //z_desc.MiscFlags = 0;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
413
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
414 ID3D11Texture2D *depth_surface;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
415 ErrorD3D(d3dd->CreateTexture2D(&z_desc, nullptr, &depth_surface));
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
416
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
417 D3D11_DEPTH_STENCIL_VIEW_DESC depth_srv_desc;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
418 memset(&depth_srv_desc, 0, sizeof(depth_srv_desc));
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
419 depth_srv_desc.Format = DXGI_FORMAT_D32_FLOAT;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
420 depth_srv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
421 //depth_srv_desc.Texture2D.MipSlice = 0;
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
422 ErrorD3D(d3dd->CreateDepthStencilView(depth_surface, &depth_srv_desc, &default_depth_srv));
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
423
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
424 d3dc->OMSetRenderTargets(1, &primary_srv, default_depth_srv);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
425 d3dc->ClearDepthStencilView(default_depth_srv, D3D11_CLEAR_DEPTH, 1.0f, 0);
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
426
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
427
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
428
2521
a.parshin
parents: 2518
diff changeset
429 D3D11_RASTERIZER_DESC default_rasterizer_desc;
a.parshin
parents: 2518
diff changeset
430 memset(&default_rasterizer_desc, 0, sizeof(default_rasterizer_desc));
a.parshin
parents: 2518
diff changeset
431 default_rasterizer_desc.FillMode = D3D11_FILL_SOLID;
a.parshin
parents: 2518
diff changeset
432 default_rasterizer_desc.CullMode = D3D11_CULL_NONE;
a.parshin
parents: 2518
diff changeset
433 //default_rasterizer_desc.FrontCounterClockwise = false;
a.parshin
parents: 2518
diff changeset
434 //default_rasterizer_desc.DepthBias = 0;
a.parshin
parents: 2518
diff changeset
435 //default_rasterizer_desc.DepthBiasClamp = 0.0f;
a.parshin
parents: 2518
diff changeset
436 //default_rasterizer_desc.SlopeScaledDepthBias = 0.0f;
a.parshin
parents: 2518
diff changeset
437 //default_rasterizer_desc.DepthClipEnable = true;
a.parshin
parents: 2518
diff changeset
438 //default_rasterizer_desc.ScissorEnable = false;
a.parshin
parents: 2518
diff changeset
439 //default_rasterizer_desc.MultisampleEnable = false;
a.parshin
parents: 2518
diff changeset
440 //default_rasterizer_desc.AntialiasedLineEnable = false;
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
441
2521
a.parshin
parents: 2518
diff changeset
442 ErrorD3D(d3dd->CreateRasterizerState(&default_rasterizer_desc, &default_rasterizer));
a.parshin
parents: 2518
diff changeset
443 d3dc->RSSetState(default_rasterizer);
a.parshin
parents: 2518
diff changeset
444
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
445
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
446
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
447 D3D11_RASTERIZER_DESC ui_rasterizer_desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
448 memset(&ui_rasterizer_desc, 0, sizeof(ui_rasterizer_desc));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
449 ui_rasterizer_desc.FillMode = D3D11_FILL_SOLID;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
450 ui_rasterizer_desc.CullMode = D3D11_CULL_NONE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
451 //ui_rasterizer_desc.FrontCounterClockwise = false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
452 //ui_rasterizer_desc.DepthBias = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
453 //ui_rasterizer_desc.DepthBiasClamp = 0.0f;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
454 //ui_rasterizer_desc.SlopeScaledDepthBias = 0.0f;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
455 //ui_rasterizer_desc.DepthClipEnable = true;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
456 ui_rasterizer_desc.ScissorEnable = true;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
457 //ui_rasterizer_desc.MultisampleEnable = false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
458 //ui_rasterizer_desc.AntialiasedLineEnable = false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
459
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
460 ErrorD3D(d3dd->CreateRasterizerState(&ui_rasterizer_desc, &ui_rasterizer));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
461
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
462
2521
a.parshin
parents: 2518
diff changeset
463 default_depthstencil = nullptr;
a.parshin
parents: 2518
diff changeset
464 default_blend = nullptr;
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
465
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
466
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
467
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
468 D3D11_VIEWPORT viewport;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
469 memset(&viewport, 0, sizeof(viewport));
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
470 viewport.TopLeftX = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
471 viewport.TopLeftY = 0;
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
472 viewport.Width = window->GetWidth();
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
473 viewport.Height = window->GetHeight();
2521
a.parshin
parents: 2518
diff changeset
474 viewport.MinDepth = 0;
2496
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
475 viewport.MaxDepth = 1;
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
476 d3dc->RSSetViewports(1, &viewport);
5abd8fc8f1c6 for ITEM_ARTIFACT_LADYS_ESCORT
Ritor1
parents:
diff changeset
477
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
478 ResetUIClipRect();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
479
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
480
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
481 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
482 {
2521
a.parshin
parents: 2518
diff changeset
483 { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
a.parshin
parents: 2518
diff changeset
484 //{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 },
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
485 };
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
486 CompileShader(d3dd, L"data/shaders/UI.hlsl", layout_desc, 1/*2*/, &ui_vs, &ui_ps, &ui_layout);
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
487
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
488 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
489 uint uVertexSize = 4 * sizeof(float);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
490
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
491 float ui_mesh[] =
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
492 {
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
493 1, 1, 0, 0, // pos
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
494 1, 1, 1, 0, // pos + size.x
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
495 1, 1, 0, 1, // pos + size.y
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
496
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
497 1, 1, 0, 1, // pos + size.y
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
498 1, 1, 1, 0, // pos + size.x
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
499 1, 1, 1, 1 // pos + size.xy
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
500 /*-1, 1, 0.1, 1,
2521
a.parshin
parents: 2518
diff changeset
501 1, 1, 0.1, 1,
a.parshin
parents: 2518
diff changeset
502 -1, -1, 0.1, 1,
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
503
2521
a.parshin
parents: 2518
diff changeset
504 -1, -1, 0.1, 1,
a.parshin
parents: 2518
diff changeset
505 1, 1, 0.1, 1,
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
506 1, -1, 0.1, 1*/
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
507 };
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
508
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
509 D3D11_BUFFER_DESC vbdesc;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
510 vbdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
511 vbdesc.ByteWidth = 6 * uVertexSize;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
512 vbdesc.CPUAccessFlags = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
513 vbdesc.MiscFlags = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
514 vbdesc.StructureByteStride = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
515 vbdesc.Usage = D3D11_USAGE_DEFAULT;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
516
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
517 D3D11_SUBRESOURCE_DATA vbdata;
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
518 vbdata.pSysMem = ui_mesh;
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
519 vbdata.SysMemPitch = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
520 vbdata.SysMemSlicePitch = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
521
2521
a.parshin
parents: 2518
diff changeset
522 d3dd->CreateBuffer(&vbdesc, &vbdata, &ui_vb);
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
523 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
524
2523
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
525 D3D11_BUFFER_DESC ui_cb_fast_desc;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
526 ZeroMemory(&ui_cb_fast_desc, sizeof(ui_cb_fast_desc));
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
527 // TODO: Fix Bug Prone size
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
528 ui_cb_fast_desc.ByteWidth = 1 * 4 * sizeof(float);
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
529 ui_cb_fast_desc.Usage = D3D11_USAGE_DYNAMIC;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
530 ui_cb_fast_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
531 ui_cb_fast_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
532 ui_cb_fast_desc.MiscFlags = 0;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
533 ui_cb_fast_desc.StructureByteStride = 0;
c532d5242055 Hello from Direct3D 11 :)
a.parshin
parents: 2521
diff changeset
534 d3dd->CreateBuffer(&ui_cb_fast_desc, nullptr, &ui_cb_fast);
2521
a.parshin
parents: 2518
diff changeset
535
a.parshin
parents: 2518
diff changeset
536 D3D11_DEPTH_STENCIL_DESC ui_depthstencil_desc;
a.parshin
parents: 2518
diff changeset
537 ui_depthstencil_desc.DepthEnable = true;
a.parshin
parents: 2518
diff changeset
538 ui_depthstencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
a.parshin
parents: 2518
diff changeset
539 ui_depthstencil_desc.DepthFunc = D3D11_COMPARISON_ALWAYS;
a.parshin
parents: 2518
diff changeset
540 ui_depthstencil_desc.StencilEnable = false;
a.parshin
parents: 2518
diff changeset
541 ui_depthstencil_desc.StencilReadMask = 0xFF;
a.parshin
parents: 2518
diff changeset
542 ui_depthstencil_desc.StencilWriteMask = 0xFF;
a.parshin
parents: 2518
diff changeset
543 // Stencil operations if pixel is front-facing
a.parshin
parents: 2518
diff changeset
544 ui_depthstencil_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
a.parshin
parents: 2518
diff changeset
545 ui_depthstencil_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
a.parshin
parents: 2518
diff changeset
546 ui_depthstencil_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
a.parshin
parents: 2518
diff changeset
547 ui_depthstencil_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
a.parshin
parents: 2518
diff changeset
548 // Stencil operations if pixel is back-facing
a.parshin
parents: 2518
diff changeset
549 ui_depthstencil_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
a.parshin
parents: 2518
diff changeset
550 ui_depthstencil_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
a.parshin
parents: 2518
diff changeset
551 ui_depthstencil_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
a.parshin
parents: 2518
diff changeset
552 ui_depthstencil_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
a.parshin
parents: 2518
diff changeset
553
a.parshin
parents: 2518
diff changeset
554 ErrorD3D(d3dd->CreateDepthStencilState(&ui_depthstencil_desc, &ui_depthstencil));
a.parshin
parents: 2518
diff changeset
555
a.parshin
parents: 2518
diff changeset
556
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
557 D3D11_BLEND_DESC ui_blend_solid_desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
558 memset(&ui_blend_solid_desc, 0, sizeof(ui_blend_solid_desc));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
559 ui_blend_solid_desc.RenderTarget[0].BlendEnable = false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
560 ui_blend_solid_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
561 ErrorD3D(d3dd->CreateBlendState(&ui_blend_solid_desc, &ui_blend_solid));
2521
a.parshin
parents: 2518
diff changeset
562
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
563 D3D11_BLEND_DESC ui_blend_alpha_desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
564 memset(&ui_blend_alpha_desc, 0, sizeof(ui_blend_alpha_desc));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
565 ui_blend_alpha_desc.RenderTarget[0].BlendEnable = true;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
566 ui_blend_alpha_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
567 ui_blend_alpha_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
568 ui_blend_alpha_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
569 ui_blend_alpha_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
570 ui_blend_alpha_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
571 ui_blend_alpha_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
572 ui_blend_alpha_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
573 ErrorD3D(d3dd->CreateBlendState(&ui_blend_alpha_desc, &ui_blend_alpha));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
574
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
575
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
576 return pD3DBitmaps.Load(L"data\\d3dbitmap.hwl") && pD3DSprites.Load(L"data\\d3dsprite.hwl");
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
577 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
578
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
579
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
580
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
581
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
582 bool RenderD3D11::MoveSpriteToDevice(Sprite *pSprite)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
583 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
584 HWLTexture *sprite_texture; // eax@1
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
585 unsigned __int16 *v9; // edx@5
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
586 LPVOID v10; // eax@5
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
587 DDSURFACEDESC2 Dst; // [sp+Ch] [bp-7Ch]@4
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
588
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
589 sprite_texture = pD3DSprites.LoadTexture(pSprite->pName, pSprite->uPaletteID);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
590 if ( sprite_texture )
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
591 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
592 pSprite->uAreaX = sprite_texture->uAreaX;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
593 pSprite->uAreaY = sprite_texture->uAreaY;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
594 pSprite->uBufferWidth = sprite_texture->uBufferWidth;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
595 pSprite->uBufferHeight = sprite_texture->uBufferHeight;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
596 pSprite->uAreaWidth = sprite_texture->uAreaWidth;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
597 pSprite->uAreaHeight = sprite_texture->uAreaHeigth;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
598
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
599 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
600 D3D11_TEXTURE2D_DESC desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
601 desc.Width = sprite_texture->uWidth;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
602 desc.Height = sprite_texture->uHeight;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
603 desc.ArraySize = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
604 desc.MipLevels = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
605 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
606 desc.SampleDesc.Count = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
607 desc.SampleDesc.Quality = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
608 desc.Usage = D3D11_USAGE_DEFAULT;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
609 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
610 desc.CPUAccessFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
611 desc.MiscFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
612
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
613 ID3D11Texture2D *vram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
614 ErrorD3D(d3dd->CreateTexture2D(&desc, nullptr, &vram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
615
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
616 D3D11_TEXTURE2D_DESC ram_desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
617 memcpy(&ram_desc, &desc, sizeof(ram_desc));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
618 ram_desc.Usage = D3D11_USAGE_STAGING;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
619 ram_desc.BindFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
620 ram_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
621
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
622 ID3D11Texture2D *ram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
623 ErrorD3D(d3dd->CreateTexture2D(&ram_desc, nullptr, &ram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
624
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
625 D3D11_MAPPED_SUBRESOURCE map;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
626 ErrorD3D(d3dc->Map(ram_texture, 0, D3D11_MAP_WRITE, 0, &map));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
627 for (unsigned int y = 0; y < desc.Height; ++y)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
628 for (unsigned int x = 0; x < desc.Width; ++x)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
629 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
630 auto src = sprite_texture->pPixels + y * desc.Width + x;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
631 auto dst = (unsigned int *)((char *)map.pData + y * map.RowPitch) + x;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
632
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
633 extern unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
634 *dst = 0xFF000000 | Color32_SwapRedBlue(*src);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
635 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
636
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
637
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
638 d3dc->Unmap(ram_texture, 0);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
639 d3dc->CopyResource(vram_texture, ram_texture);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
640 ram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
641
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
642 ID3D11ShaderResourceView *srv = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
643 ErrorD3D(d3dd->CreateShaderResourceView(vram_texture, nullptr, &srv));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
644 vram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
645
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
646 pSprite->d3d11_srv = srv;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
647 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
648 /*if (!pRenderD3D->CreateTexture(sprite_texture->uWidth, sprite_texture->uHeight, &pSprite->pTextureSurface, &pSprite->pTexture, 1u, 0, uMinDeviceTextureDim))
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
649 Error("HiScreen16::LoadTexture - D3Drend->CreateTexture() failed: %x", 0);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
650 memset(&Dst, 0, sizeof(DDSURFACEDESC2));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
651 Dst.dwSize = 124;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
652 if ( LockSurface_DDraw4((IDirectDrawSurface4 *)pSprite->pTextureSurface, &Dst, DDLOCK_WAIT | DDLOCK_WRITEONLY) )
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
653 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
654 v9 = sprite_texture->pPixels;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
655 v10 = Dst.lpSurface;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
656 for (uint i=0; i<sprite_texture->uHeight; ++i)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
657 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
658 for (uint j=0; j<sprite_texture->uWidth/2; ++j)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
659 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
660 *(int *)v10 = *(int *)v9;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
661 v9 += 2;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
662 v10 = (char *)v10 + 4;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
663 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
664 v10 = (char *)v10 + Dst.lPitch-sprite_texture->uWidth*2;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
665 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
666 ErrD3D(pSprite->pTextureSurface->Unlock(NULL));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
667 }*/
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
668 delete [] sprite_texture->pPixels;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
669 delete sprite_texture;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
670 return true;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
671 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
672 return false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
673 }
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
674
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
675
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
676 ID3DBlob *DoD3DCompiling(const wchar_t *shader_name, const char *pShaderSource, uint uShaderSourceLen, const char *pEntry, const char *pVersionString, uint uCompileOptions);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
677 void DoCompile(const wchar_t *pFilename, const char *pShaderSource, unsigned int uShaderSourceLen,
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
678 unsigned char **vs, unsigned int *vs_size, unsigned char **ps, unsigned int *ps_size);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
679 bool CompileShader(ID3D11Device *d3dd, const wchar_t *pShaderSourceFile, D3D11_INPUT_ELEMENT_DESC *input_desc, int input_desc_size,
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
680 ID3D11VertexShader **vertex_out, ID3D11PixelShader **pixel_out, ID3D11InputLayout **layout_out)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
681 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
682 unsigned char *vs, *ps;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
683 unsigned int vs_size, ps_size;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
684
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
685 HANDLE hSourceFile = CreateFileW(pShaderSourceFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
686 if (hSourceFile == INVALID_HANDLE_VALUE)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
687 Error("%S:\n\nCannot read shader file", pShaderSourceFile);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
688
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
689 char *pShaderSource = nullptr;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
690 int uShaderSourceLen = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
691 uint uFileSize = GetFileSize(hSourceFile, nullptr);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
692 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
693 DWORD w;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
694 char *p = new char[uFileSize + 1];
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
695 ReadFile(hSourceFile, p, uFileSize, &w, nullptr);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
696 CloseHandle(hSourceFile);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
697 p[uFileSize] = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
698
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
699 pShaderSource = p;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
700 uShaderSourceLen = uFileSize;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
701 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
702
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
703 DoCompile(pShaderSourceFile, pShaderSource, uShaderSourceLen, &vs, &vs_size, &ps, &ps_size);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
704
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
705 ErrorD3D(d3dd->CreateVertexShader(vs, vs_size, nullptr, vertex_out));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
706 ErrorD3D(d3dd->CreatePixelShader(ps, ps_size, nullptr, pixel_out));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
707 ErrorD3D(d3dd->CreateInputLayout(input_desc, input_desc_size, vs, vs_size, layout_out));
2518
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
708
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
709 delete [] vs;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
710 delete [] ps;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
711
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
712 return true;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
713 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
714
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
715
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
716
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
717 static HMODULE compiler_dll = nullptr;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
718 void DoCompile(const wchar_t *pFilename, const char *pSahderSource, unsigned int uShaderSourceLen,
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
719 unsigned char **vs, unsigned int *vs_size, unsigned char **ps, unsigned int *ps_size)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
720 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
721 const char *pVSEntry = "vs",
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
722 *pVSVersionString = "vs_4_0";
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
723 const char *pPSEntry = "main",
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
724 *pPSVersionString = "ps_4_0";
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
725
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
726
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
727 uint uVSCompileOptions =
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
728 #ifndef NDEBUG
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
729 D3D10_SHADER_SKIP_VALIDATION |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
730 D3D10_SHADER_SKIP_OPTIMIZATION |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
731 D3D10_SHADER_PREFER_FLOW_CONTROL;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
732 #else
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
733 D3D10_SHADER_SKIP_VALIDATION |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
734 D3D10_SHADER_OPTIMIZATION_LEVEL3 |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
735 D3D10_SHADER_WARNINGS_ARE_ERRORS |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
736 D3D10_SHADER_AVOID_FLOW_CONTROL |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
737 D3D10_SHADER_ENABLE_STRICTNESS |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
738 D3D10_SHADER_IEEE_STRICTNESS;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
739 #endif
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
740
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
741 *vs_size = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
742 *vs = nullptr;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
743 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
744 auto pVSBlob = DoD3DCompiling(pFilename, pSahderSource, uShaderSourceLen, pVSEntry, pVSVersionString, uVSCompileOptions);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
745 if (pVSBlob)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
746 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
747 *vs = new unsigned char[*vs_size = pVSBlob->GetBufferSize()];
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
748 memcpy(*vs, pVSBlob->GetBufferPointer(), *vs_size);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
749
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
750 pVSBlob->Release();
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
751 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
752 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
753
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
754
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
755 uint uPSCompileOptions =
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
756 #ifndef NDEBUG
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
757 D3D10_SHADER_SKIP_VALIDATION |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
758 D3D10_SHADER_SKIP_OPTIMIZATION |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
759 D3D10_SHADER_PREFER_FLOW_CONTROL;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
760 #else
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
761 D3D10_SHADER_SKIP_VALIDATION |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
762 D3D10_SHADER_OPTIMIZATION_LEVEL3 |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
763 D3D10_SHADER_WARNINGS_ARE_ERRORS |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
764 D3D10_SHADER_AVOID_FLOW_CONTROL |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
765 D3D10_SHADER_ENABLE_STRICTNESS |
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
766 D3D10_SHADER_IEEE_STRICTNESS;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
767 #endif
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
768
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
769 *ps_size = 0;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
770 *ps = nullptr;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
771 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
772 auto pPSBlob = DoD3DCompiling(pFilename, pSahderSource, uShaderSourceLen, pPSEntry, pPSVersionString, uPSCompileOptions);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
773 if (pPSBlob)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
774 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
775 *ps = new unsigned char[*ps_size = pPSBlob->GetBufferSize()];
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
776 memcpy(*ps, pPSBlob->GetBufferPointer(), *ps_size);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
777
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
778 pPSBlob->Release();
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
779 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
780 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
781 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
782
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
783 ID3DBlob *DoD3DCompiling(const wchar_t *shader_name, const char *pShaderSource, uint uShaderSourceLen, const char *pEntry, const char *pVersionString, uint uCompileOptions)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
784 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
785 ID3DBlob *pShader,
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
786 *pErrors;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
787
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
788 if (!compiler_dll)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
789 for (int i = 45; i >= 38; --i)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
790 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
791 wchar_t dll_name[64];
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
792 swprintf(dll_name, L"d3dcompiler_%u.dll", i);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
793
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
794 compiler_dll = LoadLibraryW(dll_name);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
795 if (compiler_dll)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
796 break;
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
797 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
798
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
799 if (!compiler_dll)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
800 Error("Cannot find any suitable d3dcompiler.dll");
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
801
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
802 typedef HRESULT (__stdcall *fnD3DCompile)(const void * pSrcData, SIZE_T SrcDataSize, LPCSTR pSourceName, CONST D3D_SHADER_MACRO* pDefines, ID3DInclude* pInclude, LPCSTR pEntrypoint, LPCSTR pTarget, UINT Flags1, UINT Flags2, ID3DBlob** ppCode, ID3DBlob** ppErrorMsgs);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
803 auto pD3DCompile = (fnD3DCompile)GetProcAddress(compiler_dll, "D3DCompile");
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
804
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
805 HRESULT hr = pD3DCompile(pShaderSource, uShaderSourceLen, nullptr, nullptr, nullptr, pEntry, pVersionString, uCompileOptions, 0, &pShader, &pErrors);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
806
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
807 if (FAILED(hr))
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
808 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
809 if (pErrors)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
810 Error("%S (%s) build failed:\n\n%s", shader_name, pVersionString, pErrors->GetBufferPointer());
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
811 else
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
812 Error("%S (%s) build failed", shader_name, pVersionString);
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
813 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
814 else if (pErrors)
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
815 {
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
816 Log::Warning(L"%s (%S) build warnings:\n\n%S", shader_name, pVersionString, pErrors->GetBufferPointer());
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
817 pErrors->Release();
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
818 }
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
819
3a1b56ab8749 d3d11 accepts RGBTexture
a.parshin
parents: 2508
diff changeset
820 return pShader;
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
821 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
822
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
823
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
824 void RenderD3D11::PrepareTexture(RGBTexture *p)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
825 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
826 if (!p->d3d11_srv)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
827 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
828 auto desc = p->d3d11_desc = new D3D11_TEXTURE2D_DESC;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
829 desc->Width = p->uWidth;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
830 desc->Height = p->uHeight;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
831 desc->ArraySize = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
832 desc->MipLevels = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
833 desc->Format = DXGI_FORMAT_R8G8B8A8_UNORM;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
834 desc->SampleDesc.Count = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
835 desc->SampleDesc.Quality = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
836 desc->Usage = D3D11_USAGE_DEFAULT;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
837 desc->BindFlags = D3D11_BIND_SHADER_RESOURCE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
838 desc->CPUAccessFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
839 desc->MiscFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
840
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
841 ID3D11Texture2D *vram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
842 ErrorD3D(d3dd->CreateTexture2D(desc, nullptr, &vram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
843
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
844 D3D11_TEXTURE2D_DESC ram_desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
845 memcpy(&ram_desc, desc, sizeof(ram_desc));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
846 ram_desc.Usage = D3D11_USAGE_STAGING;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
847 ram_desc.BindFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
848 ram_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
849
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
850 ID3D11Texture2D *ram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
851 ErrorD3D(d3dd->CreateTexture2D(&ram_desc, nullptr, &ram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
852
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
853 D3D11_MAPPED_SUBRESOURCE map;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
854 ErrorD3D(d3dc->Map(ram_texture, 0, D3D11_MAP_WRITE, 0, &map));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
855 for (unsigned int y = 0; y < desc->Height; ++y)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
856 for (unsigned int x = 0; x < desc->Width; ++x)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
857 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
858 auto src = p->pPixels + y * p->uWidth + x;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
859 auto dst = (unsigned int *)((char *)map.pData + y * map.RowPitch) + x;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
860
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
861 extern unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
862 *dst = 0xFF000000 | Color32_SwapRedBlue(*src);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
863 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
864
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
865 d3dc->Unmap(ram_texture, 0);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
866 d3dc->CopyResource(vram_texture, ram_texture);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
867 ram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
868
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
869 ErrorD3D(d3dd->CreateShaderResourceView(vram_texture, nullptr, (ID3D11ShaderResourceView **)&p->d3d11_srv));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
870 vram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
871 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
872 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
873
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
874
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
875
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
876 void RenderD3D11::PrepareTextureIndexed(Texture *p)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
877 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
878 if (!p->d3d11_srv)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
879 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
880 auto desc = p->d3d11_desc = new D3D11_TEXTURE2D_DESC;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
881 desc->Width = p->uTextureWidth;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
882 desc->Height = p->uTextureHeight;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
883 desc->ArraySize = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
884 desc->MipLevels = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
885 desc->Format = DXGI_FORMAT_R8G8B8A8_UNORM;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
886 desc->SampleDesc.Count = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
887 desc->SampleDesc.Quality = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
888 desc->Usage = D3D11_USAGE_DEFAULT;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
889 desc->BindFlags = D3D11_BIND_SHADER_RESOURCE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
890 desc->CPUAccessFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
891 desc->MiscFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
892
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
893 ID3D11Texture2D *vram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
894 ErrorD3D(d3dd->CreateTexture2D(desc, nullptr, &vram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
895
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
896 D3D11_TEXTURE2D_DESC ram_desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
897 memcpy(&ram_desc, desc, sizeof(ram_desc));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
898 ram_desc.Usage = D3D11_USAGE_STAGING;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
899 ram_desc.BindFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
900 ram_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
901
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
902 ID3D11Texture2D *ram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
903 ErrorD3D(d3dd->CreateTexture2D(&ram_desc, nullptr, &ram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
904
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
905 D3D11_MAPPED_SUBRESOURCE map;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
906 ErrorD3D(d3dc->Map(ram_texture, 0, D3D11_MAP_WRITE, 0, &map));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
907 for (unsigned int y = 0; y < desc->Height; ++y)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
908 for (unsigned int x = 0; x < desc->Width; ++x)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
909 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
910 auto index = p->pLevelOfDetail0_prolly_alpha_mask[y * p->uTextureWidth + x];
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
911 auto src = p->pPalette16[index];
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
912 auto dst = (unsigned int *)((char *)map.pData + y * map.RowPitch) + x;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
913
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
914 if (index)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
915 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
916 extern unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
917 *dst = 0xFF000000 | Color32_SwapRedBlue(src);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
918 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
919 else
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
920 *dst = 0x00000000;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
921 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
922
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
923 d3dc->Unmap(ram_texture, 0);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
924 d3dc->CopyResource(vram_texture, ram_texture);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
925 ram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
926
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
927 ErrorD3D(d3dd->CreateShaderResourceView(vram_texture, nullptr, (ID3D11ShaderResourceView **)&p->d3d11_srv));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
928 vram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
929 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
930 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
931
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
932
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
933 ID3D11ShaderResourceView *RenderD3D11::PrepareFontTexture(unsigned char *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned short *pFontPalette, unsigned short uFaceColor, unsigned short uShadowColor)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
934 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
935 D3D11_TEXTURE2D_DESC desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
936 desc.Width = uCharWidth;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
937 desc.Height = uCharHeight;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
938 desc.ArraySize = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
939 desc.MipLevels = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
940 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
941 desc.SampleDesc.Count = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
942 desc.SampleDesc.Quality = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
943 desc.Usage = D3D11_USAGE_DEFAULT;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
944 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
945 desc.CPUAccessFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
946 desc.MiscFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
947
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
948 ID3D11Texture2D *vram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
949 ErrorD3D(d3dd->CreateTexture2D(&desc, nullptr, &vram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
950
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
951 D3D11_TEXTURE2D_DESC ram_desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
952 memcpy(&ram_desc, &desc, sizeof(ram_desc));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
953 ram_desc.Usage = D3D11_USAGE_STAGING;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
954 ram_desc.BindFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
955 ram_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
956
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
957 ID3D11Texture2D *ram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
958 ErrorD3D(d3dd->CreateTexture2D(&ram_desc, nullptr, &ram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
959
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
960 D3D11_MAPPED_SUBRESOURCE map;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
961 ErrorD3D(d3dc->Map(ram_texture, 0, D3D11_MAP_WRITE, 0, &map));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
962 for (unsigned int y = 0; y < desc.Height; ++y)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
963 for (unsigned int x = 0; x < desc.Width; ++x)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
964 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
965 auto index = pFontPixels[y * desc.Width + x];
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
966 auto src = pFontPalette[index];
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
967 auto dst = (unsigned int *)((char *)map.pData + y * map.RowPitch) + x;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
968
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
969 if (index)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
970 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
971 extern unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
972 *dst = 0xFF000000 | Color32_SwapRedBlue(index == 1 ? uShadowColor : uFaceColor);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
973 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
974 else
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
975 *dst = 0x00000000;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
976 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
977
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
978 d3dc->Unmap(ram_texture, 0);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
979 d3dc->CopyResource(vram_texture, ram_texture);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
980 ram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
981
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
982 ID3D11ShaderResourceView *srv = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
983 ErrorD3D(d3dd->CreateShaderResourceView(vram_texture, nullptr, &srv));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
984 vram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
985
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
986 return srv;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
987 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
988
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
989
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
990 ID3D11ShaderResourceView *RenderD3D11::PrepareFontTexture(unsigned char *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned short *pFontPalette)
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
991 {
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
992 D3D11_TEXTURE2D_DESC desc;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
993 desc.Width = uCharWidth;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
994 desc.Height = uCharHeight;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
995 desc.ArraySize = 1;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
996 desc.MipLevels = 1;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
997 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
998 desc.SampleDesc.Count = 1;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
999 desc.SampleDesc.Quality = 0;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1000 desc.Usage = D3D11_USAGE_DEFAULT;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1001 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1002 desc.CPUAccessFlags = 0;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1003 desc.MiscFlags = 0;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1004
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1005 ID3D11Texture2D *vram_texture = nullptr;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1006 ErrorD3D(d3dd->CreateTexture2D(&desc, nullptr, &vram_texture));
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1007
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1008 D3D11_TEXTURE2D_DESC ram_desc;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1009 memcpy(&ram_desc, &desc, sizeof(ram_desc));
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1010 ram_desc.Usage = D3D11_USAGE_STAGING;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1011 ram_desc.BindFlags = 0;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1012 ram_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1013
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1014 ID3D11Texture2D *ram_texture = nullptr;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1015 ErrorD3D(d3dd->CreateTexture2D(&ram_desc, nullptr, &ram_texture));
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1016
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1017 D3D11_MAPPED_SUBRESOURCE map;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1018 ErrorD3D(d3dc->Map(ram_texture, 0, D3D11_MAP_WRITE, 0, &map));
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1019 for (unsigned int y = 0; y < desc.Height; ++y)
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1020 for (unsigned int x = 0; x < desc.Width; ++x)
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1021 {
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1022 auto index = pFontPixels[y * desc.Width + x];
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1023 auto src = pFontPalette[index];
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1024 auto dst = (unsigned int *)((char *)map.pData + y * map.RowPitch) + x;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1025
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1026 if (index)
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1027 {
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1028 extern unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1029 *dst = 0xFF000000 | Color32_SwapRedBlue(src);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1030 }
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1031 else
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1032 *dst = 0x00000000;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1033 }
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1034
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1035 d3dc->Unmap(ram_texture, 0);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1036 d3dc->CopyResource(vram_texture, ram_texture);
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1037 ram_texture->Release();
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1038
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1039 ID3D11ShaderResourceView *srv = nullptr;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1040 ErrorD3D(d3dd->CreateShaderResourceView(vram_texture, nullptr, &srv));
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1041 vram_texture->Release();
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1042
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1043 return srv;
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1044 }
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1045
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1046
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1047 void d3d11_release(ID3D11ShaderResourceView *srv)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1048 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1049 srv->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1050 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1051
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1052
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1053 //----- (004A4DE1) --------------------------------------------------------
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1054 bool RenderD3D11::LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1055 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1056 unsigned __int16 *v13; // ecx@19
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1057 unsigned __int16 *v14; // eax@19
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1058 DWORD v15; // edx@20
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1059
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1060 HWLTexture* pHWLTexture = pD3DBitmaps.LoadTexture(pName, bMipMaps);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1061 if (!pHWLTexture)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1062 return false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1063
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1064 int num_min_levels = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1065 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1066 int dim = min(pHWLTexture->uWidth, pHWLTexture->uHeight);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1067 while (dim > 1)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1068 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1069 dim /= 2;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1070 num_min_levels++;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1071 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1072 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1073
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1074
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1075 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1076 D3D11_TEXTURE2D_DESC desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1077 desc.Width = pHWLTexture->uWidth;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1078 desc.Height = pHWLTexture->uHeight;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1079 desc.ArraySize = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1080 desc.MipLevels = num_min_levels;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1081 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1082 desc.SampleDesc.Count = 1;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1083 desc.SampleDesc.Quality = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1084 desc.Usage = D3D11_USAGE_DEFAULT;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1085 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET/* for mipmap generation */;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1086 desc.CPUAccessFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1087 desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1088
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1089 ID3D11Texture2D *vram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1090 ErrorD3D(d3dd->CreateTexture2D(&desc, nullptr, &vram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1091
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1092 D3D11_TEXTURE2D_DESC ram_desc;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1093 memcpy(&ram_desc, &desc, sizeof(ram_desc));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1094 ram_desc.Usage = D3D11_USAGE_STAGING;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1095 ram_desc.BindFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1096 ram_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1097 ram_desc.MiscFlags = 0;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1098
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1099 ID3D11Texture2D *ram_texture = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1100 ErrorD3D(d3dd->CreateTexture2D(&ram_desc, nullptr, &ram_texture));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1101
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1102 D3D11_MAPPED_SUBRESOURCE map;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1103 ErrorD3D(d3dc->Map(ram_texture, 0, D3D11_MAP_WRITE, 0, &map));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1104 for (unsigned int y = 0; y < desc.Height; ++y)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1105 for (unsigned int x = 0; x < desc.Width; ++x)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1106 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1107 auto src = pHWLTexture->pPixels + y * desc.Width + x;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1108 auto dst = (unsigned int *)((char *)map.pData + y * map.RowPitch) + x;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1109
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1110 extern unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1111 *dst = 0xFF000000 | Color32_SwapRedBlue(*src);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1112 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1113
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1114 d3dc->Unmap(ram_texture, 0);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1115 d3dc->CopyResource(vram_texture, ram_texture);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1116 ram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1117
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1118 ID3D11ShaderResourceView *srv = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1119 ErrorD3D(d3dd->CreateShaderResourceView(vram_texture, nullptr, &srv));
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1120 vram_texture->Release();
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1121
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1122 d3dc->GenerateMips(srv);
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1123 *pOutTexture = (IDirect3DTexture2 *)srv;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1124 *pOutSurface = nullptr;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1125 }
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1126
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1127 delete [] pHWLTexture->pPixels;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1128 delete pHWLTexture;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2523
diff changeset
1129 return true;
2525
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1130 }
4cc81f981afb Everything except game can use d3d11
a.parshin
parents: 2524
diff changeset
1131