How can I use my custom shader with Skia?

620 views
Skip to first unread message

Cho Yong-Deok

unread,
Nov 23, 2015, 1:48:28 AM11/23/15
to skia-discuss
Hi :D

I want to use my custom shader with Skia.
So, I draw something in my skia surface(GL backend), get the texture-handle, and draw with my shader and gl calls.
but it doesn't work. It draws nothing. nothing in skia's texture. but GL calls works fine.
I read some discussions on this group. I'm trying to follow some solutions about this, but failed.
this is my pseudo code.


mySurface = SkSurface::newSurface(); // create GL backend surface.
myCanvas = mySurface->getCanvas();

// draw something in myCanvas.

myCanvas->flush();

texID = mySurface->getTextureHandle();

// draw texture with my custom shader and gl calls.

context->resetContext();


Is it possible to get texture from skia surface and draw with my custom shader?

Thanks,
Yong-Deok.


Jona

unread,
Dec 28, 2015, 11:58:32 AM12/28/15
to skia-discuss
I use the following to do a shader from a GPU backed surface.

SkShader* SurfaceView::getEraserShader()

{

    if (!mpEraserShader)

    {

        SkSurface *pSurface = ....;

        if (pSurface)

        {

            SkCanvas *pCanvas = pSurface->getCanvas();

            if (pCanvas)

            {

                // Draw stuff...

                

                pCanvas->flush();

            }

            

            SkImage *pBackground = pSurface->newImageSnapshot(SkSurface::kNo_Budgeted);

            if (pBackground)

            {

                mpEraserShader = pBackground->newShader(SkShader::TileMode::kClamp_TileMode,

                                                 SkShader::TileMode::kClamp_TileMode);

                

                SkSafeUnref(pBackground);

            }

            

            delete pSurface;

        }

    }

    

    return SkSafeRef(mpEraserShader);

}

Reply all
Reply to author
Forward
0 new messages