vanilladocs
vanillapunch.com
API / graphics3d

graphics3d

3D 그래픽. (원본 src/graphics3d, WebGL2 3D 스택)

  • 원본과 같이 2D Graphic 과 GL 컨텍스트 하나를 같이 쓴다. GL 객체를 만들거나 그리는 함수는 원본의 webGL2RenderingContext 멤버 대신 gl: &GlContext 를 받는다. (Graphic.get_gl() 로 꺼낸다. ShaderProgram 과 같은 꼴)
  • 3D 를 그리기 전에 graphic.flush_batch() 로 모아 둔 2D 를 내보내고, 다 그린 뒤 graphic.restore_render_state() 로 2D 프로그램, 버텍스 어레이, 뷰포트, 블렌드, 깊이 상태를 되돌린다.
  • 파일 하나가 원본 파일 하나다. fullscreenpass.js 는 core::fullscreenpass 에 있고 여기서 다시 내보낸다. 원본에서 옮기지 않은 것: webgl2.js 와 gl2d.js(죽은 코드, 원본은 src/deprecated 로 옮겼다).

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).
예제Example2D 를 내보내고 3D 모델을 그린 뒤 2D 상태 되돌리기Flush 2D, draw a 3D model, then restore the 2D state
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();
}

GlFramebuffertype

소스source

GL 객체 타입. (core::graphic 에 없는 프레임버퍼와 렌더버퍼)

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

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

GlRenderbuffertype

소스source

GL 렌더버퍼 핸들. (glow::Context 의 Renderbuffer, 렌더 타겟의 깊이 버퍼 같은 것)

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

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