how to get texture in webgl?without Canvas.toDataUrl()

我们两清 提交于 2019-12-13 04:49:00

问题


I want to get texture from webgl just like i can use getImageData()when the canvas context is 2d.
how can i get texture form webgl context?


回答1:


I know three possibilities. Important! For all these methods you must set preserveDrawingBuffer = true with webgl.

To data url

First one is high level method toDataURL and its origin is javascript

canvas.toDataURL(type, encoderOptions);

You can use this for example if you want to allow your client to do some app "screenshot"

Following two methods are low level and its origin is webgl. You can use them if you want to for example modify texture or calculate new texture (shadows).

5.14.12 Reading back pixels

Pixels in the current framebuffer can be read back into an ArrayBufferView object.

void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView? pixels)

5.14.8 Texture objects

Texture objects provide storage and state for texturing operations ...

void texImage2D(GLenum target, GLint level, GLenum internalformat, GLint border, GLenum format, GLenum type, HTMLCanvasElement element)



来源:https://stackoverflow.com/questions/29813005/how-to-get-texture-in-webglwithout-canvas-todataurl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!