sculpto
material_single_color.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file material_phong.h
3 * \brief Mesh material for bling-phone lighting model class deinition module.
4 *
5 * \author Sabitov Kirill
6 * \date 05 July 2022
7 *********************************************************************/
8
9#pragma once
10
11#include "material.h"
15
16namespace scl
17{
20 {
21 private:
23 struct buffer_data
24 {
25 vec3 Color {};
26 u32 IsTexture {};
27 } Data {};
28
29 shared<constant_buffer> DataBuffer {};
30 shared<texture_2d> Texture {};
31
32 public:
34 const vec3 &GetColor() const { return Data.Color; }
36 u32 GetIsTexture() const { return Data.IsTexture; }
37
38 const shared<texture_2d> &GetTexture() const { return Texture; }
39
41 void SetColor(const vec3 &Color) {
42 if (Texture)
43 {
44 Texture->Free();
45 Texture = nullptr;
46 }
47 Data.IsTexture = false;
48 Data.Color = Color;
49 DataBuffer->Update(&Data, sizeof(Data));
50 }
53 if (!Texture) return;
54
55 if (this->Texture) this->Texture->Free();
56 this->Texture = Texture;
57 if (!Data.IsTexture)
58 {
59 Data.IsTexture = true;
60 DataBuffer->Update(&Data, sizeof(Data));
61 }
62 }
63
66
68 material_single_color(const material_single_color &MaterialData) = default;
69
70 /*!*
71 * Material for blin-phong lighting model class contructor.
72 *
73 * \param Color - material color.
74 */
76 material(render_bridge::GetSingleColorMaterialShader())
77 {
78 Data.Color = Color;
79 DataBuffer = constant_buffer::Create(&Data, sizeof(buffer_data));
80 }
81
82 /*!*
83 * Material for blin-phong lighting model class contructor.
84 *
85 * \param Texture - material texture.
86 */
88 material(render_bridge::GetSingleColorMaterialShader())
89 {
90 this->Texture = Texture;
91 Data.IsTexture = true;
92 DataBuffer = constant_buffer::Create(&Data, sizeof(buffer_data));
93 }
94
95 /*!*
96 * Bind material to current render stage function.
97 *
98 * \param None.
99 * \return None.
100 */
101 void Bind() const override
102 {
103 if (Shader) Shader->Bind();
104 if (DataBuffer) DataBuffer->Bind(render_context::BINDING_POINT_MATERIAL_DATA);
105 if (Texture && Data.IsTexture) Texture->Bind(render_context::TEXTURE_SLOT_MATERIAL_DIFFUSE);
106 }
107
108 /*!*
109 * Unbind material from current render stage function.
110 *
111 * \param None.
112 * \return None.
113 */
114 void Unbind() const override
115 {
116 if (Shader) Shader->Unbind();
117 if (DataBuffer) DataBuffer->Unbind();
118 if (Texture && Data.IsTexture) Texture->Unbind();
119 }
120
121 /*!*
122 * Material for blin-phong lighting model class contructor.
123 *
124 * \param Color - material color.
125 */
127 {
128 return CreateShared<material_single_color>(Color);
129 }
130
131 /*!*
132 * Material for blin-phong lighting model class contructor.
133 *
134 * \param Texture - material texture.
135 */
137 {
138 return CreateShared<material_single_color>(Texture);
139 }
140 };
141}
142
Buffer interfaces implementation module.
static shared< constant_buffer > Create(u32 Size)
Definition: buffer.cpp:14
material_single_color(shared< texture_2d > Texture)
static shared< material_single_color > Create(shared< texture_2d > Texture)
material_single_color(const material_single_color &MaterialData)=default
const shared< texture_2d > & GetTexture() const
static shared< material_single_color > Create(const vec3 &Color)
material_single_color(const vec3 &Color)
void SetColor(const vec3 &Color)
void SetTexture(shared< texture_2d > Texture)
shared< shader_program > Shader
Definition: material.h:20
static const int BINDING_POINT_MATERIAL_DATA
static const int TEXTURE_SLOT_MATERIAL_DIFFUSE
Mesh material class deinition module.
Definition: base.h:33
std::shared_ptr< T > shared
Definition: smart_ptr.h:15
uint32_t u32
Definition: math_common.h:21
Render bridge class implementation module. Static class for making calls to low-level render api,...
Texture interface definition module.