The Framebuffer 1 Contents Buffers and Their Uses
The Framebuffer 1
Contents Buffers and Their Uses n Testing and Operating on fragments n The Accumulation Buffer n 2
Framebuffer - 1 n Buffer n n Pixel들이 저장되는 메모리 Framebuffer: 여러 Buffers의 집합 n n Color buffer: front, back, left, right Depth buffer Stencil buffer Accumulation buffer 3
Framebuffer - 1 n Color Buffer n 각 픽셀의 색상에 관한 정보를 가진 버퍼 n n GL_STEREO n n RGBA or Index color Left, Right Buffer GL_DOUBLEBUFFER n Front, Back Buffer 4
Depth Buffer n n Stencil Buffer n n 각 pixel의 깊이값을 가지고 있는 버퍼(zbuffer) Screen상에 drawing 영역을 제한하기 위해 사 용되는 버퍼 Accumulation Buffer n Holding RGBA color 5
Controlling Buffer n Clearing Buffer n Set the clearing values for each buffer Void n Void n n gl. Clear. Color(red, green, blue, alpha); gl. Clear. Index(index); gl. Clear. Depth(depth); gl. Clear. Stencil(s); gl. Clear. Accum(red, green, blue, alpha); Clear buffer n Void gl. Clear(GLbitfield mask); 6
Controlling Buffer n Selecting Color Buffer for writing and Reading n n Void gl. Draw. Buffer(mode); Void gl. Read. Buffer(mode); GL_FRONT, GL_BACK, GL_LEFT, GL_RIGHT GL_FRONT_LEFT, GL_FRONT_RIGHT, GL_BACK_LEFT, GL_BACK_RIGHT, GL_AUXi GL_FRONT_AND_BACK, GL_NONE 7
Masking Buffers n n n n Void gl. Index. Mask(GLuint mask); Void gl. Color. Mask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); Void gl. Depth. Mask(GLboolean flag); Void gl. Stencil. Mask(GLuint mask); 8
Testing and Operating on Fragments Scissor Test n Alpha Test n Stencil Test n Depth Test n Blending n Dithering n Logical Operation n 9
Tests - 1 n Scissor Test n Defining a rectangular portion of window gl. Enable(GL_SCISSOR_TEST); n Void gl. Scissor(x, y, width, height); n n Alpha Test gl. Enable(GL_ALPHA_TEST); n Void gl. Alpha. Func(GLenum func, GLclampf ref); GLenum func n 10
Tests - 2 n Stencil Test n n n Void gl. Stencil. Func(GLenum func, GLint ref, GLuint mask); Void gl. Stencil. Op(GLenum fail, GLenum zpass); Example 11
Test - 3 n Depth Test n n If the specified depth test passes, the incoming depth value replaces the values in the depth buffer Void gl. Depth. Func(GLenum func); Blending n Dithering n Logical Operation n n Void gl. Logic. Op(GLenum opcode); 12
The Accumulation Buffer n Application n n Antialiasing, motion blur, simulating photographic depth of field, calculating soft shadows Method n Void gl. Accum(GLenum op, GLfloat value); GL_ACCUM, GL_LOAD, GL_RETURN, GL_ADD, GL_MULT n Example n 13
Example - 1 n //스텐실 버퍼 영역 설정 gl. Clear(GL_STENCIL_BUFFER_BIT); gl. Stencil. Func(GL_ALWAYS, 0 X 1); gl. Stencil. Op(GL_REPLACE, GL_REPLACE); gl. Begin(GL_QUADS); //사각형 그리기 gl. Vertex 2 f(-1. 0, 0. 0); gl. Vertex 2 f(0. 0, 1. 0); gl. Vertex 2 f(1. 0, 0. 0); gl. Vertex 2 f(0. 0, -1. 0); gl. End(); 14
Example - 2 n //스텐실 영역 안에 그리기 gl. Stencil. Func(GL_EQUAL, 0 X 1); gl. Stencil. Op(GL_KEEP, GL_KEEP); gl. Call. List(BLUEMAT); //이때는 파란색으로 구를 그린다. glut. Solid. Sphere(0. 5, 15); 15
Example - 3 //스텐실 버퍼의 바깥쪽에 그리기 gl. Stencil. Func(GL_NOTEQUAL, 0 X 1); gl. Push. Matrix(); gl. Rotatef(45. 0, 0. 0, 1. 0); gl. Rotatef(45. 0, 0. 0, 1. 0, 0. 0); gl. Call. List(YELLOWMAT); //이게 적용된 것은 노란색으로 재질 설정 glut. Solid. Torus(0. 275, 0. 85, 15); gl. Push. Matrix(); //기존의 좌표를 저장하고 새로운 좌표에서 다시 한번 더 그린다. gl. Rotatef(90. 0, 1. 0, 0. 0); glut. Solid. Torus(0. 275, 0. 85, 15); gl. Pop. Matrix(); 16
Example - 4 for(frame = 0. 0; frame<5. 0; frame++) { gl. Push. Matrix(); gl. Translatef(-frame*0. 2, 0. 0); gl. Color 3 f(1. 0, 1. 0); aux. Solid. Sphere(1. 0); gl. Pop. Matrix(); if(frame==0) gl. Accum(GL_LOAD, (6 -frame)/40); else gl. Accum(GL_ACCUM, (6 -frame)/40); } gl. Accum(GL_RETURN, 1. 0); 17
GLenum func Parameter Meaning GL_NEVER Never accept GL_ALWAYS Always accept GL_LESS Fragment value < reference GL_LEQUAL Fragment value <= reference GL_EQUAL Fragment value = reference GL_GEQUAL Fragment value >= reference GL_GREATER Fragment value > reference GL_NOTEQUAL Fragment value != reference 18
Logical Operations Parameter Op GL_CLEAR 0 GL_AND s^d GL_COPY s GL_OR s. Ud GL_NOOP d GL_NAND ~(s^d) GL_SET 1 GL_NOR ~(s. Ud) GL_COPY_INVERT ~s ED GL_XOR S xor d GL_INVERT ~d GL_EQUIV ~(s xor d) GL_AND_REVERS E S^~d GL_AND_INVERTED ~s^d GL_OR_REVERSE s. U~d GL_OR_INVERTED ~s. Ud 19
- Slides: 19