KiCad PCB EDA Suite
Loading...
Searching...
No Matches
render_3d_raytrace_ram.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2020 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2024 Alex Shvartzkop <[email protected]>
6 * Copyright (C) 2015-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
27#include <wx/log.h>
28
29
31 RENDER_3D_RAYTRACE_BASE( aAdapter, aCamera ),
32 m_outputBuffer( nullptr ),
33 m_pboDataSize( 0 )
34{
35}
36
37
39{
40 deletePbo();
41}
42
43
45{
46 return m_outputBuffer;
47}
48
49
51{
52 return wxSize( m_realBufferSize.x, m_realBufferSize.y );
53}
54
55
57{
58 delete[] m_outputBuffer;
59 m_outputBuffer = nullptr;
60}
61
62
64{
65 if( m_windowSize != aSize )
66 {
67 m_windowSize = aSize;
68
69 initPbo();
70 }
71}
72
73
74bool RENDER_3D_RAYTRACE_RAM::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
75 REPORTER* aWarningReporter )
76{
77 bool requestRedraw = false;
78
79 // Initialize openGL if need
81 {
83
84 //aIsMoving = true;
85 requestRedraw = true;
86
87 // It will assign the first time the windows size, so it will now
88 // revert to preview mode the first time the Redraw is called
91 }
92
93 std::unique_ptr<BUSY_INDICATOR> busy = CreateBusyIndicator();
94
95 // Reload board if it was requested
97 {
98 if( aStatusReporter )
99 aStatusReporter->Report( _( "Loading..." ) );
100
101 //aIsMoving = true;
102 requestRedraw = true;
103 Reload( aStatusReporter, aWarningReporter, false );
104 }
105
106
107 // Recalculate constants if windows size was changed
109 {
111 aIsMoving = true;
112 requestRedraw = true;
113
115 }
116
117 const bool was_camera_changed = m_camera.ParametersChanged();
118
119 if( requestRedraw || aIsMoving || was_camera_changed )
120 m_renderState = RT_RENDER_STATE_MAX; // Set to an invalid state,
121 // so it will restart again latter
122
123 // This will only render if need, otherwise it will redraw the PBO on the screen again
124 if( aIsMoving || was_camera_changed )
125 {
126 // Set head light (camera view light) with the opposite direction of the camera
127 if( m_cameraLight )
129
130 if( m_outputBuffer )
131 {
133 }
134 }
135 else
136 {
138 {
139 if( m_outputBuffer )
140 {
141 render( m_outputBuffer, aStatusReporter );
142
144 requestRedraw = true;
145 }
146 }
147 }
148
149 return requestRedraw;
150}
151
152
154{
155 deletePbo();
156
158 m_outputBuffer = new GLubyte[m_pboDataSize]();
159}
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:73
A class used to derive camera objects from.
Definition: camera.h:103
const SFVEC3F & GetDir() const
Definition: camera.h:135
bool ParametersChanged()
Definition: camera.cpp:721
void SetDirection(const SFVEC3F &aDir)
Set directional light orientation.
Definition: light.h:131
CAMERA & m_camera
Flag if the canvas specific for this render was already initialized.
std::unique_ptr< BUSY_INDICATOR > CreateBusyIndicator() const
Return a created busy indicator, if a factory has been set, else a null pointer.
bool m_reloadRequested
The window size that this camera is working.
void Reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter, bool aOnlyLoadCopperAndShapes)
void render(GLubyte *ptrPBO, REPORTER *aStatusReporter)
DIRECTIONAL_LIGHT * m_cameraLight
RT_RENDER_STATE m_renderState
State used on quality render.
void renderPreview(GLubyte *ptrPBO)
wxSize m_oldWindowsSize
Encode Morton code positions.
RENDER_3D_RAYTRACE_RAM(BOARD_ADAPTER &aAdapter, CAMERA &aCamera)
bool Redraw(bool aIsMoving, REPORTER *aStatusReporter, REPORTER *aWarningReporter) override
Redraw the view.
void SetCurWindowSize(const wxSize &aSize) override
Before each render, the canvas will tell the render what is the size of its windows,...
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
#define _(s)
@ RT_RENDER_STATE_FINISH
@ RT_RENDER_STATE_MAX