| 40 | MultiSampling::~MultiSampling() {} |
| 41 | |
| 42 | void MultiSampling::onLoad(RenderContext* pRenderContext) |
| 43 | { |
| 44 | // Load program |
| 45 | mpRasterPass = RasterPass::create(getDevice(), "Samples/MultiSampling/MultiSampling.3d.slang", "vsMain", "psMain"); |
| 46 | |
| 47 | // Create disk triangles |
| 48 | float2 vertices[kTriangleCount * 3]; |
| 49 | for (uint32_t i = 0; i < kTriangleCount; ++i) |
| 50 | { |
| 51 | float theta0 = float(i) / kTriangleCount * M_2PI; |
| 52 | float theta1 = float(i + 1) / kTriangleCount * M_2PI; |
| 53 | vertices[i * 3 + 0] = float2(0, 0); |
| 54 | vertices[i * 3 + 1] = float2(cos(theta0), sin(theta0)) * 0.75f; |
| 55 | vertices[i * 3 + 2] = float2(cos(theta1), sin(theta1)) * 0.75f; |
| 56 | } |
| 57 | auto vertexBuffer = getDevice()->createTypedBuffer<float2>( |
| 58 | kTriangleCount * 3, ResourceBindFlags::ShaderResource | ResourceBindFlags::Vertex, MemoryType::DeviceLocal, vertices |
| 59 | ); |
| 60 | |
| 61 | // Create vertex layout |
| 62 | auto bufferLayout = VertexBufferLayout::create(); |
| 63 | bufferLayout->addElement("POSITION", 0, ResourceFormat::RG32Float, 1, 0); |
| 64 | auto layout = VertexLayout::create(); |
| 65 | layout->addBufferLayout(0, bufferLayout); |
| 66 | |
| 67 | // Create VAO |
| 68 | mpVao = Vao::create(Vao::Topology::TriangleList, layout, {vertexBuffer}); |
| 69 | |
| 70 | // Create FBO |
| 71 | mpFbo = Fbo::create(getDevice()); |
| 72 | ref<Texture> tex = getDevice()->createTexture2DMS( |
| 73 | 128, 128, ResourceFormat::RGBA32Float, kSampleCount, 1, ResourceBindFlags::ShaderResource | ResourceBindFlags::RenderTarget |
| 74 | ); |
| 75 | mpFbo->attachColorTarget(tex, 0); |
| 76 | |
| 77 | mpResolvedTexture = getDevice()->createTexture2D(128, 128, ResourceFormat::RGBA32Float, 1, 1); |
| 78 | } |
| 79 | |
| 80 | void MultiSampling::onFrameRender(RenderContext* pRenderContext, const ref<Fbo>& pTargetFbo) |
| 81 | { |
nothing calls this directly
no test coverage detected