Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering Target Node - Rendering to texture made simpler. #231

Closed
wants to merge 1 commit into from
Closed

Rendering Target Node - Rendering to texture made simpler. #231

wants to merge 1 commit into from

Conversation

krzysztofzablocki
Copy link

Problem

CCRenderTexture is abused by many people, people get confused how to render properly into it, like overriding visit methods, mostly because not all cocos nodes are easy to use with CCRenderTexture:

  • CCSpriteBatchNode cannot be visited if it's not inside scene tree, if you add it to scene tree and then call [batch visit] between begin and end of RenderTexture rendering you are rendering twice. That's just wrong. You could 'fix' it by hiding the batch at start and then make it visible just before visiting it inside your renderTexture redraw. I still believe that's far from nice solution.
  • Animations are _paused if nodes are not in scene node, again could be 'fixed' as in previous point.

'fixed' - means workaround and in my book is really poor.

Solution

Added CCRenderTargetNode - a node that simplifies rendering into CCRenderTexture.

  • Whatever you add into it, will be rendered into CCRenderTexture and only there.
  • Animations will work since nodes will be in scene tree, batches will work as well. No hacking required and only 1 rendering.
  • CCRenderTexture has lazy created .renderTargetNode property that can be used for adding renderTexture content nodes into it, they will be rendered into RenderTexture and only there.
  • ( Also it could be used to render into CCRenderTexture that's not in scene tree ( if you'd need that kind of functionality ), you can plainly create it with RenderTexture but you need to retain RenderTexture by yourself so that it doesn't get released before this node. )

@Panajev
Copy link
Contributor

Panajev commented Aug 20, 2012

It looks really interesting. It does remove a few roadblocks to CCRenderTexture.

@ricardoquesada
Copy link
Contributor

I like. Scheduled for v2.1

@ricardoquesada
Copy link
Contributor

I sort of merged it it.
What I did was to add the CCTargetRenderNode behavior in CCRenderTexture.
For some reason, it is not working properly now... working on the fix.

@krzysztofzablocki
Copy link
Author

It probably doesn't work because you should call visit on the children ( in renderTexture visit method ) when auto-draw mode is turned off.

I designed it this way ( as separate target node ) because it allows you to have more control over it, yet it's still very simple to use.

  • You could draw to offscreen render texture and make effects on it very easily.
  • You could add an overlay on top of processed texture content (as a child of render texture) and have it drawn standard way, yet still have some fancy effects in renderTexture content.
    etc.

@ricardoquesada
Copy link
Contributor

Thanks.
Yes, I am calling visit on the children. The bug is that for some reason the transformations applied to RenderTexture are not inherited by its children... I found an ugly workaround, but I am trying to figure out the cause of the bug...

CCRenderTargetNode is easy to use, and I like it. What I don't like is to have 3 different nodes with similar features:

  • CCGrabber:
  • CCRenderTexture
  • CCRenderTargetNode

Which one should you use and when ? It is not clear for the user. I think it is confusing. That's why I merged CCRenderTexture and CCRenderTargetNode.

@Panajev
Copy link
Contributor

Panajev commented Oct 9, 2012

Would the other patch related to viewport and model view transforms in begin and end do any good to the bug you see now @riq?

[web [iPhone msg]]

On 09/ott/2012, at 17:48, Ricardo Quesada [email protected] wrote:

Thanks.
Yes, I am calling visit on the children. The bug is that for some reason the transformations applied to RenderTexture are not inherited by its children... I found an ugly workaround, but I am trying to figure out the cause of the bug...

CCRenderTargetNode is easy to use, and I like it. What I don't like is to have 3 different nodes with similar features:

CCGrabber:
CCRenderTexture
CCRenderTargetNode
Which one should you use and when ? It is not clear for the user. I think it is confusing. That's why I merged CCRenderTexture and CCRenderTargetNode.


Reply to this email directly or view it on GitHub.

@krzysztofzablocki
Copy link
Author

@ricardoquesada there is still a mistake because currently code in repository is calling [children visit] in draw method but ONLY if you have autodraw enabled. You still need to visit children if you don't have autodraw enabled ( default ) or you break backward compatibility

@ricardoquesada
Copy link
Contributor

@Panajev: Mmm... yes, perhaps.

@krzysztofzablocki: Thanks. What I am doing instead is calling [sprite visit], which works in 99% percent of the cases. But as you mentioned, CCRenderTexture could have other children as well

@Panajev
Copy link
Contributor

Panajev commented Oct 9, 2012

@ricardoquesada it might not solve the issue, that I do not know for sure,
but I think it should at least provide an even cleaner foundation to
explore the issue you are experiencing.

On Tue, Oct 9, 2012 at 8:06 PM, Ricardo Quesada [email protected]:

@Panajev https://github.com/Panajev: Mmm... yes, perhaps.

@krzysztofzablocki https://github.com/krzysztofzablocki: Thanks. What I
am doing instead is calling [sprite visit], which works in 99% percent of
the cases. But as you mentioned, CCRenderTexture could have other
children as well


Reply to this email directly or view it on GitHubhttps://github.com//pull/231#issuecomment-9272588.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants