Пример #1
0
/*************************************************************************
	render a quad directly to the display
*************************************************************************/
void DirectX9Renderer::renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode)
{
	// ensure offset destination to ensure proper texel to pixel mapping from D3D.
	Rect final_rect(dest_rect);
	final_rect.offset(Point(-0.5f, -0.5f));

	QuadVertex*	buffmem;

	initPerFrameStates();
	d_device->SetTexture(0, ((DirectX9Texture*)tex)->getD3DTexture());

	if (SUCCEEDED(d_buffer->Lock(0, VERTEX_PER_QUAD * sizeof(QuadVertex), (void**)&buffmem, D3DLOCK_DISCARD)))
	{
		// setup Vertex 1...
		buffmem->x = final_rect.d_left;
		buffmem->y = final_rect.d_top;
		buffmem->z = z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = colours.d_top_left.getARGB();
		buffmem->tu1 = texture_rect.d_left;
		buffmem->tv1 = texture_rect.d_top;
		++buffmem;

        // setup Vertex 2...

        // top-left to bottom-right diagonal
        if (quad_split_mode == TopLeftToBottomRight)
        {
            buffmem->x = final_rect.d_right;
            buffmem->y = final_rect.d_bottom;
            buffmem->z = z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = colours.d_bottom_right.getARGB();
            buffmem->tu1 = texture_rect.d_right;
            buffmem->tv1 = texture_rect.d_bottom;
        }
        // bottom-left to top-right diagonal
        else
        {
            buffmem->x = final_rect.d_right;
            buffmem->y = final_rect.d_top;
            buffmem->z = z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = colours.d_top_right.getARGB();
            buffmem->tu1 = texture_rect.d_right;
            buffmem->tv1 = texture_rect.d_top;
        }
        ++buffmem;

		// setup Vertex 3...
		buffmem->x = final_rect.d_left;
		buffmem->y = final_rect.d_bottom;
		buffmem->z = z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = colours.d_bottom_left.getARGB();
		buffmem->tu1 = texture_rect.d_left;
		buffmem->tv1 = texture_rect.d_bottom;
		++buffmem;

		// setup Vertex 4...
		buffmem->x = final_rect.d_right;
		buffmem->y = final_rect.d_top;
		buffmem->z = z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = colours.d_top_right.getARGB();
		buffmem->tu1 = texture_rect.d_right;
		buffmem->tv1 = texture_rect.d_top;
		++buffmem;

		// setup Vertex 5...
		buffmem->x = final_rect.d_right;
		buffmem->y = final_rect.d_bottom;
		buffmem->z = z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = colours.d_bottom_right.getARGB();
		buffmem->tu1 = texture_rect.d_right;
		buffmem->tv1 = texture_rect.d_bottom;
		++buffmem;

		// setup Vertex 6...

        // top-left to bottom-right diagonal
        if (quad_split_mode == TopLeftToBottomRight)
        {
            buffmem->x = final_rect.d_left;
            buffmem->y = final_rect.d_top;
            buffmem->z = z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = colours.d_top_left.getARGB();
            buffmem->tu1 = texture_rect.d_left;
            buffmem->tv1 = texture_rect.d_top;
        }
        // bottom-left to top-right diagonal
        else
        {
            buffmem->x = final_rect.d_left;
            buffmem->y = final_rect.d_bottom;
            buffmem->z = z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = colours.d_bottom_left.getARGB();
            buffmem->tu1 = texture_rect.d_left;
            buffmem->tv1 = texture_rect.d_bottom;
        }

		d_buffer->Unlock();
		d_bufferPos = VERTEX_PER_QUAD;

		renderVBuffer();
	}

}
Пример #2
0
/*************************************************************************
	perform final rendering for all queued renderable quads.
*************************************************************************/
void DirectX9Renderer::doRender(void)
{
	d_currTexture = 0;

	initPerFrameStates();

	bool locked = false;
	QuadVertex*	buffmem;

	// iterate over each quad in the list
	for (QuadList::iterator i = d_quadlist.begin(); i != d_quadlist.end(); ++i)
	{
		const QuadInfo& quad = (*i);

		// flush & set texture if needed
		if (d_currTexture != quad.texture)
		{
			if (locked)
			{
				d_buffer->Unlock();
				locked = false;
			}

			// render any remaining quads for current texture
			renderVBuffer();

			// set new texture
			d_device->SetTexture(0, quad.texture);
			d_currTexture = quad.texture;
		}

		if (!locked)
		{
			if (FAILED(d_buffer->Lock(0, 0, (void**)&buffmem, D3DLOCK_DISCARD)))
			{
				return;
			}

			locked = true;
		}

		// setup Vertex 1...
		buffmem->x = quad.position.d_left;
		buffmem->y = quad.position.d_top;
		buffmem->z = quad.z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = quad.topLeftCol;
		buffmem->tu1 = quad.texPosition.d_left;
		buffmem->tv1 = quad.texPosition.d_top;
		++buffmem;

		// setup Vertex 2...

        // top-left to bottom-right diagonal
        if (quad.splitMode == TopLeftToBottomRight)
        {
            buffmem->x = quad.position.d_right;
            buffmem->y = quad.position.d_bottom;
            buffmem->z = quad.z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = quad.bottomRightCol;
            buffmem->tu1 = quad.texPosition.d_right;
            buffmem->tv1 = quad.texPosition.d_bottom;
        }
        // bottom-left to top-right diagonal
        else
        {
            buffmem->x = quad.position.d_right;
            buffmem->y = quad.position.d_top;
            buffmem->z = quad.z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = quad.topRightCol;
            buffmem->tu1 = quad.texPosition.d_right;
            buffmem->tv1 = quad.texPosition.d_top;
        }
        ++buffmem;

		// setup Vertex 3...
		buffmem->x = quad.position.d_left;
		buffmem->y = quad.position.d_bottom;
		buffmem->z = quad.z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = quad.bottomLeftCol;
		buffmem->tu1 = quad.texPosition.d_left;
		buffmem->tv1 = quad.texPosition.d_bottom;
		++buffmem;

		// setup Vertex 4...
		buffmem->x = quad.position.d_right;
		buffmem->y = quad.position.d_top;
		buffmem->z = quad.z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = quad.topRightCol;
		buffmem->tu1 = quad.texPosition.d_right;
		buffmem->tv1 = quad.texPosition.d_top;
		++buffmem;

		// setup Vertex 5...
		buffmem->x = quad.position.d_right;
		buffmem->y = quad.position.d_bottom;
		buffmem->z = quad.z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = quad.bottomRightCol;
		buffmem->tu1 = quad.texPosition.d_right;
		buffmem->tv1 = quad.texPosition.d_bottom;
		++buffmem;

		// setup Vertex 6...

        // top-left to bottom-right diagonal
        if (quad.splitMode == TopLeftToBottomRight)
        {
            buffmem->x = quad.position.d_left;
            buffmem->y = quad.position.d_top;
            buffmem->z = quad.z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = quad.topLeftCol;
            buffmem->tu1 = quad.texPosition.d_left;
            buffmem->tv1 = quad.texPosition.d_top;
        }
        // bottom-left to top-right diagonal
        else
        {
            buffmem->x = quad.position.d_left;
            buffmem->y = quad.position.d_bottom;
            buffmem->z = quad.z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = quad.bottomLeftCol;
            buffmem->tu1 = quad.texPosition.d_left;
            buffmem->tv1 = quad.texPosition.d_bottom;
        }
        ++buffmem;

		// update buffer level
		d_bufferPos += VERTEX_PER_QUAD;

		// if there is not enough room in the buffer for another sprite, render what we have
		if (d_bufferPos >= (VERTEXBUFFER_CAPACITY - VERTEX_PER_QUAD))
		{
			if (locked)
			{
				d_buffer->Unlock();
				locked = false;
			}

			renderVBuffer();
		}

	}

	if (locked)
	{
		d_buffer->Unlock();
		locked = false;
	}

	renderVBuffer();
}
Пример #3
0
void GuiRenderer::renderQuadDirect(const CEGUI::Rect& dest_rect, float z, const CEGUI::Texture* tex, const CEGUI::Rect& texture_rect, const CEGUI::ColourRect& colours, CEGUI::QuadSplitMode quad_split_mode)
{
    QuadInfo quad;
    quad.position.d_left    = dest_rect.d_left;
    quad.position.d_right   = dest_rect.d_right;
    quad.position.d_bottom  = _display_area.d_bottom - dest_rect.d_bottom;
    quad.position.d_top     = _display_area.d_bottom - dest_rect.d_top;
    quad.texPosition        = texture_rect;

    quad.topLeftCol     = colourToOGL(colours.d_top_left);
    quad.topRightCol    = colourToOGL(colours.d_top_right);
    quad.bottomLeftCol  = colourToOGL(colours.d_bottom_left);
    quad.bottomRightCol = colourToOGL(colours.d_bottom_right);

    MyQuad myquad[VERTEX_PER_QUAD];

    initPerFrameStates();
    glInterleavedArrays(GL_T2F_C4UB_V3F , 0, myquad);
    glBindTexture(GL_TEXTURE_2D, ((GuiTexture*)tex)->getOGLTexid());

    //vert0
    myquad[0].vertex[0] = quad.position.d_left;
    myquad[0].vertex[1] = quad.position.d_top;
    myquad[0].vertex[2] = z;
    myquad[0].color     = quad.topLeftCol;
    myquad[0].tex[0]    = quad.texPosition.d_left;
    myquad[0].tex[1]    = quad.texPosition.d_top;

    //vert1
    myquad[1].vertex[0] = quad.position.d_left;
    myquad[1].vertex[1] = quad.position.d_bottom;
    myquad[1].vertex[2] = z;
    myquad[1].color     = quad.bottomLeftCol;     
    myquad[1].tex[0]    = quad.texPosition.d_left;
    myquad[1].tex[1]    = quad.texPosition.d_bottom;

    //vert2

    // top-left to bottom-right diagonal
    if (quad_split_mode == CEGUI::TopLeftToBottomRight)
    {
        myquad[2].vertex[0] = quad.position.d_right;
        myquad[2].vertex[1] = quad.position.d_bottom;
        myquad[2].vertex[2] = z;
        myquad[2].color     = quad.bottomRightCol;
        myquad[2].tex[0]    = quad.texPosition.d_right;
        myquad[2].tex[1]    = quad.texPosition.d_bottom;
    }
    // bottom-left to top-right diagonal
    else
    {
        myquad[2].vertex[0] = quad.position.d_right;
        myquad[2].vertex[1] = quad.position.d_top;
        myquad[2].vertex[2] = z;
        myquad[2].color     = quad.topRightCol;
        myquad[2].tex[0]    = quad.texPosition.d_right;
        myquad[2].tex[1]    = quad.texPosition.d_top;
    }

    //vert3
    myquad[3].vertex[0] = quad.position.d_right;
    myquad[3].vertex[1] = quad.position.d_top;
    myquad[3].vertex[2] = z;
    myquad[3].color     = quad.topRightCol;      
    myquad[3].tex[0]    = quad.texPosition.d_right;
    myquad[3].tex[1]    = quad.texPosition.d_top;

    //vert4

    // top-left to bottom-right diagonal
    if (quad_split_mode == CEGUI::TopLeftToBottomRight)
    {
        myquad[4].vertex[0] = quad.position.d_left;
        myquad[4].vertex[1] = quad.position.d_top;
        myquad[4].vertex[2] = z;
        myquad[4].color     = quad.topLeftCol;
        myquad[4].tex[0]    = quad.texPosition.d_left;
        myquad[4].tex[1]    = quad.texPosition.d_top;
    }
    // bottom-left to top-right diagonal
    else
    {
        myquad[4].vertex[0] = quad.position.d_left;
        myquad[4].vertex[1] = quad.position.d_bottom;
        myquad[4].vertex[2] = z;
        myquad[4].color     = quad.bottomLeftCol;
        myquad[4].tex[0]    = quad.texPosition.d_left;
        myquad[4].tex[1]    = quad.texPosition.d_bottom;
    }

    //vert5
    myquad[5].vertex[0] = quad.position.d_right;
    myquad[5].vertex[1] = quad.position.d_bottom;
    myquad[5].vertex[2] = z;
    myquad[5].color     = quad.bottomRightCol;
    myquad[5].tex[0]    = quad.texPosition.d_right;
    myquad[5].tex[1]    = quad.texPosition.d_bottom;

    glDrawArrays(GL_TRIANGLES, 0, 6);

    exitPerFrameStates();
}
Пример #4
0
/*************************************************************************
	perform final rendering for all queued renderable quads.
*************************************************************************/
bool DirectX9Renderer::doRender(void)
{
	d_currTexture = NULL;

    if ( !d_buffer )
        return false;

	initPerFrameStates();

	bool locked = false;
	QuadVertex*	buffmem;

	// iterate over each quad in the list
	for (QuadList::iterator i = d_quadlist.begin(); i != d_quadlist.end(); ++i)
	{
		const QuadInfo& quad = (*i);

		LPDIRECT3DTEXTURE9 d3dTexture = quad.texture->getD3DTexture();
		// flush & set texture if needed
		if (d_currTexture != d3dTexture)
		{
			if (locked)
			{
				d_buffer->Unlock();
				locked = false;
			}

			// render any remaining quads for current texture
			renderVBuffer();

			// set new texture
			d_device->SetTexture(0, d3dTexture);
			d_currTexture = d3dTexture;
		}

		if (!locked)
		{
            buffmem = NULL;
			if (FAILED(d_buffer->Lock(0, 0, (void**)&buffmem, D3DLOCK_DISCARD)))
			{
				return false;
			}
            if ( buffmem == NULL )
			{
				return false;
			}

			locked = true;
		}

        // Hack: Inform the Font class that this glyph has been used recently, if it's a glyph being drawn
        if ( quad.image )
        {
            unsigned long ulCodepoint = quad.image->getCodepoint();
            // Is it a glyph?
            if ( ulCodepoint != 0 && ulCodepoint > 127 && ulCodepoint < 65534 )
            {
                CEGUI::Font* pFont = quad.image->getFont();
                if ( pFont )
                    pFont->refreshCachedGlyph(ulCodepoint);
            }
        }

		// setup Vertex 1...
		buffmem->x = quad.position.d_left;
		buffmem->y = quad.position.d_top;
		buffmem->z = quad.z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = quad.topLeftCol;
		buffmem->tu1 = quad.texPosition.d_left;
		buffmem->tv1 = quad.texPosition.d_top;
		++buffmem;

		// setup Vertex 2...

        // top-left to bottom-right diagonal
        if (quad.splitMode == TopLeftToBottomRight)
        {
            buffmem->x = quad.position.d_right;
            buffmem->y = quad.position.d_bottom;
            buffmem->z = quad.z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = quad.bottomRightCol;
            buffmem->tu1 = quad.texPosition.d_right;
            buffmem->tv1 = quad.texPosition.d_bottom;
        }
        // bottom-left to top-right diagonal
        else
        {
            buffmem->x = quad.position.d_right;
            buffmem->y = quad.position.d_top;
            buffmem->z = quad.z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = quad.topRightCol;
            buffmem->tu1 = quad.texPosition.d_right;
            buffmem->tv1 = quad.texPosition.d_top;
        }
        ++buffmem;

		// setup Vertex 3...
		buffmem->x = quad.position.d_left;
		buffmem->y = quad.position.d_bottom;
		buffmem->z = quad.z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = quad.bottomLeftCol;
		buffmem->tu1 = quad.texPosition.d_left;
		buffmem->tv1 = quad.texPosition.d_bottom;
		++buffmem;

		// setup Vertex 4...
		buffmem->x = quad.position.d_right;
		buffmem->y = quad.position.d_top;
		buffmem->z = quad.z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = quad.topRightCol;
		buffmem->tu1 = quad.texPosition.d_right;
		buffmem->tv1 = quad.texPosition.d_top;
		++buffmem;

		// setup Vertex 5...
		buffmem->x = quad.position.d_right;
		buffmem->y = quad.position.d_bottom;
		buffmem->z = quad.z;
		buffmem->rhw = 1.0f;
		buffmem->diffuse = quad.bottomRightCol;
		buffmem->tu1 = quad.texPosition.d_right;
		buffmem->tv1 = quad.texPosition.d_bottom;
		++buffmem;

		// setup Vertex 6...

        // top-left to bottom-right diagonal
        if (quad.splitMode == TopLeftToBottomRight)
        {
            buffmem->x = quad.position.d_left;
            buffmem->y = quad.position.d_top;
            buffmem->z = quad.z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = quad.topLeftCol;
            buffmem->tu1 = quad.texPosition.d_left;
            buffmem->tv1 = quad.texPosition.d_top;
        }
        // bottom-left to top-right diagonal
        else
        {
            buffmem->x = quad.position.d_left;
            buffmem->y = quad.position.d_bottom;
            buffmem->z = quad.z;
            buffmem->rhw = 1.0f;
            buffmem->diffuse = quad.bottomLeftCol;
            buffmem->tu1 = quad.texPosition.d_left;
            buffmem->tv1 = quad.texPosition.d_bottom;
        }
        ++buffmem;

		// update buffer level
		d_bufferPos += VERTEX_PER_QUAD;

		// if there is not enough room in the buffer for another sprite, render what we have
		if (d_bufferPos >= (VERTEXBUFFER_CAPACITY - VERTEX_PER_QUAD))
		{
			if (locked)
			{
				d_buffer->Unlock();
				locked = false;
			}

			renderVBuffer();
		}

	}

	if (locked)
	{
		d_buffer->Unlock();
		locked = false;
	}

	renderVBuffer();
    return true;
}
Пример #5
0
void GuiRenderer::doRender()
{
    initPerFrameStates();
    glInterleavedArrays( GL_T2F_C4UB_V3F , 0, _buff );

    _currTexture = 0;

    // iterate over each quad in the list
    for (QuadList::iterator i = _quadlist.begin(); i != _quadlist.end(); ++i)
    {
        const QuadInfo& quad = (*i);

        if(_currTexture != quad.texid)
        {            
            renderVBuffer();           
            glBindTexture(GL_TEXTURE_2D, quad.texid);
            _currTexture = quad.texid;          
        }

        //vert0       
        _buff[_bufferPos].vertex[0] = quad.position.d_left;
        _buff[_bufferPos].vertex[1] = quad.position.d_top;
        _buff[_bufferPos].vertex[2] = quad.z;
        _buff[_bufferPos].color     = quad.topLeftCol;
        _buff[_bufferPos].tex[0]    = quad.texPosition.d_left;
        _buff[_bufferPos].tex[1]    = quad.texPosition.d_top;         
        ++_bufferPos;

        //vert1
        _buff[_bufferPos].vertex[0] = quad.position.d_left;
        _buff[_bufferPos].vertex[1] = quad.position.d_bottom;
        _buff[_bufferPos].vertex[2] = quad.z;
        _buff[_bufferPos].color     = quad.bottomLeftCol;
        _buff[_bufferPos].tex[0]    = quad.texPosition.d_left;
        _buff[_bufferPos].tex[1]    = quad.texPosition.d_bottom;
        ++_bufferPos;

        //vert2

        // top-left to bottom-right diagonal
        if (quad.splitMode == CEGUI::TopLeftToBottomRight)
        {
            _buff[_bufferPos].vertex[0] = quad.position.d_right;
            _buff[_bufferPos].vertex[1] = quad.position.d_bottom;
            _buff[_bufferPos].vertex[2] = quad.z;
            _buff[_bufferPos].color     = quad.bottomRightCol;
            _buff[_bufferPos].tex[0]    = quad.texPosition.d_right;
            _buff[_bufferPos].tex[1]    = quad.texPosition.d_bottom;         
        }
        // bottom-left to top-right diagonal
        else
        {
            _buff[_bufferPos].vertex[0] = quad.position.d_right;
            _buff[_bufferPos].vertex[1] = quad.position.d_top;
            _buff[_bufferPos].vertex[2] = quad.z;
            _buff[_bufferPos].color     = quad.topRightCol;
            _buff[_bufferPos].tex[0]    = quad.texPosition.d_right;
            _buff[_bufferPos].tex[1]    = quad.texPosition.d_top;         
        }
        ++_bufferPos;

        //vert3
        _buff[_bufferPos].vertex[0] = quad.position.d_right;
        _buff[_bufferPos].vertex[1] = quad.position.d_top;
        _buff[_bufferPos].vertex[2] = quad.z;
        _buff[_bufferPos].color     = quad.topRightCol;
        _buff[_bufferPos].tex[0]    = quad.texPosition.d_right;
        _buff[_bufferPos].tex[1]    = quad.texPosition.d_top;
        ++_bufferPos;

        //vert4

        // top-left to bottom-right diagonal
        if (quad.splitMode == CEGUI::TopLeftToBottomRight)
        {
            _buff[_bufferPos].vertex[0] = quad.position.d_left;
            _buff[_bufferPos].vertex[1] = quad.position.d_top;
            _buff[_bufferPos].vertex[2] = quad.z;
            _buff[_bufferPos].color     = quad.topLeftCol;
            _buff[_bufferPos].tex[0]    = quad.texPosition.d_left;
            _buff[_bufferPos].tex[1]    = quad.texPosition.d_top;         
        }
        // bottom-left to top-right diagonal
        else
        {
            _buff[_bufferPos].vertex[0] = quad.position.d_left;
            _buff[_bufferPos].vertex[1] = quad.position.d_bottom;
            _buff[_bufferPos].vertex[2] = quad.z;
            _buff[_bufferPos].color     = quad.bottomLeftCol;
            _buff[_bufferPos].tex[0]    = quad.texPosition.d_left;
            _buff[_bufferPos].tex[1]    = quad.texPosition.d_bottom;         
        }
        ++_bufferPos;

        //vert 5
        _buff[_bufferPos].vertex[0] = quad.position.d_right;
        _buff[_bufferPos].vertex[1] = quad.position.d_bottom;
        _buff[_bufferPos].vertex[2] = quad.z;
        _buff[_bufferPos].color     = quad.bottomRightCol;
        _buff[_bufferPos].tex[0]    = quad.texPosition.d_right;
        _buff[_bufferPos].tex[1]    = quad.texPosition.d_bottom;         
        ++_bufferPos;

        if(_bufferPos > (VERTEXBUFFER_CAPACITY - VERTEX_PER_QUAD))
        {          
            renderVBuffer();
        }
    }

    //Render
    renderVBuffer();
    exitPerFrameStates();
}