/************************************************************************* Queues an area of the associated Texture the be drawn on the screen. Low-level routine not normally used! *************************************************************************/ void Imageset::draw(GeometryBuffer& buffer, const Rect& source_rect, const Rect& dest_rect, const Rect* clip_rect,const ColourRect& colours, QuadSplitMode quad_split_mode) const { // get the rect area that we will actually draw to (i.e. perform clipping) Rect final_rect(clip_rect ? dest_rect.getIntersection(*clip_rect) : dest_rect ); // check if rect was totally clipped if ((final_rect.getWidth() == 0) || (final_rect.getHeight() == 0)) return; // Fix bug #45 // Obtain correct scale values from the texture const float x_scale = d_texture->getTexelScaling().d_x; const float y_scale = d_texture->getTexelScaling().d_y; float tex_per_pix_x = source_rect.getWidth() / dest_rect.getWidth(); float tex_per_pix_y = source_rect.getHeight() / dest_rect.getHeight(); // calculate final, clipped, texture co-ordinates Rect tex_rect((source_rect.d_left + ((final_rect.d_left - dest_rect.d_left) * tex_per_pix_x)) * x_scale, (source_rect.d_top + ((final_rect.d_top - dest_rect.d_top) * tex_per_pix_y)) * y_scale, (source_rect.d_right + ((final_rect.d_right - dest_rect.d_right) * tex_per_pix_x)) * x_scale, (source_rect.d_bottom + ((final_rect.d_bottom - dest_rect.d_bottom) * tex_per_pix_y)) * y_scale); final_rect.d_left = PixelAligned(final_rect.d_left); final_rect.d_right = PixelAligned(final_rect.d_right); final_rect.d_top = PixelAligned(final_rect.d_top); final_rect.d_bottom = PixelAligned(final_rect.d_bottom); Vertex vbuffer[6]; // vertex 0 vbuffer[0].position = Vector3(final_rect.d_left, final_rect.d_top, 0.0f); vbuffer[0].colour_val = colours.d_top_left; vbuffer[0].tex_coords = Vector2(tex_rect.d_left, tex_rect.d_top); // vertex 1 vbuffer[1].position = Vector3(final_rect.d_left, final_rect.d_bottom, 0.0f); vbuffer[1].colour_val = colours.d_bottom_left; vbuffer[1].tex_coords = Vector2(tex_rect.d_left, tex_rect.d_bottom); // vertex 2 vbuffer[2].position.d_x = final_rect.d_right; vbuffer[2].position.d_z = 0.0f; vbuffer[2].colour_val = colours.d_bottom_right; vbuffer[2].tex_coords.d_x = tex_rect.d_right; // top-left to bottom-right diagonal if (quad_split_mode == TopLeftToBottomRight) { vbuffer[2].position.d_y = final_rect.d_bottom; vbuffer[2].tex_coords.d_y = tex_rect.d_bottom; } // bottom-left to top-right diagonal else { vbuffer[2].position.d_y = final_rect.d_top; vbuffer[2].tex_coords.d_y = tex_rect.d_top; } // vertex 3 vbuffer[3].position = Vector3(final_rect.d_right, final_rect.d_top, 0.0f); vbuffer[3].colour_val = colours.d_top_right; vbuffer[3].tex_coords = Vector2(tex_rect.d_right, tex_rect.d_top); // vertex 4 vbuffer[4].position.d_x = final_rect.d_left; vbuffer[4].position.d_z = 0.0f; vbuffer[4].colour_val = colours.d_top_left; vbuffer[4].tex_coords.d_x = tex_rect.d_left; // top-left to bottom-right diagonal if (quad_split_mode == TopLeftToBottomRight) { vbuffer[4].position.d_y = final_rect.d_top; vbuffer[4].tex_coords.d_y = tex_rect.d_top; } // bottom-left to top-right diagonal else { vbuffer[4].position.d_y = final_rect.d_bottom; vbuffer[4].tex_coords.d_y = tex_rect.d_bottom; } // vertex 5 vbuffer[5].position = Vector3(final_rect.d_right, final_rect.d_bottom, 0.0f); vbuffer[5].colour_val= colours.d_bottom_right; vbuffer[5].tex_coords = Vector2(tex_rect.d_right, tex_rect.d_bottom); // TODO: Remove cast when GeometryBuffer gets it's APIs fixed! buffer.setActiveTexture((Texture*)d_texture); buffer.appendGeometry(vbuffer, 6); }
//----------------------------------------------------------------------------// void BasicImage::render(GeometryBuffer& buffer, const Rectf& dest_area, const Rectf* clip_area, const ColourRect& colours) const { const QuadSplitMode quad_split_mode(TopLeftToBottomRight); Rectf dest(dest_area); // apply rendering offset to the destination Rect dest.offset(d_scaledOffset); // get the rect area that we will actually draw to (i.e. perform clipping) Rectf final_rect(clip_area ? dest.getIntersection(*clip_area) : dest ); // check if rect was totally clipped if ((final_rect.getWidth() == 0) || (final_rect.getHeight() == 0)) return; // Obtain correct scale values from the texture const Vector2f& scale = d_texture->getTexelScaling(); const Vector2f tex_per_pix(d_area.getWidth() / dest.getWidth(), d_area.getHeight() / dest.getHeight()); // calculate final, clipped, texture co-ordinates const Rectf tex_rect((d_area.d_min + ((final_rect.d_min - dest.d_min) * tex_per_pix)) * scale, (d_area.d_max + ((final_rect.d_max - dest.d_max) * tex_per_pix)) * scale); // URGENT FIXME: Shouldn't this be in the hands of the user? final_rect.d_min.d_x = CoordConverter::alignToPixels(final_rect.d_min.d_x); final_rect.d_min.d_y = CoordConverter::alignToPixels(final_rect.d_min.d_y); final_rect.d_max.d_x = CoordConverter::alignToPixels(final_rect.d_max.d_x); final_rect.d_max.d_y = CoordConverter::alignToPixels(final_rect.d_max.d_y); Vertex vbuffer[6]; // vertex 0 vbuffer[0].position = Vector3f(final_rect.left(), final_rect.top(), 0.0f); vbuffer[0].colour_val = colours.d_top_left; vbuffer[0].tex_coords = Vector2f(tex_rect.left(), tex_rect.top()); // vertex 1 vbuffer[1].position = Vector3f(final_rect.left(), final_rect.bottom(), 0.0f); vbuffer[1].colour_val = colours.d_bottom_left; vbuffer[1].tex_coords = Vector2f(tex_rect.left(), tex_rect.bottom()); // vertex 2 vbuffer[2].position.d_x = final_rect.right(); vbuffer[2].position.d_z = 0.0f; vbuffer[2].colour_val = colours.d_bottom_right; vbuffer[2].tex_coords.d_x = tex_rect.right(); // top-left to bottom-right diagonal if (quad_split_mode == TopLeftToBottomRight) { vbuffer[2].position.d_y = final_rect.bottom(); vbuffer[2].tex_coords.d_y = tex_rect.bottom(); } // bottom-left to top-right diagonal else { vbuffer[2].position.d_y = final_rect.top(); vbuffer[2].tex_coords.d_y = tex_rect.top(); } // vertex 3 vbuffer[3].position = Vector3f(final_rect.right(), final_rect.top(), 0.0f); vbuffer[3].colour_val = colours.d_top_right; vbuffer[3].tex_coords = Vector2f(tex_rect.right(), tex_rect.top()); // vertex 4 vbuffer[4].position.d_x = final_rect.left(); vbuffer[4].position.d_z = 0.0f; vbuffer[4].colour_val = colours.d_top_left; vbuffer[4].tex_coords.d_x = tex_rect.left(); // top-left to bottom-right diagonal if (quad_split_mode == TopLeftToBottomRight) { vbuffer[4].position.d_y = final_rect.top(); vbuffer[4].tex_coords.d_y = tex_rect.top(); } // bottom-left to top-right diagonal else { vbuffer[4].position.d_y = final_rect.bottom(); vbuffer[4].tex_coords.d_y = tex_rect.bottom(); } // vertex 5 vbuffer[5].position = Vector3f(final_rect.right(), final_rect.bottom(), 0.0f); vbuffer[5].colour_val= colours.d_bottom_right; vbuffer[5].tex_coords = Vector2f(tex_rect.right(), tex_rect.bottom()); buffer.setActiveTexture(d_texture); buffer.appendGeometry(vbuffer, 6); }