void CCDirectRenderer::drawRenderPass(DrawingFrame& frame, const CCRenderPass* renderPass)
{
    if (!useRenderPass(frame, renderPass))
        return;

    frame.scissorRectInRenderPassSpace = frame.currentRenderPass->outputRect();
    if (frame.rootDamageRect != frame.rootRenderPass->outputRect()) {
        WebTransformationMatrix inverseTransformToRoot = frame.currentRenderPass->transformToRootTarget().inverse();
        frame.scissorRectInRenderPassSpace.intersect(CCMathUtil::projectClippedRect(inverseTransformToRoot, frame.rootDamageRect));
    }

    enableScissorTestRect(moveScissorToWindowSpace(frame, frame.scissorRectInRenderPassSpace));
    clearFramebuffer(frame);

    const CCQuadList& quadList = renderPass->quadList();
    for (CCQuadList::constBackToFrontIterator it = quadList.backToFrontBegin(); it != quadList.backToFrontEnd(); ++it) {
        FloatRect quadScissorRect = frame.scissorRectInRenderPassSpace;
        quadScissorRect.intersect(it->get()->clippedRectInTarget());
        if (!quadScissorRect.isEmpty()) {
            enableScissorTestRect(moveScissorToWindowSpace(frame, quadScissorRect));
            drawQuad(frame, it->get());
        }
    }

    CachedTexture* texture = m_renderPassTextures.get(renderPass->id());
    if (texture)
        texture->setIsComplete(!renderPass->hasOcclusionFromOutsideTargetSurface());
}
예제 #2
0
파일: main.cpp 프로젝트: gustavoem/bcc
void display (void)
{
    int i;
    int j;
    clearFramebuffer ();
    for (i = 0;i < ImageH; i++)
    {
        for (j = 0; j < ImageW; j++)
        {
            rayCast (i, j);
        }
    }
    drawit ();
}
예제 #3
0
void init(void)
{
    clearFramebuffer();
}
예제 #4
0
파일: main.cpp 프로젝트: gustavoem/bcc
void init (void)
{
    eye.x = 400;
    eye.y = 400;
    eye.z = 0;

    if (state == 0)
    {
        // Sphere 1
        Color color;
        color.r = 0;
        color.g = 1;
        color.b = 1;
        R3Vector center;
        center.x = 100;
        center.y = 100;
        center.z = FILM_WALL_Z + 200;
        Material material;
        material.k_a = 0.2;
        material.k_d = 0.3;
        material.k_s = 0.6;
        material.n = 100;
        material.k_r = 0.1;
        Sphere * sphere1 = new Sphere (center, 100, color, material);
        objs.push_back (sphere1);

        color.r = 1;
        color.g = 1;
        color.b = 1;
        center.y = 50;
        center.z = FILM_WALL_Z + 400;
        center.x = 400;
        material.k_a = 0.5;
        material.k_d = 0.0;
        material.k_s = 0;
        material.n = 10;
        material.k_r = 0.0;
        Sphere * sphere2 = new Sphere (center, 50, color, material);
        objs.push_back (sphere2);

        center.x = 500;
        material.k_a = 0.4;
        material.k_d = 0.5;
        material.k_s = 0.0;
        material.n = 10;
        material.k_r = 0.0;
        Sphere * sphere3 = new Sphere (center, 50, color, material);
        objs.push_back (sphere3);

        center.x = 600;
        material.k_a = 0.4;
        material.k_d = 0.5;
        material.k_s = 0.5;
        material.n = 10;
        material.k_r = 0.0;
        Sphere * sphere4 = new Sphere (center, 50, color, material);
        objs.push_back (sphere4);

        center.x = 700;
        material.k_a = 0.4;
        material.k_d = 0.5;
        material.k_s = 0.5;
        material.n = 10;
        material.k_r = 0.5;
        Sphere * sphere5 = new Sphere (center, 50, color, material);
        objs.push_back (sphere5);


        // Walls
        color.r = .7;
        color.g = .7;
        color.b = .7;
        center.x = 0;
        center.y = 0;
        center.z = FILM_WALL_Z;
        material.k_a = 0.3;
        material.k_d = 0.7;
        material.k_s = 0;
        R3Vector normal;
        normal.x = 1;
        normal.y = 0;
        normal.z = 0;
        material.n = 2;
        material.k_r = 0;
        // left plane
        Plane * plane1 = new Plane (center, color, material, normal);
        objs.push_back (plane1);
        
        // floor plane
        normal.x = 0;
        normal.y = 1;
        normal.z = 0;
        Plane * plane2 = new Plane (center, color, material, normal);
        objs.push_back (plane2);
        
        center.x = 800;
        center.y = 800;
        
        // ceiling
        normal.x = 0;
        normal.y = -1;
        normal.z = 0;
        Plane * plane3 = new Plane (center, color, material, normal);
        objs.push_back (plane3);

        // right plane
        normal.x = -1;
        normal.y = 0;
        normal.z = 0;
        Plane * plane4 = new Plane (center, color, material, normal);
        objs.push_back (plane4);

        // back plane
        material.k_r = 1;
        material.k_a = 0;
        material.k_d = 0;
        material.k_s = 0;
        center.z = FILM_WALL_Z + 1000;
        normal.x = 0;
        normal.y = 0;
        normal.z = -1;
        Plane * plane5 = new Plane (center, color, material, normal);
        objs.push_back (plane5);
        material.k_r = 0;

        // Light
        color.r = 255 / 255;
        color.g = 214.0 / 255;
        color.b = 170.0 / 255;
        center.x = 400;
        center.y = 790;
        center.z = FILM_WALL_Z + 100;
        material.k_a = 1;
        material.k_d = 0;
        material.k_s = 0;
        Light * light1 = new Light (center, color);
        lights.push_back (light1);
        objs.push_back (light1);

        color.r = 0.5;
        color.g = 70.0 / 255;
        color.b = 0;
        center.x = 400;
        center.y = 20;
        center.z = FILM_WALL_Z;
        material.k_a = 2;
        material.k_d = 0;
        material.k_s = 0;
        Light * light2 = new Light (center, color);
        lights.push_back (light2);
        objs.push_back (light2);

    }
    else
    {
        Color color;
        R3Vector center;
        center.x = 0;
        center.y = 0;
        center.z = FILM_WALL_Z;
        Material material;
        material.k_a = 0;
        material.k_d = .1;
        material.k_s = .1;
        material.k_r = .7;
        material.n = 2;
        R3Vector normal;
        
        // floor
        color.r = 0;
        color.g = 1;
        color.b = 0;
        normal.x = 0;
        normal.y =  1;
        normal.z = 0;
        Plane * plane2 = new Plane (center, color, material, normal);
        objs.push_back (plane2);

        // right plane
        center.x = 400;
        center.y = 800 * (sqrt (3) / 2);
        color.r = 0;
        color.g = 0;
        color.b = 1;
        normal.x = -sqrt (3);
        normal.y =  -1;
        normal.z = 0;
        normalize (&normal);
        Plane * plane3 = new Plane (center, color, material, normal);
        objs.push_back (plane3);
        
        // left plane
        color.r = 1;
        color.g = 0;
        color.b = 0;
        normal.x = sqrt (3);
        normal.y =  -1;
        normal.z = 0;
        normalize (&normal);
        Plane * plane1 = new Plane (center, color, material, normal);
        objs.push_back (plane1);


        // bacl plane
        color.r = .8;
        color.g = .8;
        color.b = .8;

        material.k_r = 0;
        material.k_a = 1;
        material.k_d = 0;
        material.k_s = 0;
        center.z = FILM_WALL_Z + 5000;
        normal.x = 0;
        normal.y = 0;
        normal.z = -1;
        Plane * plane5 = new Plane (center, color, material, normal);
        objs.push_back (plane5);
        material.k_r = 0;

        color.r = 1;
        color.g = 0;
        color.b = 0;
        center.x = 400;
        center.y = 800 * (sqrt (3) / 4) + 50;
        center.z = FILM_WALL_Z + 4900;
        material.k_a = 1;
        material.k_d = 0.6;
        material.k_s = 0.6;
        material.n = 3;
        material.k_r = 0;
        Sphere * sphere1 = new Sphere (center, 100, color, material);
        objs.push_back (sphere1);

        color.r = 0;
        color.g = 1;
        color.b = 0;
        center.x = 400 - 100;
        center.y = 800 * (sqrt (3) / 4) - 100;
        center.z = FILM_WALL_Z + 4900;
        material.k_a = 1;
        material.k_d = 0.6;
        material.k_s = 0.6;
        material.n = 3;
        material.k_r = 0;
        Sphere * sphere2 = new Sphere (center, 100, color, material);
        objs.push_back (sphere2);

        color.r = 0;
        color.g = 0;
        color.b = 1;
        center.x = 400 + 100;
        center.y = 800 * (sqrt (3) / 4) - 100;
        center.z = FILM_WALL_Z + 4900;
        material.k_a = 1;
        material.k_d = 0.6;
        material.k_s = 0.6;
        material.n = 3;
        material.k_r = 0;
        Sphere * sphere3 = new Sphere (center, 100, color, material);
        objs.push_back (sphere3);

        // Light
        color.r = 0.3;
        color.g = 0.3;
        color.b = 0.3;
        center.x = 400;
        center.y = 800 * (sqrt (3) / 4);
        center.z = FILM_WALL_Z - 4900;
        material.k_a = 1;
        material.k_d = 0;
        material.k_s = 0;
        Light * light1 = new Light (center, color);
        lights.push_back (light1);
        objs.push_back (light1);
    }

    Color color;
    R3Vector center;
    color.r = 1;
    color.g = 1;
    color.b = 1;
    center.x = 400;
    center.y = 0;
    center.z = 0;
    ambient_light = new Light (center, color);
    clearFramebuffer ();
}
예제 #5
0
bool DrawingBuffer::reset(const IntSize& newSize)
{
#if 0
    if (!m_context)
        return false;

    m_context->makeContextCurrent();

    int maxTextureSize = 0;
    m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize);
    if (newSize.height() > maxTextureSize || newSize.width() > maxTextureSize) {
      clear();
      return false;
    }

    const GraphicsContext3D::Attributes& attributes = m_context->getContextAttributes();

    if (newSize != m_size) {
        m_size = newSize;

        unsigned long internalColorFormat, colorFormat, internalRenderbufferFormat;
        if (attributes.alpha) {
            internalColorFormat = GraphicsContext3D::RGBA;
            colorFormat = GraphicsContext3D::RGBA;
            internalRenderbufferFormat = Extensions3D::RGBA8_OES;
        } else {
            internalColorFormat = GraphicsContext3D::RGB;
            colorFormat = GraphicsContext3D::RGB;
            internalRenderbufferFormat = Extensions3D::RGB8_OES;
        }


        // resize multisample FBO
        if (multisample()) {
            int maxSampleCount = 0;
            
            m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
            int sampleCount = std::min(8, maxSampleCount);

            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);

            m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
            m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height());
            m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
            resizeDepthStencil(sampleCount);
            if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
                // Cleanup
                clear();
                return false;
            }
        }

        // resize regular FBO
        m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);

        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
        
        m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE);

        m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);

        if (!multisample())
            resizeDepthStencil(0);
        if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
            // Cleanup
            clear();
            return false;
        }
    }

    clearFramebuffer();

    didReset();

#endif
    return true;
}
예제 #6
0
bool DrawingBuffer::reset(const IntSize& newSize)
{
    if (!m_context)
        return false;

    m_context->makeContextCurrent();

    int maxTextureSize = 0;
    m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize);
    if (newSize.height() > maxTextureSize || newSize.width() > maxTextureSize) {
        clear();
        return false;
    }

    int pixelDelta = newSize.width() * newSize.height();
    int oldSize = 0;
    if (!m_size.isEmpty()) {
        oldSize = m_size.width() * m_size.height();
        pixelDelta -= oldSize;
    }

    IntSize adjustedSize = newSize;
    if (s_maximumResourceUsePixels) {
        while ((s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUsePixels) {
            adjustedSize.scale(s_resourceAdjustedRatio);
            if (adjustedSize.isEmpty()) {
                clear();
                return false;
            }
            pixelDelta = adjustedSize.width() * adjustedSize.height();
            pixelDelta -= oldSize;
        }
     }

    const GraphicsContext3D::Attributes& attributes = m_context->getContextAttributes();

    if (adjustedSize != m_size) {

        unsigned internalColorFormat, colorFormat, internalRenderbufferFormat;
        if (attributes.alpha) {
            internalColorFormat = GraphicsContext3D::RGBA;
            colorFormat = GraphicsContext3D::RGBA;
            internalRenderbufferFormat = Extensions3D::RGBA8_OES;
        } else {
            internalColorFormat = GraphicsContext3D::RGB;
            colorFormat = GraphicsContext3D::RGB;
            internalRenderbufferFormat = Extensions3D::RGB8_OES;
        }


        do {
            m_size = adjustedSize;
            // resize multisample FBO
            if (multisample()) {
                int maxSampleCount = 0;

                m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
                int sampleCount = std::min(4, maxSampleCount);

                m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);

                m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
                m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height());
                m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
                resizeDepthStencil(sampleCount);
                if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
                    adjustedSize.scale(s_resourceAdjustedRatio);
                    continue;
                }
            }

            // resize regular FBO
            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);

            m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
            m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);

            m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);

            // resize the backing color buffer
            if (m_separateBackingTexture) {
                m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer);
                m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
            }

            m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);

            if (!multisample())
                resizeDepthStencil(0);
            if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE)
                break;
            adjustedSize.scale(s_resourceAdjustedRatio);

        } while (!adjustedSize.isEmpty());

        pixelDelta = m_size.width() * m_size.height();
        pixelDelta -= oldSize;
        s_currentResourceUsePixels += pixelDelta;

        if (!newSize.isEmpty() && adjustedSize.isEmpty()) {
            clear();
            return false;
        }
    }

    clearFramebuffer();

    return true;
}