mirror of https://github.com/Leinnan/doppler.git
Impl Drop for Framebuffer, Texture and Shader. Regenerate framebuffer on size change
This commit is contained in:
parent
972b99a6a3
commit
d78ba01130
|
|
@ -3,10 +3,17 @@ out vec4 FragColor;
|
|||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform float screen_width;
|
||||
uniform float screen_height;
|
||||
uniform sampler2D screenTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 col = texture(screenTexture, TexCoords).rgb;
|
||||
FragColor = vec4(col, 1.0);
|
||||
vec2 uv = TexCoords.xy;
|
||||
uv *= 1.0 - uv.yx;
|
||||
float vig = uv.x*uv.y * 15.0;
|
||||
vig = pow(vig, 0.3);
|
||||
|
||||
|
||||
FragColor = texture(screenTexture, TexCoords) * vig;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ impl Engine {
|
|||
// height will be significantly larger than specified on retina displays.
|
||||
unsafe { gl::Viewport(0, 0, width, height) }
|
||||
self.window_size = (width as f32, height as f32);
|
||||
self.framebuffer = unsafe { FramebufferSystem::generate(width, height) };
|
||||
}
|
||||
glfw::WindowEvent::CursorPos(xpos, ypos) => {
|
||||
if skip_input {
|
||||
|
|
@ -265,8 +266,8 @@ impl Default for Engine {
|
|||
unsafe {
|
||||
gl::Enable(gl::DEPTH_TEST);
|
||||
}
|
||||
let (scr_width, scr_height) = window.get_framebuffer_size();
|
||||
let client = ExampleClient::create(&window);
|
||||
let (scr_width, scr_height) = window.get_framebuffer_size();
|
||||
let fb = unsafe { FramebufferSystem::generate(scr_width, scr_height) };
|
||||
println!("{:?}", fb);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ pub struct FramebufferSystem {
|
|||
|
||||
impl Drop for FramebufferSystem {
|
||||
fn drop(&mut self) {
|
||||
println!("Drop framebuffer!");
|
||||
unsafe {
|
||||
gl::DeleteVertexArrays(1, &self.vao);
|
||||
gl::DeleteBuffers(1, &self.vbo);
|
||||
gl::DeleteFramebuffers(1, &self.framebuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -85,6 +87,8 @@ impl FramebufferSystem {
|
|||
);
|
||||
screenShader.use_program();
|
||||
screenShader.setInt(c_str!("screenTexture"), 0);
|
||||
screenShader.setFloat(c_str!("screen_width"), scr_width as f32);
|
||||
screenShader.setFloat(c_str!("screen_height"), scr_height as f32);
|
||||
|
||||
// framebuffer configuration
|
||||
// -------------------------
|
||||
|
|
|
|||
|
|
@ -49,6 +49,12 @@ pub struct Texture {
|
|||
pub path: String,
|
||||
}
|
||||
|
||||
impl Drop for Texture {
|
||||
fn drop(&mut self) {
|
||||
unsafe { gl::DeleteTextures(1, &self.id); }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Mesh {
|
||||
/* Mesh Data */
|
||||
|
|
|
|||
|
|
@ -10,13 +10,19 @@ use gl::types::*;
|
|||
|
||||
use crate::gaia::consts;
|
||||
use cgmath::prelude::*;
|
||||
use cgmath::{Matrix, Matrix4, Vector3};
|
||||
use cgmath::{Matrix, Matrix4, Vector3, Vector2};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Shader {
|
||||
pub ID: u32,
|
||||
}
|
||||
|
||||
impl Drop for Shader {
|
||||
fn drop(&mut self) {
|
||||
unsafe{gl::DeleteShader(self.ID);}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Shader {
|
||||
fn default() -> Self {
|
||||
let vShaderCode = CString::new(consts::VERTEX_SHADER_SRC.as_bytes()).unwrap();
|
||||
|
|
@ -108,6 +114,13 @@ impl Shader {
|
|||
value.as_ptr(),
|
||||
);
|
||||
}
|
||||
pub unsafe fn set_vector2(&self, name: &CStr, value: &Vector2<f32>) {
|
||||
gl::Uniform2fv(
|
||||
gl::GetUniformLocation(self.ID, name.as_ptr()),
|
||||
1,
|
||||
value.as_ptr(),
|
||||
);
|
||||
}
|
||||
/// ------------------------------------------------------------------------
|
||||
pub unsafe fn set_vec3(&self, name: &CStr, x: f32, y: f32, z: f32) {
|
||||
gl::Uniform3f(gl::GetUniformLocation(self.ID, name.as_ptr()), x, y, z);
|
||||
|
|
|
|||
Loading…
Reference in New Issue