|
11 | 11 | #include "impeller/playground/playground.h"
|
12 | 12 | #include "impeller/renderer/allocator.h"
|
13 | 13 | #include "impeller/renderer/backend/metal/context_mtl.h"
|
| 14 | +#include "impeller/renderer/backend/metal/surface_mtl.h" |
14 | 15 | #include "impeller/renderer/backend/metal/texture_mtl.h"
|
15 | 16 | #include "impeller/renderer/context.h"
|
16 | 17 | #include "impeller/renderer/formats.h"
|
17 | 18 | #include "impeller/renderer/render_pass.h"
|
18 | 19 | #include "impeller/renderer/renderer.h"
|
19 |
| -#include "impeller/renderer/surface.h" |
20 | 20 |
|
21 | 21 | #define GLFW_INCLUDE_NONE
|
22 | 22 | #import "third_party/glfw/include/GLFW/glfw3.h"
|
@@ -138,81 +138,17 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
|
138 | 138 | return true;
|
139 | 139 | }
|
140 | 140 |
|
141 |
| - auto current_drawable = [layer nextDrawable]; |
142 |
| - |
143 |
| - if (!current_drawable) { |
144 |
| - VALIDATION_LOG << "Could not acquire current drawable."; |
145 |
| - return false; |
146 |
| - } |
147 |
| - |
148 |
| - TextureDescriptor msaa_tex_desc; |
149 |
| - msaa_tex_desc.type = TextureType::k2DMultisample; |
150 |
| - msaa_tex_desc.sample_count = SampleCount::kCount4; |
151 |
| - msaa_tex_desc.format = PixelFormat::kB8G8R8A8UNormInt; |
152 |
| - msaa_tex_desc.size = { |
153 |
| - static_cast<ISize::Type>(current_drawable.texture.width), |
154 |
| - static_cast<ISize::Type>(current_drawable.texture.height)}; |
155 |
| - msaa_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget); |
156 |
| - |
157 |
| - auto msaa_tex = |
158 |
| - renderer_.GetContext()->GetPermanentsAllocator()->CreateTexture( |
159 |
| - StorageMode::kDeviceTransient, msaa_tex_desc); |
160 |
| - if (!msaa_tex) { |
161 |
| - FML_LOG(ERROR) << "Could not allocate MSAA resolve texture."; |
162 |
| - return false; |
163 |
| - } |
164 |
| - |
165 |
| - msaa_tex->SetLabel("PlaygroundMainColor4xMSAA"); |
166 |
| - |
167 |
| - TextureDescriptor onscreen_tex_desc; |
168 |
| - onscreen_tex_desc.format = PixelFormat::kB8G8R8A8UNormInt; |
169 |
| - onscreen_tex_desc.size = msaa_tex_desc.size; |
170 |
| - onscreen_tex_desc.usage = |
171 |
| - static_cast<uint64_t>(TextureUsage::kRenderTarget); |
172 |
| - |
173 |
| - ColorAttachment color0; |
174 |
| - color0.texture = msaa_tex; |
175 |
| - color0.clear_color = Color::DarkSlateGray(); |
176 |
| - color0.load_action = LoadAction::kClear; |
177 |
| - color0.store_action = StoreAction::kMultisampleResolve; |
178 |
| - color0.resolve_texture = std::make_shared<TextureMTL>( |
179 |
| - onscreen_tex_desc, current_drawable.texture); |
180 |
| - |
181 |
| - TextureDescriptor stencil0_tex; |
182 |
| - stencil0_tex.type = TextureType::k2DMultisample; |
183 |
| - stencil0_tex.sample_count = SampleCount::kCount4; |
184 |
| - stencil0_tex.format = PixelFormat::kD32FloatS8UNormInt; |
185 |
| - stencil0_tex.size = msaa_tex_desc.size; |
186 |
| - stencil0_tex.usage = |
187 |
| - static_cast<TextureUsageMask>(TextureUsage::kRenderTarget); |
188 |
| - auto stencil_texture = |
189 |
| - renderer_.GetContext()->GetPermanentsAllocator()->CreateTexture( |
190 |
| - StorageMode::kDeviceTransient, stencil0_tex); |
191 |
| - stencil_texture->SetLabel("PlaygroundMainStencil"); |
192 |
| - |
193 |
| - StencilAttachment stencil0; |
194 |
| - stencil0.texture = stencil_texture; |
195 |
| - stencil0.clear_stencil = 0; |
196 |
| - stencil0.load_action = LoadAction::kClear; |
197 |
| - stencil0.store_action = StoreAction::kDontCare; |
198 |
| - |
199 |
| - RenderTarget desc; |
200 |
| - desc.SetColorAttachment(color0, 0u); |
201 |
| - desc.SetStencilAttachment(stencil0); |
202 |
| - |
203 |
| - Surface surface(desc); |
204 |
| - |
205 | 141 | Renderer::RenderCallback wrapped_callback = [render_callback](auto& pass) {
|
206 | 142 | pass.SetLabel("Playground Main Render Pass");
|
207 | 143 | return render_callback(pass);
|
208 | 144 | };
|
209 | 145 |
|
210 |
| - if (!renderer_.Render(surface, wrapped_callback)) { |
| 146 | + if (!renderer_.Render(SurfaceMTL::WrapCurrentMetalLayerDrawable( |
| 147 | + renderer_.GetContext(), layer), |
| 148 | + wrapped_callback)) { |
211 | 149 | VALIDATION_LOG << "Could not render into the surface.";
|
212 | 150 | return false;
|
213 | 151 | }
|
214 |
| - |
215 |
| - [current_drawable present]; |
216 | 152 | }
|
217 | 153 |
|
218 | 154 | return true;
|
|
0 commit comments