nicolasgramlich / AndEngine

Free Android 2D OpenGL Game Engine
http://www.andengine.org
Apache License 2.0
3.17k stars 1.35k forks source link

ClipEntity nesting does not work #219

Closed nazgee closed 11 years ago

nazgee commented 11 years ago

There is a problem when ClipEntities are being nested- it is caused by not restoring glScissor rect properly (test bit is restored, scissor rect is not).

It can be solved by:

            /* Draw children, etc... */
            super.onManagedDraw(pGLState, pCamera);

I have this stack currently sitting static in my ClipEntity just to prove that it works, but I'm guessing that it should be kept in GLState like this:

public void applyScissors(ScissorData pScissorData) {
   mScissorsStack.push(pScissorData);
   GLES20.glScissor(pScissorData.minX, pScissorData.minY, pScissorData.width, pScissorData.height);
}

public void restoreScissors() {
    mScissorsStack.pop();
    if (!mScissorsStack.isEmpty()) {
        ScissorData oldScissor = mScissorsStack.peek();
        GLES20.glScissor(oldScissor.minX, oldScissor.minY, oldScissor.width, oldScissor.height);
    }
}

If there is something you're willing to pull- let me know. If that's something you want to fix on your own- please do :)

nazgee commented 11 years ago

This is just a prof of concept (works fine): SHA1: d1c25deaaa6717d1ae0f36adcc3c5660f9d952b5

As I said before- I will prepare a fix in GLState if you don't mind... I'm just not sure how scissor rect should be stored. I am not convinced about pulling in new ScissorData class for this purpose

nicolasgramlich commented 11 years ago

Looks good. I'd like to pipe it through the GLState so it's just like pushing and popping the GL matrices (as opposed to the static Stack).

nazgee commented 11 years ago

LOL... I was trying to forge using github API... let me clean this mess (or I'll give up and file a pull request)

nazgee commented 11 years ago

If you want regular Stack and new data-object to hold scissor rect- let me know.

nicolasgramlich commented 11 years ago

Looks good will merge asap after a closer look tonight.

nazgee commented 11 years ago

TIA

nazgee commented 11 years ago

turned out to be not that good as it looked on the first sight?

nazgee commented 11 years ago

:-1: Still not good, but you probably already know it. It correctly restores clipping, so it is better, but it also should take a union of previous clip settings...

nazgee commented 11 years ago

:+1: if you need it squashed into single commit, instead of these two, let me know.

initial conrtibution: f878887c42adcb55157e41a61922e0969ff9a591 addition of union: 73276bd8818e15d14f29980d689d511ec97bee85

nazgee commented 11 years ago

This is how embedding ClipEntities is working in "real life": http://www.youtube.com/watch?v=TVry3gB-Eqo It just works :-)