use std::marker::PhantomData;
use glutin::{dpi::PhysicalSize, PossiblyCurrent, WindowedContext};
use ogl33::{functions::glViewport, types::GLsizei};
use crate::{
config::PelAttributes,
gpu::{Program, Texture, TextureHandle},
};
pub struct Context {
pub(crate) window: WindowedContext<PossiblyCurrent>,
_program: Program,
texture: Texture,
phantom: PhantomData<*const ()>, }
impl Context {
pub fn texture(&mut self) -> TextureHandle {
self.texture.texture()
}
pub fn resize_texture(&mut self, w: usize, h: usize) {
self.texture.resize(w, h);
}
pub(super) fn new(window: WindowedContext<PossiblyCurrent>, attribs: &PelAttributes) -> Self {
let (texture_width, texture_height) = attribs.texture_size.expect("Pel texture size was not set!");
Self {
window,
_program: Program::default(),
texture: Texture::new(texture_width, texture_height),
phantom: PhantomData,
}
}
pub(crate) fn resize_viewport(&self, physical_size: PhysicalSize<u32>) {
let (w, h): (u32, u32) = physical_size.into();
unsafe {
glViewport(0, 0, w as GLsizei, h as GLsizei);
}
}
pub(crate) fn request_redraw(&self) {
self.window.window().request_redraw();
}
pub(crate) fn draw(&self) {
self.texture.draw()
}
pub(crate) fn swap_buffers(&self) {
self.window.swap_buffers().expect("failed to swap window buffers");
}
}