Thanks for the responses. Another follow up question on MakeImageSnapshot,
I am getting Alpha Channel in output image of MakeImageSnapshot as 0xFF whereas i expect it to be same as it was in render texture, Is this expectation correct?
canvas->clear(SK_ColorTransparent); // Clears RGBA to zeros on full render texture
SkPaint clearPaint;
clearPaint.setColor(SK_ColorRED);
canvas->drawRect(bounds(), clearPaint); // Draws partial section of rendertexture with red color (R- 0xFF, A- 0xFF
sk_sp<SkImage> image = canvas->getSurface()->makeImageSnapshot();
sk_sp<SkShader> imageShader = image->makeShader(SkSamplingOptions(SkFilterMode::kNearest, SkMipmapMode::kNone));
const char* src =
"uniform shader input;"
"half4 main(float2 coord) {"
"half4 red = float4(1.0, 0.0, 0.0, 1.0);"
"half4 green = float4(0.0, 1.0, 0.0, 1.0);"
"half4 color = sample(input).rgba;"
"if(color.r < 0.5)" // Comparing R channel values
" return red;"
"else"
" return green;"
"}";
Above shader correctly renders partial area (where red was drawn with drawrect) 'Green' and remaining Red. But If i change the highlighted line (in Bold) above to following:
"if(color.a < 0.5)" // Comparing R channel values
Then shader renders full Green as if full image has Alpha channel > 0.5.
Please assist if there is any way to change some image color type/alpha type so that Alpha channels in output of makeImageSnapshot() are same as in render texture (canvas->getSurface()).
Regards
Harish