mirror of
https://github.com/Relintai/sfw.git
synced 2025-03-11 23:39:09 +01:00
Split materials into header and cpp.
This commit is contained in:
parent
eb61466024
commit
59f495edff
@ -69,6 +69,14 @@ ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/input.cpp -o sfw/rende
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/shortcut.cpp -o sfw/render_core/shortcut.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/font.cpp -o sfw/render_core/font.o
|
||||
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/color_material_2d.cpp -o sfw/render_core/color_material_2d.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/color_material.cpp -o sfw/render_core/color_material.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/colored_material.cpp -o sfw/render_core/colored_material.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/font_material.cpp -o sfw/render_core/font_material.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/texture_material_2d.cpp -o sfw/render_core/texture_material_2d.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/texture_material.cpp -o sfw/render_core/texture_material.o
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/transparent_texture_material.cpp -o sfw/render_core/transparent_texture_material.o
|
||||
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_immediate/renderer.cpp -o sfw/render_immediate/renderer.o
|
||||
|
||||
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_objects/camera_3d.cpp -o sfw/render_objects/camera_3d.o
|
||||
@ -105,6 +113,10 @@ ccache g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/core/aabb.o sfw/c
|
||||
sfw/render_core/input_event.o sfw/render_core/input_map.o \
|
||||
sfw/render_core/input.o sfw/render_core/shortcut.o \
|
||||
sfw/render_core/keyboard.o sfw/render_core/font.o \
|
||||
sfw/render_core/color_material_2d.o sfw/render_core/color_material.o \
|
||||
sfw/render_core/colored_material.o sfw/render_core/font_material.o \
|
||||
sfw/render_core/texture_material_2d.o sfw/render_core/texture_material.o \
|
||||
sfw/render_core/transparent_texture_material.o \
|
||||
sfw/render_immediate/renderer.o \
|
||||
sfw/render_objects/camera_3d.o sfw/render_objects/object_3d.o sfw/render_objects/mesh_instance_3d.o \
|
||||
sfw/render_objects/object_2d.o \
|
||||
|
53
sfw/render_core/color_material.cpp
Normal file
53
sfw/render_core/color_material.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
|
||||
//--STRIP
|
||||
#include "color_material.h"
|
||||
//--STRIP
|
||||
|
||||
void ColorMaterial::bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
|
||||
set_uniform(camera_matrix_location, RenderState::camera_transform_3d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
|
||||
}
|
||||
|
||||
void ColorMaterial::setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
camera_matrix_location = get_uniform("u_camera_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
}
|
||||
|
||||
const GLchar **ColorMaterial::get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_camera_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec4 a_color;\n"
|
||||
"\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_color = a_color;\n"
|
||||
" gl_Position = u_proj_matrix * u_camera_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **ColorMaterial::get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() { gl_FragColor = v_color; }\n"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
ColorMaterial::ColorMaterial() {
|
||||
projection_matrix_location = 0;
|
||||
camera_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
}
|
@ -15,54 +15,13 @@ public:
|
||||
return 2;
|
||||
}
|
||||
|
||||
void bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
|
||||
set_uniform(camera_matrix_location, RenderState::camera_transform_3d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
|
||||
}
|
||||
void bind_uniforms();
|
||||
void setup_uniforms();
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
camera_matrix_location = get_uniform("u_camera_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
}
|
||||
const GLchar **get_vertex_shader_source();
|
||||
const GLchar **get_fragment_shader_source();
|
||||
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_camera_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec4 a_color;\n"
|
||||
"\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_color = a_color;\n"
|
||||
" gl_Position = u_proj_matrix * u_camera_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() { gl_FragColor = v_color; }\n"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
ColorMaterial() {
|
||||
projection_matrix_location = 0;
|
||||
camera_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
}
|
||||
ColorMaterial();
|
||||
|
||||
GLint projection_matrix_location;
|
||||
GLint camera_matrix_location;
|
||||
|
60
sfw/render_core/color_material_2d.cpp
Normal file
60
sfw/render_core/color_material_2d.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
|
||||
//--STRIP
|
||||
#include "color_material_2d.h"
|
||||
//--STRIP
|
||||
|
||||
void ColorMaterial2D::bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_2d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_2d);
|
||||
}
|
||||
|
||||
void ColorMaterial2D::setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
}
|
||||
|
||||
void ColorMaterial2D::unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void ColorMaterial2D::setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **ColorMaterial2D::get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec4 a_color;\n"
|
||||
"\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_color = a_color;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **ColorMaterial2D::get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = v_color;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
ColorMaterial2D::ColorMaterial2D() {
|
||||
projection_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
}
|
@ -16,61 +16,15 @@ public:
|
||||
return 17;
|
||||
}
|
||||
|
||||
void bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_2d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_2d);
|
||||
}
|
||||
void bind_uniforms();
|
||||
void setup_uniforms();
|
||||
void unbind();
|
||||
void setup_state();
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
}
|
||||
const GLchar **get_vertex_shader_source();
|
||||
const GLchar **get_fragment_shader_source();
|
||||
|
||||
void unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec4 a_color;\n"
|
||||
"\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_color = a_color;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = v_color;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
ColorMaterial2D() {
|
||||
projection_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
}
|
||||
ColorMaterial2D();
|
||||
|
||||
GLint projection_matrix_location;
|
||||
GLint model_view_matrix_location;
|
||||
|
49
sfw/render_core/colored_material.cpp
Normal file
49
sfw/render_core/colored_material.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
//--STRIP
|
||||
#include "colored_material.h"
|
||||
//--STRIP
|
||||
|
||||
void ColoredMaterial::bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
|
||||
|
||||
glUniform4f(tri_color_uniform_location, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void ColoredMaterial::setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
tri_color_uniform_location = get_uniform("fragment_color");
|
||||
}
|
||||
|
||||
const GLchar **ColoredMaterial::get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **ColoredMaterial::get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform vec4 fragment_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = fragment_color;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
ColoredMaterial::ColoredMaterial() {
|
||||
}
|
@ -15,52 +15,13 @@ public:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
|
||||
void bind_uniforms();
|
||||
void setup_uniforms();
|
||||
|
||||
glUniform4f(tri_color_uniform_location, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
const GLchar **get_vertex_shader_source();
|
||||
const GLchar **get_fragment_shader_source();
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
tri_color_uniform_location = get_uniform("fragment_color");
|
||||
}
|
||||
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform vec4 fragment_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = fragment_color;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
ColoredMaterial() :
|
||||
Material() {
|
||||
}
|
||||
ColoredMaterial();
|
||||
|
||||
GLint projection_matrix_location;
|
||||
GLint model_view_matrix_location;
|
||||
|
81
sfw/render_core/font_material.cpp
Normal file
81
sfw/render_core/font_material.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
//--STRIP
|
||||
#include "font_material.h"
|
||||
//--STRIP
|
||||
|
||||
void FontMaterial::bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_2d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_2d);
|
||||
|
||||
if (texture.is_valid()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
|
||||
glUniform1i(texture_location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void FontMaterial::setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
texture_location = get_uniform("u_texture");
|
||||
}
|
||||
|
||||
void FontMaterial::unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void FontMaterial::setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **FontMaterial::get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_uv;\n"
|
||||
"attribute vec4 a_color;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" v_color = a_color;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **FontMaterial::get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" vec4 col = texture2D(u_texture, v_uv);\n"
|
||||
"\n"
|
||||
" if (col.r < 0.5) {\n"
|
||||
" discard;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" gl_FragColor = col * v_color;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
FontMaterial::FontMaterial() {
|
||||
projection_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
|
||||
texture_location = 0;
|
||||
}
|
@ -16,83 +16,15 @@ public:
|
||||
return 11;
|
||||
}
|
||||
|
||||
void bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_2d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_2d);
|
||||
void bind_uniforms();
|
||||
void setup_uniforms();
|
||||
void unbind();
|
||||
void setup_state();
|
||||
|
||||
if (texture.is_valid()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
|
||||
glUniform1i(texture_location, 0);
|
||||
}
|
||||
}
|
||||
const GLchar **get_vertex_shader_source();
|
||||
const GLchar **get_fragment_shader_source();
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
texture_location = get_uniform("u_texture");
|
||||
}
|
||||
|
||||
void unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_uv;\n"
|
||||
"attribute vec4 a_color;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" v_color = a_color;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" vec4 col = texture2D(u_texture, v_uv);\n"
|
||||
"\n"
|
||||
" if (col.r < 0.5) {\n"
|
||||
" discard;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" gl_FragColor = col * v_color;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
FontMaterial() {
|
||||
projection_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
|
||||
texture_location = 0;
|
||||
}
|
||||
FontMaterial();
|
||||
|
||||
GLint projection_matrix_location;
|
||||
GLint model_view_matrix_location;
|
||||
|
76
sfw/render_core/texture_material.cpp
Normal file
76
sfw/render_core/texture_material.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
//--STRIP
|
||||
#include "texture_material.h"
|
||||
//--STRIP
|
||||
|
||||
void TextureMaterial::bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
|
||||
set_uniform(camera_matrix_location, RenderState::camera_transform_3d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
|
||||
|
||||
if (texture.is_valid()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
|
||||
glUniform1i(texture_location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void TextureMaterial::setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_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");
|
||||
}
|
||||
|
||||
void TextureMaterial::unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void TextureMaterial::setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **TextureMaterial::get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_camera_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_uv;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" gl_Position = u_proj_matrix * u_camera_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **TextureMaterial::get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = texture2D(u_texture, v_uv);\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
TextureMaterial::TextureMaterial() {
|
||||
projection_matrix_location = 0;
|
||||
camera_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
|
||||
texture_location = 0;
|
||||
}
|
@ -16,77 +16,15 @@ public:
|
||||
return 3;
|
||||
}
|
||||
|
||||
void bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
|
||||
set_uniform(camera_matrix_location, RenderState::camera_transform_3d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
|
||||
void bind_uniforms();
|
||||
void setup_uniforms();
|
||||
void unbind();
|
||||
void setup_state();
|
||||
|
||||
if (texture.is_valid()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
|
||||
glUniform1i(texture_location, 0);
|
||||
}
|
||||
}
|
||||
const GLchar **get_vertex_shader_source();
|
||||
const GLchar **get_fragment_shader_source();
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_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");
|
||||
}
|
||||
|
||||
void unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_camera_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_uv;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" gl_Position = u_proj_matrix * u_camera_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = texture2D(u_texture, v_uv);\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
TextureMaterial() {
|
||||
projection_matrix_location = 0;
|
||||
camera_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
|
||||
texture_location = 0;
|
||||
}
|
||||
TextureMaterial();
|
||||
|
||||
GLint projection_matrix_location;
|
||||
GLint camera_matrix_location;
|
||||
|
77
sfw/render_core/texture_material_2d.cpp
Normal file
77
sfw/render_core/texture_material_2d.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
//--STRIP
|
||||
#include "texture_material_2d.h"
|
||||
//--STRIP
|
||||
|
||||
void TextureMaterial2D::bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_2d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_2d);
|
||||
|
||||
if (texture.is_valid()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
|
||||
glUniform1i(texture_location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void TextureMaterial2D::setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
texture_location = get_uniform("u_texture");
|
||||
}
|
||||
|
||||
void TextureMaterial2D::unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void TextureMaterial2D::setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **TextureMaterial2D::get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_uv;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **TextureMaterial2D::get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" vec4 col = texture2D(u_texture, v_uv);\n"
|
||||
"\n"
|
||||
" if (col.a < 0.1) {\n"
|
||||
" discard;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" gl_FragColor = col;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
TextureMaterial2D::TextureMaterial2D() {
|
||||
projection_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
|
||||
texture_location = 0;
|
||||
}
|
@ -16,80 +16,16 @@ public:
|
||||
return 10;
|
||||
}
|
||||
|
||||
void bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_2d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_2d);
|
||||
void bind_uniforms();
|
||||
void setup_uniforms();
|
||||
void unbind();
|
||||
void setup_state();
|
||||
|
||||
if (texture.is_valid()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
|
||||
glUniform1i(texture_location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
texture_location = get_uniform("u_texture");
|
||||
}
|
||||
|
||||
void unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_uv;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" vec4 col = texture2D(u_texture, v_uv);\n"
|
||||
"\n"
|
||||
" if (col.a < 0.1) {\n"
|
||||
" discard;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" gl_FragColor = col;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
TextureMaterial2D() {
|
||||
projection_matrix_location = 0;
|
||||
model_view_matrix_location = 0;
|
||||
|
||||
texture_location = 0;
|
||||
}
|
||||
const GLchar **get_vertex_shader_source();
|
||||
const GLchar **get_fragment_shader_source();
|
||||
|
||||
TextureMaterial2D();
|
||||
|
||||
GLint projection_matrix_location;
|
||||
GLint model_view_matrix_location;
|
||||
|
||||
|
74
sfw/render_core/transparent_texture_material.cpp
Normal file
74
sfw/render_core/transparent_texture_material.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
//--STRIP
|
||||
#include "transparent_texture_material.h"
|
||||
//--STRIP
|
||||
|
||||
void TransparentTextureMaterial::bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
|
||||
|
||||
if (texture.is_valid()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
|
||||
glUniform1i(texture_location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void TransparentTextureMaterial::setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
texture_location = get_uniform("u_texture");
|
||||
}
|
||||
|
||||
void TransparentTextureMaterial::unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void TransparentTextureMaterial::setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **TransparentTextureMaterial::get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_uv;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **TransparentTextureMaterial::get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" vec4 col = texture2D(u_texture, v_uv);\n"
|
||||
"\n"
|
||||
" if (col.a < 0.1) {\n"
|
||||
" discard;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" gl_FragColor = col;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
TransparentTextureMaterial::TransparentTextureMaterial() {
|
||||
texture_location = 0;
|
||||
}
|
@ -16,76 +16,15 @@ public:
|
||||
return 4;
|
||||
}
|
||||
|
||||
void bind_uniforms() {
|
||||
set_uniform(projection_matrix_location, RenderState::projection_matrix_3d);
|
||||
set_uniform(model_view_matrix_location, RenderState::model_view_matrix_3d);
|
||||
void bind_uniforms();
|
||||
void setup_uniforms();
|
||||
void unbind();
|
||||
void setup_state();
|
||||
|
||||
if (texture.is_valid()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->get_gl_texture());
|
||||
glUniform1i(texture_location, 0);
|
||||
}
|
||||
}
|
||||
const GLchar **get_vertex_shader_source();
|
||||
const GLchar **get_fragment_shader_source();
|
||||
|
||||
void setup_uniforms() {
|
||||
projection_matrix_location = get_uniform("u_proj_matrix");
|
||||
model_view_matrix_location = get_uniform("u_model_view_matrix");
|
||||
|
||||
texture_location = get_uniform("u_texture");
|
||||
}
|
||||
|
||||
void unbind() {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void setup_state() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const GLchar **get_vertex_shader_source() {
|
||||
static const GLchar *vertex_shader_source[] = {
|
||||
"uniform mat4 u_proj_matrix;\n"
|
||||
"uniform mat4 u_model_view_matrix;\n"
|
||||
"\n"
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_uv;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" gl_Position = u_proj_matrix * u_model_view_matrix * a_position;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return vertex_shader_source;
|
||||
}
|
||||
|
||||
const GLchar **get_fragment_shader_source() {
|
||||
static const GLchar *fragment_shader_source[] = {
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"\n"
|
||||
"varying vec2 v_uv;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" vec4 col = texture2D(u_texture, v_uv);\n"
|
||||
"\n"
|
||||
" if (col.a < 0.1) {\n"
|
||||
" discard;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" gl_FragColor = col;\n"
|
||||
"}"
|
||||
};
|
||||
|
||||
return fragment_shader_source;
|
||||
}
|
||||
|
||||
TransparentTextureMaterial() {
|
||||
texture_location = 0;
|
||||
}
|
||||
TransparentTextureMaterial();
|
||||
|
||||
GLint projection_matrix_location;
|
||||
GLint model_view_matrix_location;
|
||||
|
Loading…
Reference in New Issue
Block a user