Exemplo n.º 1
0
void TerrainRenderer::UpdateBorderTriangleColor(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
{
	unsigned int pos = y * width + x;
	
	// Für VBO-Aktualisierung:
	// Erzeugte Ränder zählen
	unsigned count_borders = 0;
	// Erstes Offset merken
	unsigned first_offset = 0;


	// Rand	links - rechts
	for(unsigned char i = 0; i < 2; ++i)
	{
		if(borders[pos].left_right[i])
		{
			unsigned int offset = borders[pos].left_right_offset[i];

			if(!first_offset)
				first_offset = offset;

			gl_colors[offset].colors[i ? 0 : 2].r = gl_colors[offset].colors[i ? 0 : 2].g = gl_colors[offset].colors[i ? 0 : 2].b = GetColor(x, y);
			gl_colors[offset].colors[1        ].r = gl_colors[offset].colors[1        ].g = gl_colors[offset].colors[1        ].b = GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4));
			gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetBColor(x, y, i);

			++count_borders;
		}
	}

	// Rand rechts - links
	for(unsigned char i = 0; i < 2; ++i)
	{
		if(borders[pos].right_left[i])
		{
			unsigned int offset = borders[pos].right_left_offset[i];

			if(!first_offset)
				first_offset = offset;

			gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4));
			gl_colors[offset].colors[1        ].r = gl_colors[offset].colors[1        ].g = gl_colors[offset].colors[1        ].b = GetColor(gwv->GetXA(x,y,3), gwv->GetYA(x,y,3));
			gl_colors[offset].colors[i ? 0 : 2].r = gl_colors[offset].colors[i ? 0 : 2].g = gl_colors[offset].colors[i ? 0 : 2].b = GetBColor(x + i, y, i ? 0 : 1);

			++count_borders;
		}
	}

	// Rand oben - unten
	for(unsigned char i = 0; i < 2; ++i)
	{
		if(borders[pos].top_down[i])
		{
			unsigned int offset = borders[pos].top_down_offset[i];

			if(!first_offset)
				first_offset = offset;

			gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetColor(gwv->GetXA(x,y,5), gwv->GetYA(x,y,5));
			gl_colors[offset].colors[1        ].r = gl_colors[offset].colors[1        ].g = gl_colors[offset].colors[1        ].b = GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4));

			if(i == 0)
				gl_colors[offset].colors[2].r = gl_colors[offset].colors[2].g = gl_colors[offset].colors[2].b = GetBColor(x, y, i);
			else
				gl_colors[offset].colors[0].r = gl_colors[offset].colors[0].g = gl_colors[offset].colors[0].b = GetBColor(gwv->GetXA(x,y,5), gwv->GetYA(x,y,5),i);

			++count_borders;
		}
	}

	/// Bei Vertexbuffern das die Daten aktualisieren
	if(update && SETTINGS.video.vbo)
	{
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
		glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,first_offset * 3 * 3 * sizeof(float), 
			count_borders * 3 * 3 * sizeof(float), &gl_colors[first_offset]);
	}
}
Exemplo n.º 2
0
void TerrainRenderer::UpdateBorderTriangleColor(const MapPoint pt, const GameWorldViewer& gwv, const bool update)
{
    unsigned int pos = GetVertexIdx(pt);

    // Für VBO-Aktualisierung:
    // Erzeugte Ränder zählen
    unsigned count_borders = 0;
    // Erstes Offset merken
    unsigned first_offset = 0;


    // Rand links - rechts
    for(unsigned char i = 0; i < 2; ++i)
    {
        if(!borders[pos].left_right[i])
            continue;
        unsigned int offset = borders[pos].left_right_offset[i];

        if(!first_offset)
            first_offset = offset;

        gl_colors[offset][i ? 0 : 2].r = gl_colors[offset][i ? 0 : 2].g = gl_colors[offset][i ? 0 : 2].b = GetColor(pt); //-V807
        gl_colors[offset][1        ].r = gl_colors[offset][1        ].g = gl_colors[offset][1        ].b = GetColor(gwv.GetNeighbour(pt, 4)); //-V807
        gl_colors[offset][i ? 2 : 0].r = gl_colors[offset][i ? 2 : 0].g = gl_colors[offset][i ? 2 : 0].b = GetBColor(pt, i); //-V807

        ++count_borders;
    }

    // Rand rechts - links
    for(unsigned char i = 0; i < 2; ++i)
    {
        if(!borders[pos].right_left[i])
            continue;
        unsigned int offset = borders[pos].right_left_offset[i];

        if(!first_offset)
            first_offset = offset;

        gl_colors[offset][i ? 2 : 0].r = gl_colors[offset][i ? 2 : 0].g = gl_colors[offset][i ? 2 : 0].b = GetColor(gwv.GetNeighbour(pt, 4));
        gl_colors[offset][1        ].r = gl_colors[offset][1        ].g = gl_colors[offset][1        ].b = GetColor(gwv.GetNeighbour(pt, 3));
        MapPoint pt2(pt.x + i, pt.y);
        if(pt2.x >= width)
            pt2.x -= width;
        gl_colors[offset][i ? 0 : 2].r = gl_colors[offset][i ? 0 : 2].g = gl_colors[offset][i ? 0 : 2].b = GetBColor(pt2, i ? 0 : 1);

        ++count_borders;
    }

    // Rand oben - unten
    for(unsigned char i = 0; i < 2; ++i)
    {
        if(!borders[pos].top_down[i])
            continue;
        unsigned int offset = borders[pos].top_down_offset[i];

        if(!first_offset)
            first_offset = offset;

        gl_colors[offset][i ? 2 : 0].r = gl_colors[offset][i ? 2 : 0].g = gl_colors[offset][i ? 2 : 0].b = GetColor(gwv.GetNeighbour(pt, 5));
        gl_colors[offset][1        ].r = gl_colors[offset][1        ].g = gl_colors[offset][1        ].b = GetColor(gwv.GetNeighbour(pt, 4));

        if(i == 0)
            gl_colors[offset][2].r = gl_colors[offset][2].g = gl_colors[offset][2].b = GetBColor(pt, i); //-V807
        else
            gl_colors[offset][0].r = gl_colors[offset][0].g = gl_colors[offset][0].b = GetBColor(gwv.GetNeighbour(pt, 5), i); //-V807

        ++count_borders;
    }

    /// Bei Vertexbuffern das die Daten aktualisieren
    if(update && vboBuffersUsed)
    {
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
        glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, first_offset * sizeof(ColorTriangle), count_borders * sizeof(ColorTriangle), &gl_colors[first_offset]);
    }
}