void PMaterialParameter::upload(PGlShader              *shader,
                                PRenderTransform       *transform, 
                                PCamera                *camera, 
                                const PRenderLightQueue &lights)
{
    PASSERT_NOTREACHABLE("PMaterialParameter doesn't use this upload().");
}
Ejemplo n.º 2
0
void PGlState::setCull(PGlStateEnum mode)
{
    if (m_cull == mode)
    {
        return;
    }

    m_cull = mode;

    switch (puint32(mode))
    {
        case P_GLCULL_NONE:
            glDisable(GL_CULL_FACE);
            break;
        case P_GLCULL_BACK:
            glEnable(GL_CULL_FACE);
            glCullFace(GL_BACK);
            break;
        case P_GLCULL_FRONT:
            glEnable(GL_CULL_FACE);
            glCullFace(GL_FRONT);
            break;
        default:
            PASSERT_NOTREACHABLE("Unknown cull mode");
            break;
    }
}
Ejemplo n.º 3
0
void PCamera::setViewport(pfloat32 x, pfloat32 y, pfloat32 width, pfloat32 height)
{
    m_viewport = pVector4(x, y, width, height);

    switch (m_projection.projection())
    {
        case P_PROJECTION_PERSPECTIVE:
            {
                pfloat32 aspect = width / height;
                m_projection.perspective(m_projection.fov(), 
                                         aspect, 
                                         m_projection.zNear(), 
                                         m_projection.zFar());
            }
            break;
        case P_PROJECTION_ORTHOGONAL:
            {
                pfloat32 aspect = width / height;
                m_projection.orthogonal(aspect, 
                                        m_projection.zNear(), 
                                        m_projection.zFar());
            }
            break;
        case P_PROJECTION_WINDOW:
            m_projection.window(width, height);
            break;
        default:
            PASSERT_NOTREACHABLE("Unknown projection type.");
            break;
    }
}
Ejemplo n.º 4
0
void PBackground::setLayout(puint32 layout)
{
    if (m_layout == layout)
    {
        return ;
    }

    m_layout = layout;

    switch ((layout & 0xf0))
    {
        case LAYOUT_LEFT:
            m_sizeInfo[2] = 0;
            break;
        case LAYOUT_CENTER:
            m_sizeInfo[2] = (1.0f - m_sizeInfo[0]) * 0.5f;
            break;
        case LAYOUT_RIGHT:
            m_sizeInfo[2] = 1.0f - m_sizeInfo[0];
            break;
        default:
            PASSERT_NOTREACHABLE("Unknown background layout value.");
            break;
    }
    
    switch ((layout & 0x0f))
    {
        case LAYOUT_TOP:
            m_sizeInfo[3] = 1.0f - m_sizeInfo[1];
            break;
        case LAYOUT_MIDDLE:
            m_sizeInfo[3] = (1.0f - m_sizeInfo[1]) * 0.5f;
            break;
        case LAYOUT_BOTTOM:
            m_sizeInfo[3] = 0;
            break;
        default:
            PASSERT_NOTREACHABLE("Unknown background layout value.");
            break;
    }

    m_dirty = true;
}
Ejemplo n.º 5
0
void PNetworkServer::update()
{
    if (m_state == NETWORK_CONNECTED)
    {
        pint32 ret;
        while ((ret = enet_host_service(m_data->server, &m_data->event, P_NETWORK_POLL_TIME)) > 0)
        // FIXME: why enet_host_check_events doesn't work as enet_host_service()?
        //while ((ret = enet_host_check_events(m_data->server, &m_data->event)) > 0)
        {
            switch (m_data->event.type)
            {
                case ENET_EVENT_TYPE_CONNECT:
                    {
                        puint32 id = m_nextId++;
                        PNetworkPeer *peer = onPeerConnected(id);
                        if (peer != P_NULL)
                        {
                            m_peers.insert(id, peer);
                            peer->data()->peer = m_data->event.peer;
                        }
                        m_data->event.peer->data = PNEW(puint32);
                        *(puint32*)(m_data->event.peer->data) = id;
                    }
                    break;
                case ENET_EVENT_TYPE_RECEIVE:
                    {
                        puint32 id = *(puint32*)(m_data->event.peer->data);
                        PMap<puint32, PNetworkPeer*>::iterator it = m_peers.find(id);
                        if (it != m_peers.end())
                        {
                            onMessageReceived(it.value(), (const puint8 *)(m_data->event.packet->data), 
                                m_data->event.packet->dataLength);
                        }
                        else
                        {
                            PLOG_ERROR("Failed to find network connection %d.", id);
                        }
                        enet_packet_destroy (m_data->event.packet);
                    }
                    break;
                case ENET_EVENT_TYPE_DISCONNECT:
                    {
                        puint32 id = *(puint32*)(m_data->event.peer->data);
                        PMap<puint32, PNetworkPeer*>::iterator it = m_peers.find(id);
                        if (it != m_peers.end())
                        {
                            onPeerDisconnected(it.value());
                            PDELETE(it.value());
                            m_peers.erase(it);
                            puint32 *tmp = (puint32*)(m_data->event.peer->data);
                            PDELETE(tmp);
                        }
                        else
                        {
                            PLOG_ERROR("Failed to find network connection %d.", id);
                        }
                    }
                    break;
                default:
                    PASSERT_NOTREACHABLE("Unknown server side event.");
                    break;
            }
        }

        if (ret < 0)
        {
            m_state = NETWORK_ERROR;
        }
    }
}
Ejemplo n.º 6
0
pbool PCamera::unpack(const PXmlElement* xmlElement)
{
    if (PNode::unpack(xmlElement))
    {
        // When the aspect, width or height of the projection is left to be default value,
        // we need to explicitly set them.
        const puint32 *rect = scene()->viewport();
        if (m_projection.projection() == P_PROJECTION_ORTHOGONAL)
        {
            if (m_projection.aspect() < 0)
            {
                pfloat32 aspect = ((pfloat32)rect[2] / (pfloat32)rect[3]);
                m_projection.orthogonal(aspect, m_projection.zNear(), m_projection.zFar());
            }
        }
        else if (m_projection.projection() == P_PROJECTION_PERSPECTIVE)
        {
            if (m_projection.aspect() < 0)
            {
                pfloat32 aspect = ((pfloat32)rect[2] / (pfloat32)rect[3]);
                m_projection.perspective(m_projection.fov(), aspect, m_projection.zNear(), m_projection.zFar());
            }
        }
        else if (m_projection.projection() == P_PROJECTION_WINDOW)
        {
            if (m_projection.width() < 0 || m_projection.height())
            {
                m_projection.window((pfloat32)rect[2], (pfloat32)rect[3]);
            }
        }
        else
        {
            PASSERT_NOTREACHABLE("Unknown projection type.");
        }

        // See if there is any lookat attribute and the transform attribute is not used.
        // In this case, the lookat property will be used to set the transform the camera.
        const pchar *lookatValue = xmlElement->attribute("lookat");
        const pchar *transformValue = xmlElement->attribute("transform");
        if (lookatValue != P_NULL && transformValue == P_NULL)
        {
            const pchar *p = lookatValue;

            pfloat32 eyex, eyey, eyez;
            pfloat32 centerx, centery, centerz;
            pfloat32 upx, upy, upz;

            if ((p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
                (p = pStringUnpackFloat(p, &eyex)) != P_NULL &&
                (p = pStringUnpackFloat(p, &eyey)) != P_NULL &&
                (p = pStringUnpackFloat(p, &eyez)) != P_NULL &&
                (p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
                (p = pStringUnpackFloat(p, &centerx)) != P_NULL &&
                (p = pStringUnpackFloat(p, &centery)) != P_NULL &&
                (p = pStringUnpackFloat(p, &centerz)) != P_NULL &&
                (p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
                (p = pStringUnpackFloat(p, &upx)) != P_NULL &&
                (p = pStringUnpackFloat(p, &upy)) != P_NULL &&
                (p = pStringUnpackFloat(p, &upz)) != P_NULL)
            {
                m_localTransform.setLookAt(eyex, eyey, eyez,
                                           centerx, centery, centerz,
                                           upx, upy, upz);
            }
            else
            {
                PLOG_ERROR("The camera %s has a valid lookat property in the xml node.", m_name.toString().c_str());
            }
        }

        return true;
    }

    return false;
}