Commit 754d79c4 authored by Justine Martin's avatar Justine Martin 💖
Browse files

refactor : Sépare les classes RenderObject et RenderObjectPart de

GlApplication
parent c7d1b170
Loading
Loading
Loading
Loading
+1 −1
Changes for CMakeLists.txt: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -17,5 +17,5 @@ include_directories("glitter/ext/tinyobjloader"
		"glitter/ext/glm"
		${OPENGL_INCLUDE_DIR})

add_executable(GLE-test src/main.cpp src/GlApplication.cpp)
add_executable(GLE-test src/main.cpp src/RenderObject.cpp src/RenderObjectPart.cpp src/GlApplication.cpp)
target_link_libraries(GLE-test utils ${GLFW3_LIBRARIES} ${GLEW_LIBRARIES})
+17 −79
Changes for include/GlApplication.hpp: 17 added lines, 79 removed lines.
Original line number Diff line number Diff line
#ifndef __PA5_APPLICATION_H__
#define __PA5_APPLICATION_H__
#pragma once

#include <Application.hpp>
#include <glApi.hpp>
#include <ObjLoader.hpp>
#include <utils.hpp>

#include <GLFW/glfw3.h>
#include <glm/ext.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <stb_image.h>

#include <iostream>
#include <memory>
struct GLFWwindow;
#include "Application.hpp"
#include "glApi.hpp"

// forward declarations
struct SimpleMaterial;
#include "RenderObject.hpp"
#include "RenderObjectPart.hpp"

class RenderObject;

class GlApplication : public Application {
    public:
@@ -25,76 +35,6 @@ private:
        void continuousKey();
        void computeView(bool reset = false);

private:
  class RenderObjectPart {
  public:
    RenderObjectPart() = delete;
    RenderObjectPart(const RenderObjectPart &) = delete;
    RenderObjectPart(RenderObjectPart &&) = default;
    RenderObjectPart(std::shared_ptr<VAO> vao, std::shared_ptr<Program> program, std::shared_ptr<Texture> texture, std::shared_ptr<Texture> ntexture, std::shared_ptr<Texture> stexture);
    void draw(Sampler * colormap, Sampler * normalmap, Sampler * specularmap);
    void update(const glm::mat4 & proj, const glm::mat4 & view, const glm::mat4 & mw, bool displayNormals);

  private:
    std::shared_ptr<VAO> m_vao;
    std::shared_ptr<Program> m_program;
    std::shared_ptr<Texture> m_diffuseTexture;
    std::shared_ptr<Texture> m_normalTexture;
    std::shared_ptr<Texture> m_specularTexture;
  };

  /**
   * @brief The RenderObject class
   *
   * A RenderObject is split into parts, sharing the same geometry (VBOs), but referencing different primitive subsets (IBO) and materials (textures, ...).
   */
  class RenderObject {
  public:
    RenderObject() = delete;
    RenderObject(const RenderObject &) = delete;

    static std::unique_ptr<RenderObject> createCheckerBoardPlaneInstance(const glm::mat4 & modelWorld);
    /**
     * @brief creates an instance from a wavefront file and modelWorld matrix
     * @param objname the filename of the wavefront file
     * @param modelWorld the matrix transform between the object (a.k.a model) space and the world space
     * @return the created RenderObject as a smart pointer
     */
    static std::unique_ptr<RenderObject> createWavefrontInstance(const std::string & objname, const glm::mat4 & modelWorld);

    /**
     * @brief Sets all uniform variables related to material and lighting
     * @param program
     * @param material
     *
     * @note Besides the material, three directional lights (defined in world space) are passed to the GLSL program.
     */
    void setProgramMaterial(std::shared_ptr<Program> & program, const SimpleMaterial & material) const;

    /**
     * @brief Draw this RenderObject
     */
    void draw();

    /**
     * @brief update the program MVP uniform variable
     * @param proj the projection matrix
     * @param view the worldView matrix
     */
    void update(const glm::mat4 & proj, const glm::mat4 & view);

  private:
    RenderObject(const glm::mat4 & modelWorld);
    void loadWavefront(const std::string & objname);

  private:
    glm::mat4 m_mw; ///< modelWorld matrix
    std::vector<RenderObjectPart> m_parts;
    std::unique_ptr<Sampler> m_diffusemap;
    std::unique_ptr<Sampler> m_normalmap;
    std::unique_ptr<Sampler> m_specularmap;
  };

    private:
        std::vector<std::unique_ptr<RenderObject>> m_objects; ///< render objects
        glm::mat4 m_proj;                                     ///< Projection matrix
@@ -104,5 +44,3 @@ private:
        float m_currentTime;                                  ///< elapsed time since first frame
        float m_deltaTime;                                    ///< elapsed time since last frame
};

#endif // !defined(__PA5_APPLICATION_H__)
+64 −0
Changes for include/RenderObject.hpp: 64 added lines, 0 removed lines.
Original line number Diff line number Diff line
#pragma once

#include <glApi.hpp>
#include <ObjLoader.hpp>
#include <utils.hpp>

#include <stb_image.h>

#include <memory>

#include "GlApplication.hpp"
#include "RenderObjectPart.hpp"

/**
 * @brief The RenderObject class
 *
 * A RenderObject is split into parts, sharing the same geometry (VBOs), but referencing different primitive subsets (IBO) and materials (textures, ...).
 */
class RenderObject {
	public:
		RenderObject() = delete;
		RenderObject(const RenderObject &) = delete;

		static std::unique_ptr<RenderObject> createCheckerBoardPlaneInstance(const glm::mat4 & modelWorld);
		/**
		 * @brief creates an instance from a wavefront file and modelWorld matrix
		 * @param objname the filename of the wavefront file
		 * @param modelWorld the matrix transform between the object (a.k.a model) space and the world space
		 * @return the created RenderObject as a smart pointer
		 */
		static std::unique_ptr<RenderObject> createWavefrontInstance(const std::string & objname, const glm::mat4 & modelWorld);

		/**
		 * @brief Sets all uniform variables related to material and lighting
		 * @param program
		 * @param material
		 *
		 * @note Besides the material, three directional lights (defined in world space) are passed to the GLSL program.
		 */
		void setProgramMaterial(std::shared_ptr<Program> & program, const SimpleMaterial & material) const;

		/**
		 * @brief Draw this RenderObject
		 */
		void draw();

		/**
		 * @brief update the program MVP uniform variable
		 * @param proj the projection matrix
		 * @param view the worldView matrix
		 */
		void update(const glm::mat4 & proj, const glm::mat4 & view);

	private:
		RenderObject(const glm::mat4 & modelWorld);
		void loadWavefront(const std::string & objname);

	private:
		glm::mat4 m_mw; ///< modelWorld matrix
		std::vector<RenderObjectPart> m_parts;
		std::unique_ptr<Sampler> m_diffusemap;
		std::unique_ptr<Sampler> m_normalmap;
		std::unique_ptr<Sampler> m_specularmap;
};
+22 −0
Changes for include/RenderObjectPart.hpp: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
#pragma once

#include <glApi.hpp>

#include <memory>

class RenderObjectPart {
            public:
                RenderObjectPart() = delete;
                RenderObjectPart(const RenderObjectPart &) = delete;
                RenderObjectPart(RenderObjectPart &&) = default;
                RenderObjectPart(std::shared_ptr<VAO> vao, std::shared_ptr<Program> program, std::shared_ptr<Texture> texture, std::shared_ptr<Texture> ntexture, std::shared_ptr<Texture> stexture);
                void draw(Sampler * colormap, Sampler * normalmap, Sampler * specularmap);
                void update(const glm::mat4 & proj, const glm::mat4 & view, const glm::mat4 & mw, bool displayNormals);

            private:
                std::shared_ptr<VAO> m_vao;
                std::shared_ptr<Program> m_program;
                std::shared_ptr<Texture> m_diffuseTexture;
                std::shared_ptr<Texture> m_normalTexture;
                std::shared_ptr<Texture> m_specularTexture;
        };
+752 KiB

File added.

No diff preview for this file type.

Loading