Material cleanups.

This commit is contained in:
Relintai 2024-01-04 18:39:16 +01:00
parent 12a6cab9e9
commit 29a7478e0a
4 changed files with 15 additions and 11 deletions

View File

@ -7,6 +7,8 @@
#include "render_core/render_state.h" #include "render_core/render_state.h"
class FontMaterial : public Material { class FontMaterial : public Material {
SFW_OBJECT(FontMaterial, Material);
public: public:
int get_material_id() { int get_material_id() {
return 11; return 11;

View File

@ -7,6 +7,8 @@
#include "render_core/render_state.h" #include "render_core/render_state.h"
class TextureMaterial : public Material { class TextureMaterial : public Material {
SFW_OBJECT(TextureMaterial, Material);
public: public:
int get_material_id() { int get_material_id() {
return 3; return 3;
@ -17,7 +19,7 @@ public:
set_uniform(camera_matrix_location, RenderState::camera_transform_3d); set_uniform(camera_matrix_location, RenderState::camera_transform_3d);
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d); set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
if (texture) { if (texture.is_valid()) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture()); glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
glUniform1i(texture_location, 0); glUniform1i(texture_location, 0);
@ -26,7 +28,7 @@ public:
void setup_uniforms() { void setup_uniforms() {
projection_matrix_location = get_uniform("u_proj_matrix"); 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"); model_view_matrix_location = get_uniform("u_model_view_matrix");
texture_location = get_uniform("u_texture"); texture_location = get_uniform("u_texture");
@ -76,14 +78,12 @@ public:
return fragment_shader_source; return fragment_shader_source;
} }
TextureMaterial() : TextureMaterial() {
Material() {
projection_matrix_location = 0; projection_matrix_location = 0;
camera_matrix_location = 0; camera_matrix_location = 0;
model_view_matrix_location = 0; model_view_matrix_location = 0;
texture_location = 0; texture_location = 0;
texture = NULL;
} }
GLint projection_matrix_location; GLint projection_matrix_location;
@ -92,7 +92,7 @@ public:
GLint texture_location; GLint texture_location;
Texture *texture; Ref<Texture> texture;
}; };
#endif // COLORED_MATERIAL_H #endif // COLORED_MATERIAL_H

View File

@ -7,6 +7,8 @@
#include "render_core/render_state.h" #include "render_core/render_state.h"
class TextureMaterial2D : public Material { class TextureMaterial2D : public Material {
SFW_OBJECT(TextureMaterial2D, Material);
public: public:
int get_material_id() { int get_material_id() {
return 10; return 10;

View File

@ -7,6 +7,8 @@
#include "render_core/render_state.h" #include "render_core/render_state.h"
class TransparentTextureMaterial : public Material { class TransparentTextureMaterial : public Material {
SFW_OBJECT(TransparentTextureMaterial, Material);
public: public:
int get_material_id() { int get_material_id() {
return 4; return 4;
@ -16,7 +18,7 @@ public:
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d); set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d); set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
if (texture) { if (texture.is_valid()) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture()); glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
glUniform1i(texture_location, 0); glUniform1i(texture_location, 0);
@ -79,10 +81,8 @@ public:
return fragment_shader_source; return fragment_shader_source;
} }
TransparentTextureMaterial() : TransparentTextureMaterial() {
Material() {
texture_location = 0; texture_location = 0;
texture = NULL;
} }
GLint projection_matrix_location; GLint projection_matrix_location;
@ -90,7 +90,7 @@ public:
GLint texture_location; GLint texture_location;
Texture *texture; Ref<Texture> texture;
}; };
#endif // COLORED_MATERIAL_H #endif // COLORED_MATERIAL_H