ios - OpenGL ES 2.0 - GL_POINTS and Stencil Buffer -
i trying draw texture in opengl es 2.0 using gl_points applying stencil buffer. stencil buffer should come texture. rendering results texture , presenting texture screen. here code rendering texture:
//initialize buffers, initialize texture, bind framebuffer ..... glclearstencil(0); glclear (gl_stencil_buffer_bit); glcolormask( gl_false, gl_false, gl_false, gl_false ); glenable(gl_stencil_test); glstencilfunc(gl_always, 1, 1); glstencilop(gl_keep, gl_keep, gl_replace); glbindtexture(gl_texture_2d, stencil); gluseprogram(program[program_point].id); gldrawarrays(gl_points, 0, (int)vertexcount); glcolormask(gl_true, gl_true, gl_true, gl_true); glstencilfunc(gl_never, 0, 1); glstencilop(gl_replace, gl_keep, gl_keep); glbindtexture(gl_texture_2d, texture); gluseprogram(program[program_point].id); gldrawarrays(gl_points, 0, (int)vertexcount); gldisable(gl_stencil_test); .... //render texture screen
the result getting texture beingness drawn without masking applied stencil. had few questions regarding issue:
is possible utilize stencil buffer gl_points? is possible utilize stencil buffer when rendering texture? does stencil texture have have special properties (solid colour, internal format...etc)? are there apparent mistakes code?this result looking for:
update:
my problem, pointed out selected answer, did not attach stencil stencil attachment of fbo:
glframebufferrenderbuffer(gl_framebuffer, gl_stencil_attachment, gl_renderbuffer, stencilbufferid);
i did not know required when rendering texture. secondly not using proper stencil test.
glstencilfunc(gl_equal, 1, 1); glstencilop(gl_keep, gl_keep, gl_keep);
did job.
addressing questions in order:
is possible utilize stencil buffer gl_points?yes. stencil test applied fragments, no matter of primitive type rendered. case write framebuffer without applying stencil test glclear()
.
yes. however, when render texture using fbo, stencil buffer of default framebuffer not used. have create stencil renderbuffer, , attach stencil attachment of fbo:
gluint stencilbufferid = 0; glgenrenderbuffers(1, &stencilbufferid); glbindrenderbuffer(gl_renderbuffer, stencilbufferid); glrenderbufferstorage(gl_renderbuffer, gl_stencil_index8, width, height); glframebufferrenderbuffer(gl_framebuffer, gl_stencil_attachment, gl_renderbuffer, stencilbufferid);
does stencil texture have have special properties (solid colour, internal format...etc)? opengl es 2.0 not have stencil textures. have utilize renderbuffer stencil attachment, shown in code fragment above. gl_stencil_index8
format supported renderbuffers can used stencil attachment. es 3.0 supports depth/stencil textures.
maybe. 1 thing looks odd never apply stencil test in code shown. while enable stencil test, utilize gl_always
, gl_never
stencil function. names suggest, these functions either or never pass stencil test. don't allow fragments pass/fail depending on stencil value. have expected before sec draw call:
glstencilfunc(gl_equal, 1, 1); glstencilop(gl_keep, gl_keep, gl_keep);
this render fragments current stencil buffer value 1, corresponds fragments rendered previous draw call.
ios objective-c opengl-es opengl-es-2.0 stencil-buffer
No comments:
Post a Comment