# class hiro::draw::GeometryRenderer

## Overview

Renderer used for rendering geometry. More…

    #include <GeometryRenderer.h>

    class GeometryRenderer: public hiro::draw::ElementRenderer {
    public:
        // construction

        GeometryRenderer();
        GeometryRenderer(hiro::draw::GeometryName geometry_name);
        GeometryRenderer(const glw::PArrayObject& vao);
        GeometryRenderer(const hiro::draw::GeometryRenderer& source);
        GeometryRenderer(hiro::draw::GeometryRenderer&&);
        virtual ~GeometryRenderer();

        // methods

        GeometryRenderer& operator=(const hiro::draw::GeometryRenderer& source);
        GeometryRenderer& operator=(hiro::draw::GeometryRenderer&&);
        void Set(hiro::draw::GeometryName geometry_name);
        void Set(glw::PArrayObject& vao);
        void SetInstancingEnabled(bool instancing_enabled);
        void SetInstancingTransforms(const std::vector<glm::mat4>& transformations);
        void SetPreInstancingTransform(const glm::mat4& transformation);
        virtual bool IsCompatibileWithStyle(const hiro::draw::Style* style);

    protected:
        // methods

        virtual void OnRenderFaces();
        virtual void OnRenderPoints();
        virtual void OnRenderNormals();
        virtual void OnRenderSimple();
        FacesStyle::NormalSource GetValidNormalSource(const GeometryStyle& style);
    };

### Inherited Members

    public:
        // methods

        virtual bool IsCompatibileWithStyle(const hiro::draw::Style* style) = 0;
        ElementRenderer& operator=(const hiro::draw::ElementRenderer& source);
        ElementRenderer& operator=(hiro::draw::ElementRenderer&&);

    protected:
        // methods

        virtual void LoadRequiredShaderPrograms(glw::ProgramList* programs);
        virtual void Render(const std::string& program);
        virtual void OnRenderSimple();
        virtual void Render2D(const std::string& program);
        virtual void OnRenderSimple2D();
        virtual void FillTextRenderer(hiro::draw::TextRenderer* t_renderer);

        template <typename StyleType>
        const StyleType* GetStyle() const;

        const Scene* GetScene() const;
        virtual void LoadRequiredShaderPrograms(glw::ProgramList* programs);
        virtual void Render(const std::string& program);
        virtual void OnRenderPoints();
        virtual void OnRenderFaces();
        virtual void OnRenderNormals();
        void RenderPoints(const hiro::draw::PointsStyle& style, std::function<void(void)> render_func);
        void RenderFaces(const hiro::draw::FacesStyle& style, std::function<void(void)> render_func);
        void RenderNormals(const hiro::draw::NormalsStyle& style, std::function<void(void)> render_func);

## Detailed Documentation

Renderer used for rendering geometry.

Geometry can be set to this renderer by two ways. Eider by specifying geometry name, or by specifying your own geometry via vertex buffer.

Right | Center | Left
--- | --- | ---
10 | 10 | 10
1000 | 1000 | 1000

When specifying your own geometry, vertices should have following attributes:

Location | Type | Content | Required When:
--- | --- | --- | ---
0 | vec3 | position | always
1 | vec3 | normal | normal source is NormalSource::point_normals
2 | vec2 | texture coordinate | using any type of texture
3 | vec3 | custom color | color source is ColorSource::custom_colors
4 | vec4 | tangent | normal source is NormalSource::normal_texture

### Construction

    GeometryRenderer()

Creates empty geometry renderer without any geometry.

    GeometryRenderer(hiro::draw::GeometryName geometry_name)

Creates a renderer with the geometry.

    GeometryRenderer(const glw::PArrayObject& vao)

Creates a renderer with the custom geometry.

### Methods

    void Set(hiro::draw::GeometryName geometry_name)

Replaces the geometry in the renderer.

    void Set(glw::PArrayObject& vao)

Replaces the geometry in the renderer.

    void SetInstancingEnabled(bool instancing_enabled)

Changes rendering mode of instanced rendering.

    void SetInstancingTransforms(const std::vector<glm::mat4>& transformations)

Set transformations of individual instances. Size of the array denotes number of instances.

    void SetPreInstancingTransform(const glm::mat4& transformation)

Set pre-instancing transformation that is applied before instancing.

    virtual bool IsCompatibileWithStyle(const hiro::draw::Style* style)

Test whether specified style is compatible with the object.

    virtual void OnRenderFaces()

Defines behavior on face rendering.

    virtual void OnRenderPoints()

Defines behavior on point rendering.

    virtual void OnRenderNormals()

Defines behavior on normal rendering.

    virtual void OnRenderSimple()

Defines behavior on simple rendering.

    FacesStyle::NormalSource GetValidNormalSource(const GeometryStyle& style)

Obtains normal source, that is valid for current geometry and style combination.