From 29a7478e0af36bc83bbaf5f7c8350937f9b772ea Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 4 Jan 2024 18:39:16 +0100 Subject: [PATCH] Material cleanups. --- sfw/render_core/font_material.h | 2 ++ sfw/render_core/texture_material.h | 12 ++++++------ sfw/render_core/texture_material_2d.h | 2 ++ sfw/render_core/transparent_texture_material.h | 10 +++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sfw/render_core/font_material.h b/sfw/render_core/font_material.h index 52dd1c9..57982fa 100644 --- a/sfw/render_core/font_material.h +++ b/sfw/render_core/font_material.h @@ -7,6 +7,8 @@ #include "render_core/render_state.h" class FontMaterial : public Material { + SFW_OBJECT(FontMaterial, Material); + public: int get_material_id() { return 11; diff --git a/sfw/render_core/texture_material.h b/sfw/render_core/texture_material.h index 9fa05e8..3cc11cb 100644 --- a/sfw/render_core/texture_material.h +++ b/sfw/render_core/texture_material.h @@ -7,6 +7,8 @@ #include "render_core/render_state.h" class TextureMaterial : public Material { + SFW_OBJECT(TextureMaterial, Material); + public: int get_material_id() { return 3; @@ -17,7 +19,7 @@ public: set_uniform(camera_matrix_location, RenderState::camera_transform_3d); set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d); - if (texture) { + if (texture.is_valid()) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture()); glUniform1i(texture_location, 0); @@ -26,7 +28,7 @@ public: void setup_uniforms() { projection_matrix_location = get_uniform("u_proj_matrix"); - camera_matrix_location = get_uniform("u_camera_matrix"); + camera_matrix_location = get_uniform("u_camera_matrix"); model_view_matrix_location = get_uniform("u_model_view_matrix"); texture_location = get_uniform("u_texture"); @@ -76,14 +78,12 @@ public: return fragment_shader_source; } - TextureMaterial() : - Material() { + TextureMaterial() { projection_matrix_location = 0; camera_matrix_location = 0; model_view_matrix_location = 0; texture_location = 0; - texture = NULL; } GLint projection_matrix_location; @@ -92,7 +92,7 @@ public: GLint texture_location; - Texture *texture; + Ref texture; }; #endif // COLORED_MATERIAL_H diff --git a/sfw/render_core/texture_material_2d.h b/sfw/render_core/texture_material_2d.h index 17cf9fc..4c8d1cb 100644 --- a/sfw/render_core/texture_material_2d.h +++ b/sfw/render_core/texture_material_2d.h @@ -7,6 +7,8 @@ #include "render_core/render_state.h" class TextureMaterial2D : public Material { + SFW_OBJECT(TextureMaterial2D, Material); + public: int get_material_id() { return 10; diff --git a/sfw/render_core/transparent_texture_material.h b/sfw/render_core/transparent_texture_material.h index 425eaa3..710ebb8 100644 --- a/sfw/render_core/transparent_texture_material.h +++ b/sfw/render_core/transparent_texture_material.h @@ -7,6 +7,8 @@ #include "render_core/render_state.h" class TransparentTextureMaterial : public Material { + SFW_OBJECT(TransparentTextureMaterial, Material); + public: int get_material_id() { return 4; @@ -16,7 +18,7 @@ public: set_uniform(projection_matrix_location, RenderState::projection_matrix_3d); set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d); - if (texture) { + if (texture.is_valid()) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture()); glUniform1i(texture_location, 0); @@ -79,10 +81,8 @@ public: return fragment_shader_source; } - TransparentTextureMaterial() : - Material() { + TransparentTextureMaterial() { texture_location = 0; - texture = NULL; } GLint projection_matrix_location; @@ -90,7 +90,7 @@ public: GLint texture_location; - Texture *texture; + Ref texture; }; #endif // COLORED_MATERIAL_H