Exemplo n.º 1
0
Skybox::Skybox(GraphicsEngine* pGraphicsEngine)
: pGraphEngine(pGraphicsEngine)
{
	skydrawShader = GraphicsEngine::LoadShaderProgramFromFiles("Skybox_skydraw_v.glsl", "Skybox_skydraw_f.glsl");
	skydrawShader.Use();

	sh_ViewProjectionMatrix = gl::Uniform<glm::mat4>(skydrawShader, "viewProjectionMatrix");

	VAO.Bind();

	std::vector<GLfloat> vertexPosData = {
		-1.0f,-1.0f,-1.0f,
		+1.0f,-1.0f,-1.0f,
		-1.0f,+1.0f,-1.0f,
		+1.0f,+1.0f,-1.0f,
		-1.0f,-1.0f,+1.0f,
		+1.0f,-1.0f,+1.0f,
		-1.0f,+1.0f,+1.0f,
		+1.0f,+1.0f,+1.0f
	};

	vertexPositions.Bind(gl::Buffer::Target::Array);
	gl::Buffer::Data(gl::Buffer::Target::Array, vertexPosData);
	gl::VertexArrayAttrib vertAttr(skydrawShader, "vertexPos");
	vertAttr.Setup(3, gl::DataType::Float).Enable();

	std::vector<GLushort> indexData = {
		1, 3, 5, 7, 9,
		4, 6, 0, 2, 9,
		2, 6, 3, 7, 9,
		4, 0, 5, 1, 9,
		5, 7, 4, 6, 9,
		0, 2, 1, 3, 9
	};

	//At Drawnig...
	//gl.Enable(Capability::PrimitiveRestart);
	//gl.PrimitiveRestartIndex(9);

	indices.Bind(gl::Buffer::Target::ElementArray);
	gl::Buffer::Data(gl::Buffer::Target::ElementArray, indexData);

	///Fadeout shader
	fadeoutShader = GraphicsEngine::LoadShaderProgramFromFiles("Passthrough2_v.glsl", "Skybox_fadeout_f.glsl");
	fadeoutShader.Use();

	//gl::UniformSampler(fadeoutShader, "screenColor").Set(0);
	//gl::UniformSampler(fadeoutShader, "screenDepth").Set(1);
	gl::UniformSampler(fadeoutShader, "skyboxColor").Set(2);
	
	resultFB = Framebuffer(0, 0, Framebuffer::ATTACHMENT_COLOR | Framebuffer::ATTACHMENT_DEPTH);
	pGraphEngine->AddFramebufferForManagment(resultFB);
}
void GlRenderer::fill_rect( uint8_t color[3],
                            uint16_t top_left[2],
                            uint16_t dimensions[2])
{
    // Draw pending commands
    this->draw();

    // Fill rect ignores the draw area. Save the previous value
    // and reconfigure the scissor box to the fill rectangle
    // instead.
    uint16_t draw_area_top_left[2] = {
        this->config->draw_area_top_left[0],
        this->config->draw_area_top_left[1]
    };
    uint16_t draw_area_dimensions[2] = {
        this->config->draw_area_dimensions[0],
        this->config->draw_area_dimensions[1]
    };

    this->config->draw_area_top_left[0] = top_left[0];
    this->config->draw_area_top_left[1] = top_left[1];
    this->config->draw_area_dimensions[0] = dimensions[0];
    this->config->draw_area_dimensions[1] = dimensions[1];

    this->apply_scissor();

    /* This scope is intentional, just like in the Rust version */
    {
        // Bind the out framebuffer
        Framebuffer _fb = Framebuffer(this->fb_out);

        glClearColor(   (float) color[0] / 255.0,
                        (float) color[1] / 255.0,
                        (float) color[2] / 255.0,
                        // XXX Not entirely sure what happens to
                        // the mask bit in fill_rect commands
                        0.0);
        glClear(GL_COLOR_BUFFER_BIT);
    }

    // Reconfigure the draw area
    this->config->draw_area_top_left[0]     = draw_area_top_left[0];
    this->config->draw_area_top_left[1]     = draw_area_top_left[1];
    this->config->draw_area_dimensions[0]   = draw_area_dimensions[0];
    this->config->draw_area_dimensions[1]   = draw_area_dimensions[1];

    this->apply_scissor();
}
Exemplo n.º 3
0
void MainWindow::create_swapchain() {
	// needed because the swapchain immediatly destroys it images
	device()->graphic_queue().wait();

	if(_swapchain) {
		_swapchain->reset();
	} else {
		_swapchain = std::make_unique<Swapchain>(device(), static_cast<Window*>(this));
	}

	_framebuffers = std::make_unique<Framebuffer[]>(_swapchain->image_count());
	for(usize i = 0; i != _swapchain->image_count(); ++i) {
		ColorAttachmentView color(_swapchain->images()[i]);
		_framebuffers[i] = Framebuffer(device(), {color});
	}
}
void GlRenderer::upload_vram_window(uint16_t top_left[2],
                                    uint16_t dimensions[2],
                                    uint16_t pixel_buffer[VRAM_PIXELS])
{
    this->fb_texture->set_sub_image_window( top_left,
                                            dimensions,
                                            (size_t) VRAM_WIDTH_PIXELS,
                                            GL_RGBA,
                                            GL_UNSIGNED_SHORT_1_5_5_5_REV,
                                            pixel_buffer);

    this->image_load_buffer->clear();

    uint16_t x_start    = top_left[0];
    uint16_t x_end      = x_start + dimensions[0];
    uint16_t y_start    = top_left[1];
    uint16_t y_end      = y_start + dimensions[1];

    const size_t slice_len = 4;
    ImageLoadVertex slice[slice_len] =
        {
            {   {x_start,   y_start }   },
            {   {x_end,     y_start }   },
            {   {x_start,   y_end   }   },
            {   {x_end,     y_end   }   }
        };
    this->image_load_buffer->push_slice(slice, slice_len);

    this->image_load_buffer->program->uniform1i("fb_texture", 0);

    glDisable(GL_SCISSOR_TEST);
    glDisable(GL_BLEND);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // Bind the output framebuffer
    Framebuffer _fb = Framebuffer(this->fb_out);

    this->image_load_buffer->draw(GL_TRIANGLE_STRIP);
    glPolygonMode(GL_FRONT_AND_BACK, this->command_polygon_mode);
    glEnable(GL_SCISSOR_TEST);

    get_error();
}
void GlRenderer::draw()
{
    if (this->command_buffer->empty() && this->semi_transparent_vertices.empty())
        return; // Nothing to be done

    int16_t x = this->config->draw_offset[0];
    int16_t y = this->config->draw_offset[1];

    this->command_buffer->program->uniform2i("offset", (GLint)x, (GLint)y);

    // We use texture unit 0
    this->command_buffer->program->uniform1i("fb_texture", 0);
    this->command_buffer->program->uniform1ui("texture_flt", this->filter_type);

    // Set the texture window parameters
    this->command_buffer->program->uniform1ui("tex_x_mask", tex_x_mask);
    this->command_buffer->program->uniform1ui("tex_x_or", tex_x_or);
    this->command_buffer->program->uniform1ui("tex_y_mask", tex_y_mask);
    this->command_buffer->program->uniform1ui("tex_y_or", tex_y_or);

    // Bind the out framebuffer
    Framebuffer _fb = Framebuffer(this->fb_out, this->fb_out_depth);

    glClear(GL_DEPTH_BUFFER_BIT);

    // First we draw the opaque vertices
    if (!this->command_buffer->empty()) {
        glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
        glDisable(GL_BLEND);

        this->command_buffer->program->uniform1ui("draw_semi_transparent", 0);
        this->command_buffer->draw(this->command_draw_mode);
        this->command_buffer->clear();
    }

    // Then the semi-transparent vertices
    if (!this->semi_transparent_vertices.empty()) {

        // Emulation of the various PSX blending mode using a
        // combination of constant alpha/color (to emulate
        // constant 1/4 and 1/2 factors) and blending equation.
        GLenum blend_func = GL_FUNC_ADD;
        GLenum blend_src = GL_CONSTANT_ALPHA;
        GLenum blend_dst = GL_CONSTANT_ALPHA;

        switch (this->semi_transparency_mode) {
        /* 0.5xB + 0.5 x F */
        case SemiTransparencyMode_Average:
            blend_func = GL_FUNC_ADD;
            // Set to 0.5 with glBlendColor
            blend_src = GL_CONSTANT_ALPHA;
            blend_dst = GL_CONSTANT_ALPHA;
            break;
        /* 1.0xB + 1.0 x F */
        case SemiTransparencyMode_Add:
            blend_func = GL_FUNC_ADD;
            blend_src = GL_ONE;
            blend_dst = GL_ONE;
            break;
        /* 1.0xB - 1.0 x F */
        case SemiTransparencyMode_SubtractSource:
            blend_func = GL_FUNC_REVERSE_SUBTRACT;
            blend_src = GL_ONE;
            blend_dst = GL_ONE;
            break;
        case SemiTransparencyMode_AddQuarterSource:
            blend_func = GL_FUNC_ADD;
            blend_src = GL_CONSTANT_COLOR;
            blend_dst = GL_ONE;
            break;
        }

        glBlendFuncSeparate(blend_src, blend_dst, GL_ONE, GL_ZERO);
        glBlendEquationSeparate(blend_func, GL_FUNC_ADD);
        glEnable(GL_BLEND);

        this->command_buffer->program->uniform1ui("draw_semi_transparent", 1);

        this->command_buffer->push_slice(&this->semi_transparent_vertices[0], this->semi_transparent_vertices.size());

        this->command_buffer->draw(this->command_draw_mode);

        this->command_buffer->clear();

        this->semi_transparent_vertices.clear();
    }

    this->primitive_ordering = 0;
}
Exemplo n.º 6
0
			static Framebuffer framebufferDefault() noexcept
				{return Framebuffer(0);}