# graphics3d (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/graphics3d/

3D graphics. (the original src/graphics3d, the WebGL2 3D stack)
- Like the original, it shares one GL context with the 2D Graphic. Functions that create GL objects or draw take gl: &GlContext instead of the original's webGL2RenderingContext
  member. (taken out with Graphic.get_gl(). Same form as ShaderProgram)
- Before drawing 3D, flush the accumulated 2D with graphic.flush_batch(), and after drawing restore the
  2D program, vertex array, viewport, blend and depth state with graphic.restore_render_state().
- One file is one original file. fullscreenpass.js is in core::fullscreenpass and is re-exported here.
  Not carried over from the original: webgl2.js and gl2d.js (dead code, the original moved them to src/deprecated).

Example: Flush 2D, draw a 3D model, then restore the 2D state

```rust
use vanilla::{Graphic, Matrix4, SkinnedModel, SkinnedModelRenderer, Vector3};

fn draw_3d(graphic: &mut Graphic, skinned_model_renderer: &SkinnedModelRenderer, skinned_model: &mut SkinnedModel, view_projection_matrix: &Matrix4, camera_position: Vector3) {
	graphic.flush_batch();
	let model_matrix = Matrix4::create_identity();
	skinned_model_renderer.draw(graphic.get_gl(), skinned_model, view_projection_matrix.get_elements(), model_matrix.get_elements(), camera_position.x, camera_position.y, camera_position.z);
	graphic.restore_render_state();
}
```

## GlFramebuffer (type)

GL object types. (framebuffers and renderbuffers, which core::graphic does not have)

```rust
pub type GlFramebuffer = <glow::Context as glow::HasContext>::Framebuffer
```

## GlRenderbuffer (type)

GL renderbuffer handle. (Renderbuffer of glow::Context, such as a render target's depth buffer)

```rust
pub type GlRenderbuffer = <glow::Context as glow::HasContext>::Renderbuffer
```

