I have a class and this extend from Sprite, this class init with texture.
I update the texture with data(buffer video) in a loop.
I don’t know if this is correct, but workly…
If anyone can advise me alternative method, i appreciate.
Perhaps show us what you have done thus far…
Example:
Player.h
class VideoPlayer : public cocos2d::Sprite { public: ~VideoPlayer(); static VideoPlayer* create(cocos2d::Size size); void play(const std::string &path, bool repeat = true); char *m_videobuf;
Player.cpp
VideoPlayer *VideoPlayer::create(Size size) { auto player = new VideoPlayer; if(player && player->init(size)) { player->autorelease(); } else { CC_SAFE_DELETE(player); } return player; } bool VideoPlayer::init(Size &size) { m_videobuf = (char *)malloc((width * height) << 2); memset(m_videobuf, 0, (width * height) << 2); ... Texture2D *texture = new Texture2D(); texture->initWithData(m_videobuf, (width * height) << 2, PixelFormat::RGBA8888, width, height, size); texture->autorelease(); initWithTexture(texture); scheduleUpdate(); return true; } void VideoPlayer::update(float dt) { _texture->updateWithData(m_videobuf, 0, 0, width, height); }
Alternative for draw texture? Shaders or by GPU?!
I think is heavy for CPU… or not? Thanks.
How i can render texture data(m_videobuf) on gpu like shader?! I try with customcommand, read guide but not understand this phase…
I don’t think you can render more effective via gpu or shader: first of all - you need to turn your videofile frame buffer into texture and then upload this texture into vram. I think this step is unavoidable. One thing you can optimise in your videoplayer class, is to call _texture->updateWithData only when video data is really changed, f.e. video has 30 fps or even 15, but you transferring same data every 1/60 sec.
Thanks for the advice!