Ejemplo n.º 1
0
		bool paint::apply(const element* parent, render_context& ctx) const
		{
			switch(color_attrib_) {
			case ColorAttrib::NONE:
				// Nothing to do if there is no color.
				return false;
			case ColorAttrib::CURRENT_COLOR: {
				auto cc = ctx.get_current_color();
				ASSERT_LOG(cc != NULL, "Current color specified as color source, but there is no current color value.");
				cairo_set_source_rgb(ctx.cairo(), cc->r(), cc->g(), cc->b());
				return true;
			}
			case ColorAttrib::FUNC_IRI:
				ASSERT_LOG(false, "XXX: todo: lookup FUNC_IRI to get color value");
				return true;
			case ColorAttrib::ICC_COLOR:
				ASSERT_LOG(false, "XXX: todo: ICC_COLOR to get color value");
				return true;
			case ColorAttrib::INHERIT:
				// XXX: Nothing to do?
				return true;
			case ColorAttrib::VALUE:
				double opacity = ctx.opacity_top();
				cairo_set_source_rgba(ctx.cairo(), color_value_.r(), color_value_.g(), color_value_.b(), opacity);
				return true;
			}
			return false;
		}
Ejemplo n.º 2
0
			void handle_apply(render_context& ctx) override {
				if(std::abs(cx_) < DBL_EPSILON && std::abs(cy_) < DBL_EPSILON) {
					cairo_rotate(ctx.cairo(), angle_);
				} else {
					cairo_translate(ctx.cairo(), cx_, cy_);
					cairo_rotate(ctx.cairo(), angle_);
					cairo_translate(ctx.cairo(), -cx_, -cy_);
				}
			}
Ejemplo n.º 3
0
void
uniform_image_sampler_base::apply_value(const render_context& context, const program& p)
{
    const opengl::gl_core& glapi = context.opengl_api();
#if SCM_GL_CORE_USE_EXT_DIRECT_STATE_ACCESS
    if (_bound_unit >= 0) {
        glapi.glProgramUniform1i(p.program_id(), _location, _bound_unit);
    }
    else if (   glapi.extension_ARB_bindless_texture
             && _resident_handle != 0ull)
    {
        glapi.glProgramUniformHandleui64ARB(p.program_id(), _location, _resident_handle);
    }
#else
    if (_bound_unit >= 0) {
        glapi.glUniform1i(_location, _bound_unit);
    }
    else if (   glapi.extension_ARB_bindless_texture
             && _resident_handle != 0ull)
    {
        glapi.glUniformHandleui64ARB(_location, _resident_handle);
    }
#endif
    gl_assert(glapi, leaving uniform_1f::apply_value());

}
Ejemplo n.º 4
0
void
uniform_vec4ui::apply_value(const render_context& context, const program& p)
{
    const opengl::gl_core& glapi = context.opengl_api();
    glapi.glUniform4uiv(_location, _elements, (_value.front().data_array));//_value.data_array);
    gl_assert(glapi, leaving uniform_vec4ui::apply_value());
}
Ejemplo n.º 5
0
void
uniform_1ui::apply_value(const render_context& context, const program& p)
{
    const opengl::gl_core& glapi = context.opengl_api();
    glapi.glUniform1uiv(_location, _elements, &(_value.front()));//&_value);
    gl_assert(glapi, leaving uniform_1ui::apply_value());
}
Ejemplo n.º 6
0
void
transform_feedback::end(render_context& in_context)
{
    assert(state().ok());
    gl_assert(in_context.opengl_api(), entering transform_feedback:end());

    const opengl::gl_core& glapi = in_context.opengl_api();

    if (active()) {
        glapi.glEndTransformFeedback();
    }
    unbind(in_context);

    _active            = false;

    gl_assert(in_context.opengl_api(), leaving transform_feedback:end());
}
Ejemplo n.º 7
0
void
transform_feedback::begin(render_context& in_context, primitive_type in_topology_mode) 
{
    assert(state().ok());
    gl_assert(in_context.opengl_api(), entering transform_feedback:begin());

    const opengl::gl_core& glapi = in_context.opengl_api();

    bind(in_context);
    if (!active()) {
        glapi.glBeginTransformFeedback(util::gl_primitive_type(in_topology_mode));
    }
    gl_assert(in_context.opengl_api(), leaving transform_feedback:begin());

    _active            = true;
    _captured_topology = in_topology_mode;

    gl_assert(in_context.opengl_api(), leaving transform_feedback:begin());
}
Ejemplo n.º 8
0
Archivo: sync.cpp Proyecto: 4og/schism
void
sync::server_wait(const render_context& in_context,
                        scm::uint64     in_timeout) const
{
    const opengl::gl_core& glapi = in_context.opengl_api();
    assert(0 != object());

    glapi.glWaitSync(object(), 0, sync_timeout_ignored);

    gl_assert(glapi, leaving sync::server_wait());
}
Ejemplo n.º 9
0
void
transform_feedback::unbind(render_context& in_context) const
{
    assert(state().ok());

    if (SCM_GL_CORE_OPENGL_CORE_VERSION >= SCM_GL_CORE_OPENGL_CORE_VERSION_400) {
        assert(object_id() != 0);

        const opengl::gl_core& glapi = in_context.opengl_api();

        glapi.glBindTransformFeedback(object_target(), 0);

        gl_assert(glapi, transform_feedback::unbind() after glBindTransformFeedback());
    }
    else {
        unbind_stream_out_buffers(in_context);
    }

    gl_assert(in_context.opengl_api(), leaving transform_feedback:unbind());
}
Ejemplo n.º 10
0
Archivo: query.cpp Proyecto: 4og/schism
void
query::end(const render_context& in_context) const
{
    const opengl::gl_core& glapi = in_context.opengl_api();
    assert(0 != query_id());
    assert(0 != query_type());

    glapi.glEndQuery(query_type());

    gl_assert(glapi, leaving query::end());
}
Ejemplo n.º 11
0
void
transform_feedback::unbind_stream_out_buffers(render_context& in_context) const
{
    const opengl::gl_core& glapi = in_context.opengl_api();

    for (int bind_index = 0; bind_index < _stream_out_setup.used_streams(); ++bind_index) {
        const buffer_ptr& cur_buffer = _stream_out_setup[bind_index].first;

        if (cur_buffer) {
            cur_buffer->unbind_range(in_context, BIND_TRANSFORM_FEEDBACK_BUFFER, bind_index);
        }
        assert(cur_buffer->ok());
    }
}
Ejemplo n.º 12
0
std::string outside_section::render(
    render_context& ctx, const token& token)
{
    using flag = render_node::flag;
    switch (token.token_type()) {
    case token::type::section_open:
        ctx.set_state<in_section>(in_section::type::normal, token);
        break;
    case token::type::inverted_section_open:
        ctx.set_state<in_section>(in_section::type::inverted, token);
        break;
    case token::type::variable:
        return visit(render_node(ctx, flag::escape_html), ctx.get_node(token.name()));
    case token::type::unescaped_variable:
        return visit(render_node(ctx, flag::none), ctx.get_node(token.name()));
    case token::type::text:
        return token.raw();
    case token::type::partial:
        return ctx.render_partial(token.name(), token.partial_prefix());
    default:
        break;
    }
    return "";
}
Ejemplo n.º 13
0
Archivo: query.cpp Proyecto: 4og/schism
bool
query::available(const render_context& in_context) const
{
    const opengl::gl_core& glapi = in_context.opengl_api();
    assert(0 != query_id());
    assert(0 != query_type());

    int query_available = GL_FALSE;

    glapi.glGetQueryObjectiv(query_id(), GL_QUERY_RESULT_AVAILABLE, &query_available);
    
    gl_assert(glapi, leaving query::available());

    return query_available != GL_FALSE;
}
Ejemplo n.º 14
0
		void linear_gradient::handle_set_source(render_context& ctx) const
		{
			cairo_pattern_t* pattern = cairo_pattern_create_linear(
				x1_.value_in_specified_units(svg_length::SVG_LENGTHTYPE_NUMBER),
				y1_.value_in_specified_units(svg_length::SVG_LENGTHTYPE_NUMBER),
				x2_.value_in_specified_units(svg_length::SVG_LENGTHTYPE_NUMBER),
				y2_.value_in_specified_units(svg_length::SVG_LENGTHTYPE_NUMBER));
			apply_stops(ctx, pattern);
			auto status = cairo_pattern_status(pattern);
			ASSERT_LOG(status == CAIRO_STATUS_SUCCESS, "Linear Gradient pattern couldn't be created: " << cairo_status_to_string(status));

			pattern_.reset(pattern, [](cairo_pattern_t* p) { cairo_pattern_destroy(p); });
			apply_transforms(pattern);
			cairo_set_source(ctx.cairo(), pattern);
		}
Ejemplo n.º 15
0
Archivo: sync.cpp Proyecto: 4og/schism
sync_status
sync::status(const render_context& in_context) const
{
    const opengl::gl_core& glapi = in_context.opengl_api();
    assert(0 != object());

    int cur_status = 0;

    glapi.glGetSynciv(object(), GL_SYNC_STATUS, 1, 0, &cur_status);

    switch (cur_status) {
        case GL_SIGNALED:   return SYNC_SIGNALED;
        case GL_UNSIGNALED:
        default:            return SYNC_UNSIGNALED;
    }

    gl_assert(glapi, leaving sync::status());
}
Ejemplo n.º 16
0
Archivo: sync.cpp Proyecto: 4og/schism
sync_wait_result
sync::client_wait(const render_context& in_context,
                        scm::uint64     in_timeout,
                        bool            in_flush) const
{
    const opengl::gl_core& glapi = in_context.opengl_api();
    assert(0 != object());

    GLenum r = glapi.glClientWaitSync(object(), in_flush ? GL_SYNC_FLUSH_COMMANDS_BIT : 0, in_timeout);

    gl_assert(glapi, leaving sync::client_wait());

    switch (r) {
        case GL_ALREADY_SIGNALED:       return SYNC_WAIT_ALREADY_SIGNALED;
        case GL_CONDITION_SATISFIED:    return SYNC_WAIT_CONDITION_SATISFIED;
        case GL_TIMEOUT_EXPIRED:        return SYNC_WAIT_TIMEOUT_EXPIRED;
        case GL_WAIT_FAILED:
        default:                        return SYNC_WAIT_FAILED;
    }
}
Ejemplo n.º 17
0
			void handle_apply(render_context& ctx) override {
				cairo_transform(ctx.cairo(), &mat_);
			}
Ejemplo n.º 18
0
		void parse::render(render_context& ctx) const
		{
			cairo_set_source_rgb(ctx.cairo(), 0.0, 0.0, 0.0);
			cairo_set_line_cap(ctx.cairo(), CAIRO_LINE_CAP_BUTT);
			cairo_set_line_join(ctx.cairo(), CAIRO_LINE_JOIN_MITER);
			cairo_set_miter_limit(ctx.cairo(), 4.0);
			cairo_set_fill_rule(ctx.cairo(), CAIRO_FILL_RULE_WINDING);
			cairo_set_line_width(ctx.cairo(), 1.0);
			ctx.fill_color_push(paint_ptr(new paint(0,0,0,255)));
			ctx.stroke_color_push(paint_ptr(new paint()));
			ctx.opacity_push(1.0);
			ctx.letter_spacing_push(0);
			ctx.fa().push_font_size(12);

			for(auto p : svg_data_) {
				p->render(ctx);
			}

			ctx.letter_spacing_pop();
			ctx.opacity_pop();
			ctx.stroke_color_pop();
			ctx.fill_color_pop();
		}
Ejemplo n.º 19
0
			void handle_apply(render_context& ctx) override {
				cairo_scale(ctx.cairo(), sx_, sy_);
			}
Ejemplo n.º 20
0
			void handle_apply(render_context& ctx) override {
				cairo_translate(ctx.cairo(), x_, y_);
			}
Ejemplo n.º 21
0
void
rasterizer_state::apply(const render_context&   in_context,
                        const float             in_line_width,
                        const float             in_point_size,
                        const rasterizer_state& in_applied_state,
                        const float             in_applied_line_width,
                        const float             in_applied_point_size) const
{
    const opengl::gl_core& glapi = in_context.opengl_api();

    if (_descriptor._fill_mode != in_applied_state._descriptor._fill_mode) {
        glapi.glPolygonMode(GL_FRONT_AND_BACK, util::gl_fill_mode(_descriptor._fill_mode));
        gl_assert(glapi, rasterizer_state::apply() after glPolygonMode);
    }
    if (_descriptor._cull_mode != in_applied_state._descriptor._cull_mode) {
        if (_descriptor._cull_mode == CULL_NONE) {
            glapi.glDisable(GL_CULL_FACE);
        }
        else {
            glapi.glEnable(GL_CULL_FACE);
            glapi.glCullFace(util::gl_cull_mode(_descriptor._cull_mode));
        }
        gl_assert(glapi, rasterizer_state::apply() after glCullFace);
    }
    if (_descriptor._front_face != in_applied_state._descriptor._front_face) {
        glapi.glFrontFace(util::gl_polygon_orientation(_descriptor._front_face));
        gl_assert(glapi, rasterizer_state::apply() after glFrontFace);
    }
    if (_descriptor._multi_sample != in_applied_state._descriptor._multi_sample) {
        if (_descriptor._multi_sample) {
            glapi.glEnable(GL_MULTISAMPLE);
        }
        else {
            glapi.glDisable(GL_MULTISAMPLE);
        }
        gl_assert(glapi, rasterizer_state::apply() after GL_MULTISAMPLE);
    }

    if (SCM_GL_CORE_OPENGL_CORE_VERSION >= SCM_GL_CORE_OPENGL_CORE_VERSION_400) {
        if (   _descriptor._multi_sample
            && _descriptor._sample_shading)
        {
            glapi.glEnable(GL_SAMPLE_SHADING);
        }
        else {
            glapi.glDisable(GL_SAMPLE_SHADING);
        }
        gl_assert(glapi, rasterizer_state::apply() after GL_SAMPLE_SHADING);

        glapi.glMinSampleShading(math::clamp(_descriptor._min_sample_shading, 0.0f, 1.0f));
        gl_assert(glapi, rasterizer_state::apply() after glMinSampleShading);
    }

    if (_descriptor._scissor_test != in_applied_state._descriptor._scissor_test) {
        if (_descriptor._scissor_test) {
            glapi.glEnable(GL_SCISSOR_TEST);
        }
        else {
            glapi.glDisable(GL_SCISSOR_TEST);
        }
        gl_assert(glapi, rasterizer_state::apply() after GL_SCISSOR_TEST);
    }
    if (_descriptor._smooth_lines != in_applied_state._descriptor._smooth_lines) {
        if (_descriptor._smooth_lines) {
            glapi.glEnable(GL_LINE_SMOOTH);
        }
        else {
            glapi.glDisable(GL_LINE_SMOOTH);
        }
        gl_assert(glapi, rasterizer_state::apply() after GL_LINE_SMOOTH);
    }

    if (in_line_width != in_applied_line_width) { // i do no care about float compare at this point
        glapi.glLineWidth(math::max<float>(0.0f, in_line_width));
        gl_assert(glapi, rasterizer_state::apply() after glLineWidth);
    }
    if (in_point_size != in_applied_point_size) { // i do no care about float compare at this point
        glapi.glPointSize(math::max<float>(0.0f, in_point_size));
        gl_assert(glapi, rasterizer_state::apply() after glPointSize);
    }
    if (_descriptor._point_state != in_applied_state._descriptor._point_state) {
        if (_descriptor._point_state._shader_point_size) {
            glapi.glEnable(GL_PROGRAM_POINT_SIZE);
        }
        else {
            glapi.glDisable(GL_PROGRAM_POINT_SIZE);
        }
        glapi.glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, math::max<float>(0.0f, _descriptor._point_state._point_fade_threshold));
        glapi.glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, util::gl_origin_mode( _descriptor._point_state._point_origin_mode));
        gl_assert(glapi, rasterizer_state::apply() after glPointParameter);
    }

    gl_assert(glapi, leaving rasterizer_state::apply());
}