Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/CockpitInteriorRenderFixture.h

Source at documentation-generation time. See Test catalog for fixture associations.

1// Exercise the production interior draw path after the aircraft's two-UV layout.
2// Only the surrounding game state is stubbed; drawing uses the native DX11 device.
3void CockpitInteriors(Window11& host)
4{
5 RenderDevice device(host.Draws());
6 RenderMaterial material(device);
7 constexpr DWORD RISE_FVF_VERTEX = VertexFormat::XYZ | VertexFormat::NORMAL | VertexFormat::TEX1;
8 constexpr DWORD shipFormat = VertexFormat::XYZ | VertexFormat::NORMAL | VertexFormat::TEX2;
9 constexpr int REF_WINDOWLESS=1,REF_BUILDING=2;
10 enum class VehicleType { Hangar,ControlTower };
11 struct RiseVertexVertex { float x,y,z,nx,ny,nz,u,v; };
12 const RiseVertexVertex room[] = {
13 {-1,1,.75f,0,0,-1,0,0},{1,1,.75f,0,0,-1,1,0},{-1,-1,.75f,0,0,-1,0,1},
14 {1,1,.75f,0,0,-1,1,0},{1,-1,.75f,0,0,-1,1,1},{-1,-1,.75f,0,0,-1,0,1}
15 };
16 ComPtr<RenderBuffer> buffer;
17 HR(device.CreateVertexBuffer(sizeof(room),0,RISE_FVF_VERTEX,ResourcePool::Managed,&buffer,nullptr),"interior mesh buffer");
18 void* data=nullptr;
19 HR(buffer->Lock(0,0,&data,0),"lock interior mesh");
20 memcpy(data,room,sizeof(room));HR(buffer->Unlock(),"upload interior mesh");
21 ComPtr<RenderTexture> texture;
22 HR(CreateTexture(&device,1,1,1,0,ImageFormat::BGRA8,ResourcePool::Managed,&texture),"interior wall texture");
23 LockedRectangle pixel;
24 HR(texture->LockRect(0,&pixel,nullptr,0),"lock interior texture");
25 *static_cast<DWORD*>(pixel.pBits)=0xff408020;
26 HR(texture->UnlockRect(0),"upload interior texture");
27
28 struct Component {
29 unsigned char type=0;bool visible=true;short texture=0;
30 UINT startvertex=0,primitives=2;RiseMath::Matrix matWorld;
31 };
32 struct Cockpit {
33 unsigned ourplyrC=0,components=1;
35 float power=1;short screentexture=-1,projecttexture=-1;
36 Component componentarray[1];
37 } ourcockpit;
38 struct Geometry { RenderBuffer* VB=nullptr; } polyobjects[6];
39 polyobjects[5].VB=buffer.Get();
40 struct Gui { struct Player { int frame=REF_WINDOWLESS; } player[1]; } gui;
41 struct Graphics { RenderMaterial* g_pEffect; } graphics{&material};
42 struct Game { Gui* GUI;Graphics* graphics; } game{&gui,&graphics};
43 struct View {
44 Game* gameclass;RiseMath::Matrix matrixLook,matrixProjCock;
45 Light sunlight{};
46 RenderTexture* m_pddsDynamicTexture=nullptr;
47 RenderTexture* m_pddsProjectionTexture=nullptr;
48 RenderTexture* m_pddsCockpitTexture[1];
49 RenderTexture* m_pddsCockpitLights[1]{};
50 } view{&game};
51 view.m_pddsCockpitTexture[0]=texture.Get();
52 auto* viewscreen=&view;
53 struct Logger { void AddToCallStack(const char*) {} } log;
54 auto* logger=&log;
55 RiseMath::MatrixIdentity(&view.matrixLook);RiseMath::MatrixIdentity(&view.matrixProjCock);
57 const auto renderInterior=[&](RenderDevice* pd3dDevice) {
58#pragma push_macro("V")
59#undef V
60#define V(call) HR(hr=(call),#call)
61#include "CockpitInterior.generated.h"
62#pragma pop_macro("V")
63 };
64
65 HR(device.BeginScene(),"begin interior regression");
66 HR(device.SetRenderState(RenderState::CULLMODE,Cull::NONE),"interior fixture winding");
67 HR(device.SetRenderState(RenderState::STENCILENABLE,TRUE),"interior stencil enabled");
68 HR(device.SetRenderState(RenderState::LIGHTING,FALSE),"aircraft fixture unlit");
69 HR(device.SetRenderState(RenderState::TEXTUREFACTOR,0xff0000ff),"aircraft fixture color");
70 HR(device.SetTextureStageState(0,TextureState::COLOROP,TextureOperation::SELECTARG1),"aircraft fixture solid color");
71 HR(device.SetTextureStageState(0,TextureState::COLORARG1,TextureArgument::TFACTOR),"aircraft fixture factor");
72 HR(device.SetTextureStageState(0,TextureState::ALPHAOP,TextureOperation::SELECTARG1),"aircraft fixture opacity");
73 HR(device.SetTextureStageState(0,TextureState::ALPHAARG1,TextureArgument::TFACTOR),"aircraft fixture alpha factor");
74 struct ShipVertex { RiseVertexVertex vertex;float u2,v2; };
75 ShipVertex ship[6]{};
76 for(unsigned i=0;i<6;++i) {
77 ship[i].vertex=room[i];ship[i].vertex.x*=.25f;ship[i].vertex.y*=.25f;ship[i].vertex.z=.25f;
78 }
79 std::vector<uint32_t> reference;
80 for(int frame:{REF_WINDOWLESS,REF_BUILDING}) for(bool aircraftFirst:{false,true}) {
81 gui.player[0].frame=frame;
82 HR(device.Clear(0,nullptr,ClearFlags::TARGET|ClearFlags::ZBUFFER|ClearFlags::STENCIL,0xff000000,1,0),"clear interior fixture");
83 HR(device.SetRenderState(RenderState::STENCILFUNC,Compare::ALWAYS),"aircraft stencil");
84 HR(device.SetFVF(aircraftFirst ? shipFormat : RISE_FVF_VERTEX),"preceding geometry format");
85 if(aircraftFirst)
86 HR(device.DrawPrimitiveUP(Primitive::TriangleList,2,ship,sizeof(ShipVertex)),"draw aircraft before room");
87 renderInterior(&device);
88 const auto pixels=Pixels(host.Device());
89 std::cout<<"Interior frame="<<frame<<" aircraft="<<aircraftFirst<<" wall=0x"<<std::hex
90 <<pixels[8*64+8]<<" center=0x"<<pixels[24*64+32]<<std::dec<<'\n';
91 Check(pixels[8*64+8]==0xff408020,"building interior paints its wall texture");
92 Check(pixels[24*64+32]==(aircraftFirst ? 0xff0000ff : 0xff408020),"interior preserves the aircraft in front of the room");
93 if(!aircraftFirst) {
94 if(reference.empty())reference=pixels;
95 else Check(pixels==reference,"windowless and windowed interior paths agree");
96 }
97 else {
98 unsigned walls=0;
99 for(size_t i=0;i<pixels.size();++i)if(pixels[i]!=0xff0000ff) {
100 Check(pixels[i]==reference[i],"aircraft layout does not alter surrounding interior pixels");++walls;
101 }
102 Check(walls>2000,"room remains visible around the aircraft");
103 }
104 }
105 HR(device.EndScene(),"finish interior regression");
106 DebugClean(host.Device());
107}
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
VehicleType
Definition ServerTypes.h:60
@ Hangar
Definition ServerTypes.h:90
@ ControlTower
Definition ServerTypes.h:86
@ REF_BUILDING
Definition ServerTypes.h:46
@ REF_WINDOWLESS
Definition ServerTypes.h:50
Rendering::RenderMaterial * g_pEffect
Definition Graphics.h:30
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
Scockpit ourcockpit
Definition globals.cpp:114
s_polygon_object polyobjects[maxpolyC]
Definition globals.cpp:106
#define RISE_FVF_VERTEX
Definition globals.h:118
Path Geometry(const Input &, const Request &r, const ArrivalPreview &gate)
constexpr uint8_t Pixels[262144]
HRESULT CreateTexture(RenderDevice *owner, UINT width, UINT height, UINT levels, DWORD usage, ImageFormat format, ResourcePool pool, RenderTexture **result)
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
@ Game
Use the game audio system.
Definition discordpp.h:505
gui(open_browser=True)
Definition erin.py:108
type
Definition erin.py:143
s_mesh_component * componentarray
Definition globals.h:704
RiseMath::Matrix matWorld
Definition globals.h:425
Rendering::RenderBuffer * VB
Definition globals.h:360