-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRayTracingEngineView.cpp
More file actions
193 lines (148 loc) · 4.94 KB
/
RayTracingEngineView.cpp
File metadata and controls
193 lines (148 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// RayTracingEngineView.cpp : implementation of the CRayTracingEngineView class
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "RayTracingEngine.h"
#endif
#include "RayTracingEngineDoc.h"
#include "RayTracingEngineView.h"
#include "ApplicationEngine.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CRayTracingEngineView
IMPLEMENT_DYNCREATE(CRayTracingEngineView, CView)
BEGIN_MESSAGE_MAP(CRayTracingEngineView, CView)
ON_COMMAND(ID_RENDER, &CRayTracingEngineView::OnRender)
END_MESSAGE_MAP()
// CRayTracingEngineView construction/destruction
CRayTracingEngineView::CRayTracingEngineView()
{
// TODO: add construction code here
m_pApplication = nullptr;
}
CRayTracingEngineView::~CRayTracingEngineView()
{
delete m_pApplication;
}
BOOL CRayTracingEngineView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CRayTracingEngineView drawing
void CRayTracingEngineView::OnDraw(CDC* pDC)
{
CRayTracingEngineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
if (m_pApplication != nullptr)
DrawFrameBuffer(pDC);
}
// CRayTracingEngineView diagnostics
#ifdef _DEBUG
void CRayTracingEngineView::AssertValid() const
{
CView::AssertValid();
}
void CRayTracingEngineView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CRayTracingEngineDoc* CRayTracingEngineView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRayTracingEngineDoc)));
return (CRayTracingEngineDoc*)m_pDocument;
}
#endif //_DEBUG
void CRayTracingEngineView::DrawFrameBuffer(CDC *pDC)
{
if (m_pApplication->m_pFrameBuffer == nullptr)
{
return;
}
HDC hdc;
hdc = ::CreateCompatibleDC(pDC->m_hDC);
HBITMAP m_bitmap;
// Display the current image
char buffer[sizeof(BITMAPINFO)];
BITMAPINFO* binfo = (BITMAPINFO*)buffer;
memset(binfo, 0, sizeof(BITMAPINFOHEADER));
binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// Create the bitmap
BITMAPINFOHEADER* bih = &binfo->bmiHeader;
bih->biBitCount = 3 * 8;
bih->biWidth = m_pApplication->m_nWidth;
bih->biHeight = m_pApplication->m_nHeight;
bih->biPlanes = 1;
bih->biCompression = BI_RGB;
bih->biSizeImage = 0;
m_bitmap = CreateDIBSection(hdc, binfo, 0, 0, 0, DIB_RGB_COLORS);
int colors = DIB_RGB_COLORS;
::SelectObject(hdc, m_bitmap);
binfo->bmiHeader.biBitCount = 0;
GetDIBits(hdc, m_bitmap, 0, 0, 0, binfo, colors);
binfo->bmiHeader.biBitCount = 24;
binfo->bmiHeader.biHeight = -abs(binfo->bmiHeader.biHeight);
SetDIBits(hdc, m_bitmap, 0, m_pApplication->m_nHeight, m_pApplication->m_pFrameBuffer, binfo, colors);
::SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);
CRect client;
GetClientRect(&client);
::BitBlt(pDC->m_hDC, 0, 0, m_pApplication->m_nWidth, m_pApplication->m_nHeight,
hdc, 0, 0, SRCCOPY);
::DeleteDC(hdc);
DeleteObject(m_bitmap);
}
void CRayTracingEngineView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
// Assign Application 5
if (m_pApplication == nullptr)
{
m_pApplication = new ApplicationEngine;
}
// Initialize and begin renderer
((ApplicationEngine *)m_pApplication)->Initialize();
}
/*
void CRayTracingEngineView::OnRender()
{
// TODO: Add your command handler code here
if (m_pApplication != nullptr)
((ApplicationEngine *)m_pApplication)->Render();
else
AfxMessageBox("Application was not allocated\n");
// Set window size
CRect clientRect, windowRect;
int x_offset, y_offset;
GetClientRect(&clientRect);
AfxGetMainWnd()->GetWindowRect(&windowRect);
x_offset = windowRect.Width() - clientRect.Width();
y_offset = windowRect.Height() - clientRect.Height();
AfxGetMainWnd()->SetWindowPos(NULL, 0, 0, x_offset + m_pApplication->m_nWidth, y_offset + m_pApplication->m_nHeight, NULL);
Invalidate(true);
}
*/
void CRayTracingEngineView::OnRender()
{
// TODO: Add your command handler code here
if (m_pApplication != nullptr)
((ApplicationEngine *)m_pApplication)->Render();
else
AfxMessageBox(_T("Application was not allocated\n"));
// Set window size
CRect clientRect, windowRect;
int x_offset, y_offset;
GetClientRect(&clientRect);
AfxGetMainWnd()->GetWindowRect(&windowRect);
x_offset = windowRect.Width() - clientRect.Width();
y_offset = windowRect.Height() - clientRect.Height();
AfxGetMainWnd()->SetWindowPos(NULL, 0, 0, x_offset + m_pApplication->m_nWidth, y_offset + m_pApplication->m_nHeight, NULL);
Invalidate(true);
}