Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/display_driver.h
| Show All 9 Lines | |||||
| #include "RNA_blender_cpp.h" | #include "RNA_blender_cpp.h" | ||||
| #include "session/display_driver.h" | #include "session/display_driver.h" | ||||
| #include "util/thread.h" | #include "util/thread.h" | ||||
| #include "util/unique_ptr.h" | #include "util/unique_ptr.h" | ||||
| #include "util/vector.h" | #include "util/vector.h" | ||||
| typedef struct GPUContext GPUContext; | |||||
| typedef struct GPUFence GPUFence; | |||||
| typedef struct GPUShader GPUShader; | |||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| /* Base class of shader used for display driver rendering. */ | /* Base class of shader used for display driver rendering. */ | ||||
| class BlenderDisplayShader { | class BlenderDisplayShader { | ||||
| public: | public: | ||||
| static constexpr const char *position_attribute_name = "pos"; | static constexpr const char *position_attribute_name = "pos"; | ||||
| static constexpr const char *tex_coord_attribute_name = "texCoord"; | static constexpr const char *tex_coord_attribute_name = "texCoord"; | ||||
| /* Create shader implementation suitable for the given render engine and scene configuration. */ | /* Create shader implementation suitable for the given render engine and scene configuration. */ | ||||
| static unique_ptr<BlenderDisplayShader> create(BL::RenderEngine &b_engine, BL::Scene &b_scene); | static unique_ptr<BlenderDisplayShader> create(BL::RenderEngine &b_engine, BL::Scene &b_scene); | ||||
| BlenderDisplayShader() = default; | BlenderDisplayShader() = default; | ||||
| virtual ~BlenderDisplayShader() = default; | virtual ~BlenderDisplayShader() = default; | ||||
| virtual void bind(int width, int height) = 0; | virtual GPUShader *bind(int width, int height) = 0; | ||||
| virtual void unbind() = 0; | virtual void unbind() = 0; | ||||
| /* Get attribute location for position and texture coordinate respectively. | /* Get attribute location for position and texture coordinate respectively. | ||||
| * NOTE: The shader needs to be bound to have access to those. */ | * NOTE: The shader needs to be bound to have access to those. */ | ||||
| virtual int get_position_attrib_location(); | virtual int get_position_attrib_location(); | ||||
| virtual int get_tex_coord_attrib_location(); | virtual int get_tex_coord_attrib_location(); | ||||
| protected: | protected: | ||||
| /* Get program of this display shader. | /* Get program of this display shader. | ||||
| * NOTE: The shader needs to be bound to have access to this. */ | * NOTE: The shader needs to be bound to have access to this. */ | ||||
| virtual uint get_shader_program() = 0; | virtual GPUShader *get_shader_program() = 0; | ||||
| /* Cached values of various OpenGL resources. */ | /* Cached values of various OpenGL resources. */ | ||||
| int position_attribute_location_ = -1; | int position_attribute_location_ = -1; | ||||
| int tex_coord_attribute_location_ = -1; | int tex_coord_attribute_location_ = -1; | ||||
| }; | }; | ||||
| /* Implementation of display rendering shader used in the case when render engine does not support | /* Implementation of display rendering shader used in the case when render engine does not support | ||||
| * display space shader. */ | * display space shader. */ | ||||
| class BlenderFallbackDisplayShader : public BlenderDisplayShader { | class BlenderFallbackDisplayShader : public BlenderDisplayShader { | ||||
| public: | public: | ||||
| virtual void bind(int width, int height) override; | virtual GPUShader *bind(int width, int height) override; | ||||
| virtual void unbind() override; | virtual void unbind() override; | ||||
| protected: | protected: | ||||
| virtual uint get_shader_program() override; | virtual GPUShader *get_shader_program() override; | ||||
| void create_shader_if_needed(); | void create_shader_if_needed(); | ||||
| void destroy_shader(); | void destroy_shader(); | ||||
| uint shader_program_ = 0; | GPUShader *shader_program_ = 0; | ||||
| int image_texture_location_ = -1; | int image_texture_location_ = -1; | ||||
| int fullscreen_location_ = -1; | int fullscreen_location_ = -1; | ||||
| /* Shader compilation attempted. Which means, that if the shader program is 0 then compilation or | /* Shader compilation attempted. Which means, that if the shader program is 0 then compilation or | ||||
| * linking has failed. Do not attempt to re-compile the shader. */ | * linking has failed. Do not attempt to re-compile the shader. */ | ||||
| bool shader_compile_attempted_ = false; | bool shader_compile_attempted_ = false; | ||||
| }; | }; | ||||
| class BlenderDisplaySpaceShader : public BlenderDisplayShader { | class BlenderDisplaySpaceShader : public BlenderDisplayShader { | ||||
| public: | public: | ||||
| BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene); | BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene); | ||||
| virtual void bind(int width, int height) override; | virtual GPUShader *bind(int width, int height) override; | ||||
| virtual void unbind() override; | virtual void unbind() override; | ||||
| protected: | protected: | ||||
| virtual uint get_shader_program() override; | virtual GPUShader *get_shader_program() override; | ||||
| BL::RenderEngine b_engine_; | BL::RenderEngine b_engine_; | ||||
| BL::Scene &b_scene_; | BL::Scene &b_scene_; | ||||
| /* Cached values of various OpenGL resources. */ | /* Cached values of various OpenGL resources. */ | ||||
| uint shader_program_ = 0; | GPUShader *shader_program_ = nullptr; | ||||
| }; | }; | ||||
| /* Display driver implementation which is specific for Blender viewport integration. */ | /* Display driver implementation which is specific for Blender viewport integration. */ | ||||
| class BlenderDisplayDriver : public DisplayDriver { | class BlenderDisplayDriver : public DisplayDriver { | ||||
| public: | public: | ||||
| BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background); | BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background); | ||||
| ~BlenderDisplayDriver(); | ~BlenderDisplayDriver(); | ||||
| Show All 22 Lines | protected: | ||||
| /* Helper function which allocates new GPU context. */ | /* Helper function which allocates new GPU context. */ | ||||
| void gpu_context_create(); | void gpu_context_create(); | ||||
| bool gpu_context_enable(); | bool gpu_context_enable(); | ||||
| void gpu_context_disable(); | void gpu_context_disable(); | ||||
| void gpu_context_destroy(); | void gpu_context_destroy(); | ||||
| void gpu_context_lock(); | void gpu_context_lock(); | ||||
| void gpu_context_unlock(); | void gpu_context_unlock(); | ||||
| /* Create GPU resources used by the dispaly driver. */ | |||||
| bool gpu_resources_create(); | |||||
| /* Destroy all GPU resources which are being used by this object. */ | /* Destroy all GPU resources which are being used by this object. */ | ||||
| void gpu_resources_destroy(); | void gpu_resources_destroy(); | ||||
| BL::RenderEngine b_engine_; | BL::RenderEngine b_engine_; | ||||
| bool background_; | bool background_; | ||||
| /* Content of the display is to be filled with zeroes. */ | /* Content of the display is to be filled with zeroes. */ | ||||
| std::atomic<bool> need_clear_ = true; | std::atomic<bool> need_clear_ = true; | ||||
| unique_ptr<BlenderDisplayShader> display_shader_; | unique_ptr<BlenderDisplayShader> display_shader_; | ||||
| /* Opaque storage for an internal state and data for tiles. */ | /* Opaque storage for an internal state and data for tiles. */ | ||||
| struct Tiles; | struct Tiles; | ||||
| unique_ptr<Tiles> tiles_; | unique_ptr<Tiles> tiles_; | ||||
| void *gl_render_sync_ = nullptr; | GPUFence *gpu_render_sync_ = nullptr; | ||||
| void *gl_upload_sync_ = nullptr; | GPUFence *gpu_upload_sync_ = nullptr; | ||||
| float2 zoom_ = make_float2(1.0f, 1.0f); | float2 zoom_ = make_float2(1.0f, 1.0f); | ||||
| }; | }; | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||