use Api;
use ContextError;
use CreationError;
use GlAttributes;
use GlRequest;
use GlContext;
use PixelFormat;
use PixelFormatRequirements;
use Robustness;
use platform;
pub struct HeadlessRendererBuilder<'a> {
pub dimensions: (u32, u32),
pub opengl: GlAttributes<&'a platform::HeadlessContext>,
pf_reqs: PixelFormatRequirements,
platform_specific: platform::PlatformSpecificHeadlessBuilderAttributes,
}
impl<'a> HeadlessRendererBuilder<'a> {
#[inline]
pub fn new(width: u32, height: u32) -> HeadlessRendererBuilder<'a> {
HeadlessRendererBuilder {
dimensions: (width, height),
pf_reqs: Default::default(),
opengl: Default::default(),
platform_specific: Default::default(),
}
}
#[inline]
pub fn with_gl(mut self, request: GlRequest) -> HeadlessRendererBuilder<'a> {
self.opengl.version = request;
self
}
#[inline]
pub fn with_gl_debug_flag(mut self, flag: bool) -> HeadlessRendererBuilder<'a> {
self.opengl.debug = flag;
self
}
#[inline]
pub fn with_gl_robustness(mut self, robustness: Robustness) -> HeadlessRendererBuilder<'a> {
self.opengl.robustness = robustness;
self
}
#[inline]
pub fn build(self) -> Result<HeadlessContext, CreationError> {
platform::HeadlessContext::new(self.dimensions, &self.pf_reqs, &self.opengl,
&self.platform_specific)
.map(|w| HeadlessContext { context: w })
}
#[inline]
pub fn build_strict(self) -> Result<HeadlessContext, CreationError> {
self.build()
}
}
pub struct HeadlessContext {
context: platform::HeadlessContext,
}
impl HeadlessContext {
#[inline]
pub unsafe fn make_current(&self) -> Result<(), ContextError> {
self.context.make_current()
}
#[inline]
pub fn is_current(&self) -> bool {
self.context.is_current()
}
#[inline]
pub fn get_proc_address(&self, addr: &str) -> *const () {
self.context.get_proc_address(addr)
}
#[inline]
pub fn get_api(&self) -> Api {
self.context.get_api()
}
#[inline]
pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) {
}
}
impl GlContext for HeadlessContext {
#[inline]
unsafe fn make_current(&self) -> Result<(), ContextError> {
self.context.make_current()
}
#[inline]
fn is_current(&self) -> bool {
self.context.is_current()
}
#[inline]
fn get_proc_address(&self, addr: &str) -> *const () {
self.context.get_proc_address(addr)
}
#[inline]
fn swap_buffers(&self) -> Result<(), ContextError> {
self.context.swap_buffers()
}
#[inline]
fn get_api(&self) -> Api {
self.context.get_api()
}
#[inline]
fn get_pixel_format(&self) -> PixelFormat {
self.context.get_pixel_format()
}
}