annotate Engine/Graphics/RenderD3D11.cpp @ 2524:c7264ab7132f

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