46
46
mouse_drag.connect(sigc::mem_fun(this, &ClientArea::RecvMouseDrag));
47
47
mouse_move.connect(sigc::mem_fun(this, &ClientArea::RecvMouseMove));
48
48
key_down.connect(sigc::mem_fun(this, &ClientArea::RecvKeyEvent));
50
if (GetWindowThread()->GetGraphicsDisplay().HasFrameBufferSupport())
52
m_FrameBufferObject = GetGraphicsDisplay()->GetGpuDevice()->CreateFrameBufferObject();
53
m_MainColorRT = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(2, 2, 1, BITFMT_R8G8B8A8, NUX_TRACKER_LOCATION);
54
m_MainDepthRT = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(2, 2, 1, BITFMT_D24S8, NUX_TRACKER_LOCATION);
58
51
ClientArea::~ClientArea()
62
void ClientArea::BeginDraw(GraphicsEngine &graphics_engine, bool force_draw)
55
void ClientArea::BeginDraw(GraphicsEngine& graphics_engine, bool force_draw)
64
if ((IsRedrawNeeded() == false) && (force_draw == false))
57
// if ((IsRedrawNeeded() == false) && (force_draw == false))
61
unsigned int current_alpha_blend;
62
unsigned int current_src_blend_factor;
63
unsigned int current_dest_blend_factor;
64
graphics_engine.GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
66
ObjectPtr<IOpenGLFrameBufferObject> prev_fbo_ = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
67
Geometry prev_viewport_ = graphics_engine.GetViewportRect();
67
69
if (GetWindowThread()->GetGraphicsDisplay().HasFrameBufferSupport())
69
int buffer_width = GetBaseWidth();
70
int buffer_height = GetBaseHeight();
71
int width = GetWidth();
72
int height = GetHeight();
71
73
int window_width, window_height;
72
window_width = graphics_engine.GetViewportWidth();
73
window_height = graphics_engine.GetViewportHeight();
74
window_width = prev_viewport_.width;
75
window_height = prev_viewport_.height;
77
m_ctx.width = GetBaseWidth();
78
m_ctx.height = GetBaseHeight();
80
m_ctx.height = height;
80
82
// A is obtained from graphics_engine. So A dimension's are in relative window coordinates.
81
83
Rect A = graphics_engine.GetClippingRegion();
87
89
m_ctx.width_clipregion = C.GetWidth();
88
90
m_ctx.height_clipregion = C.GetHeight();
90
ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
92
if ((m_FrameBufferObject->GetWidth() != buffer_width) || (m_FrameBufferObject->GetHeight() != buffer_height))
94
m_FrameBufferObject->FormatFrameBufferObject(buffer_width, buffer_height, BITFMT_R8G8B8A8);
95
m_MainColorRT = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(buffer_width, buffer_height, 1, BITFMT_R8G8B8A8, NUX_TRACKER_LOCATION);
96
m_MainDepthRT = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(buffer_width, buffer_height, 1, BITFMT_D24S8, NUX_TRACKER_LOCATION);
99
m_FrameBufferObject->SetRenderTarget(0, m_MainColorRT->GetSurfaceLevel(0));
100
m_FrameBufferObject->SetDepthSurface(m_MainDepthRT->GetSurfaceLevel(0));
92
//ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
94
if (m_FrameBufferObject.IsNull())
96
// Create the fbo before using it for the first time.
97
m_FrameBufferObject = GetGraphicsDisplay()->GetGpuDevice()->CreateFrameBufferObject();
100
if (!m_MainColorRT.IsValid() || (m_MainColorRT->GetWidth() != width) || (m_MainColorRT->GetHeight() != height))
102
// Create or resize the color and depth textures before using them.
103
m_MainColorRT = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(width, height, 1, BITFMT_R8G8B8A8, NUX_TRACKER_LOCATION);
104
m_MainDepthRT = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(width, height, 1, BITFMT_D24S8, NUX_TRACKER_LOCATION);
107
m_FrameBufferObject->FormatFrameBufferObject(width, height, BITFMT_R8G8B8A8);
108
m_FrameBufferObject->EmptyClippingRegion();
109
m_FrameBufferObject->SetTextureAttachment(0, m_MainColorRT, 0);
110
m_FrameBufferObject->SetDepthTextureAttachment(m_MainDepthRT, 0);
101
111
m_FrameBufferObject->Activate();
103
graphics_engine.SetViewport(0, 0, buffer_width, buffer_height);
104
m_FrameBufferObject->EmptyClippingRegion();
106
ClientDraw(graphics_engine, m_ctx, force_draw);
108
// Restore the main frame buffer object
111
Area* view_window = GetTopLevelViewWindow();
114
graphics_engine.SetViewport(0, 0, view_window->GetBaseWidth(), view_window->GetBaseHeight());
115
graphics_engine.ApplyClippingRectangle();
116
graphics_engine.ApplyModelViewMatrix();
117
graphics_engine.SetOrthographicProjectionMatrix(view_window->GetBaseWidth(), view_window->GetBaseHeight());
122
graphics_engine.SetViewport(0, 0, window_width, window_height);
123
graphics_engine.ApplyClippingRectangle();
124
graphics_engine.ApplyModelViewMatrix();
125
graphics_engine.SetOrthographicProjectionMatrix(window_width, window_height);
128
// Copy the client frame buffer into the main frame buffer.
131
w = m_MainColorRT->GetWidth();
132
h = m_MainColorRT->GetHeight();
136
TexCoordXForm texxform0;
137
texxform0.uwrap = TEXWRAP_CLAMP;
138
texxform0.vwrap = TEXWRAP_CLAMP;
139
texxform0.FlipVCoord(true);
140
GetGraphicsDisplay()->GetGraphicsEngine()->QRP_1Tex(x, y, w, h, m_MainColorRT, texxform0, Color(color::White));
145
int x = graphics_engine.GetContextX();
146
int y = graphics_engine.GetContextY();
148
// The clientarea is in absolute window coordinates. It needs to be offset so that it is in relative window coordinates.
149
m_ctx.x = GetBaseX() + x;
150
m_ctx.y = GetBaseY() + y;
151
m_ctx.width = GetBaseWidth();
152
m_ctx.height = GetBaseHeight();
154
// A is obtained from graphics_engine. So A dimension's are in relative window coordinates.
155
Rect A = graphics_engine.GetClippingRegion();
157
Rect B = Rect(m_ctx.x, m_ctx.y, m_ctx.width, m_ctx.height);
158
Rect C = A.Intersect(B);
160
m_ctx.x_clipregion = C.x;
161
m_ctx.y_clipregion = C.y;
162
m_ctx.width_clipregion = C.GetWidth();
163
m_ctx.height_clipregion = C.GetHeight();
165
int window_width, window_height;
166
window_width = graphics_engine.GetViewportWidth();
167
window_height = graphics_engine.GetViewportHeight();
169
SetClientViewport(graphics_engine);
170
// graphics_engine.SetViewport(
171
// m_ctx.x, window_height - m_ctx.y - m_ctx.height, m_ctx.width, m_ctx.height);
173
// graphics_engine.SetOpenGLClippingRectangle(
174
// m_ctx.x_clipregion,
175
// window_height - m_ctx.y_clipregion - m_ctx.height_clipregion,
176
// m_ctx.width_clipregion,
177
// m_ctx.height_clipregion);
179
ClientDraw(graphics_engine, m_ctx, force_draw);
181
// go back to 2D in case that was changed by the client.
182
graphics_engine.SetViewport(0, 0, window_width, window_height);
183
graphics_engine.ApplyClippingRectangle();
184
graphics_engine.Push2DWindow(window_width, window_height);
113
graphics_engine.SetViewport(0, 0, width, height);
116
ClientDraw(graphics_engine, m_ctx, force_draw);
119
if (prev_fbo_.IsValid())
121
// Restore the previous fbo
122
prev_fbo_->Activate();
124
prev_fbo_->ApplyClippingRegion();
127
// Restore the matrices and the view port.
128
graphics_engine.ApplyModelViewMatrix();
129
graphics_engine.SetOrthographicProjectionMatrix(prev_viewport_.width, prev_viewport_.height);
130
graphics_engine.SetViewport(prev_viewport_.x, prev_viewport_.y, prev_viewport_.width, prev_viewport_.height);
134
w = m_MainColorRT->GetWidth();
135
h = m_MainColorRT->GetHeight();
139
TexCoordXForm texxform0;
140
texxform0.uwrap = TEXWRAP_CLAMP;
141
texxform0.vwrap = TEXWRAP_CLAMP;
142
texxform0.FlipVCoord(true);
143
GetGraphicsDisplay()->GetGraphicsEngine()->QRP_1Tex(x, y, w, h, m_MainColorRT, texxform0, Color(color::White));
146
// restore blend states
147
graphics_engine.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
188
150
void ClientArea::Draw(GraphicsEngine &graphics_engine, bool force_draw)