 |
Gorgon Game Engine
|
Go to the documentation of this file.
112 return Alignment(((
int)placement & 56)>>3);
135 throw std::runtime_error(
"Unknown mode");
151 throw std::runtime_error(
"Unknown mode");
235 throw std::runtime_error(
"Unknown mode");
258 throw std::runtime_error(
"Unknown mode");
286 throw std::runtime_error(
"Unknown mode");
309 throw std::runtime_error(
"Unknown mode");
361 throw std::runtime_error(
"Unknown mode");
384 throw std::runtime_error(
"Unknown mode");
389 return repeatingsize;
412 throw std::runtime_error(
"Unknown mode");
435 throw std::runtime_error(
"Unknown mode");
440 return repeatingsize;
483 virtual GL::Texture
GetID()
const = 0;
535 #include "../Utils/ManagedBuffer.h"
536 #include "../Utils/Point2D.h"
537 #include "../Utils/Bounds2D.h"
538 #include "../Utils/Rectangle2D.h"
539 #include "../Utils/Size2D.h"
540 #include "../Utils/Logging.h"
541 #include "External/glutil/MatrixStack.h"
544 # define GL_BGR 0x80E0
545 # define GL_BGRA 0x80E1
549 # define PI 3.1415926535898f
554 namespace gge {
namespace graphics {
558 extern glutil::MatrixStack ModelViewMatrixStack;
559 extern glutil::MatrixStack ProjectionMatrixStack;
562 class TextureAttachment {
565 TexturePosition *TextureCoords;
567 bool HasOwnTextureCoords;
568 const GLTexture *Texture;
570 TextureAttachment() : HasOwnTextureCoords(false), TextureCoords(NULL), Texture(NULL) {}
573 void DeleteTextureCoords() {
574 if(HasOwnTextureCoords) {
575 HasOwnTextureCoords=
false;
576 delete[] TextureCoords;
581 void SetTexture(
const GLTexture *texture) {
582 DeleteTextureCoords();
584 this->Texture=texture;
585 TextureCoords=
const_cast<TexturePosition*
>((
const TexturePosition*)texture->ImageCoord);
589 const GLTexture *GetTexture()
const {
596 void CreateTextureCoords() {
597 if(!HasOwnTextureCoords) {
598 HasOwnTextureCoords=
true;
599 TextureCoords=
new TexturePosition[4];
603 ~TextureAttachment() {
604 DeleteTextureCoords();
613 VertexPosition VertexCoords[4];
615 TexturePosition *TextureCoords;
617 bool HasOwnTextureCoords;
627 BasicSurface() : Mode(
Normal) {
630 HasOwnTextureCoords=
false;
639 BasicSurface(GLTexture *texture) {
640 this->Texture=texture;
641 TextureCoords=texture->ImageCoord;
643 HasOwnTextureCoords=
false;
647 void DeleteTextureCoords() {
648 if(HasOwnTextureCoords) {
649 HasOwnTextureCoords=
false;
650 delete[] TextureCoords;
655 void SetTexture(
const GLTexture *texture) {
656 DeleteTextureCoords();
658 this->Texture=texture;
659 TextureCoords=
const_cast<TexturePosition*
>((
const TexturePosition*)texture->ImageCoord);
668 const GLTexture *GetTexture()
const {
675 void CreateTextureCoords() {
676 if(!HasOwnTextureCoords) {
677 HasOwnTextureCoords=
true;
678 TextureCoords=
new TexturePosition[4];
684 if(HasOwnTextureCoords && TextureCoords)
685 delete[] TextureCoords;
688 TextureAttachment *Alpha;
692 const GLTexture *Texture;
695 std::array<float,24> GetVertexData(
const BasicSurface& surface);
699 class SizeController2D {
704 Single = B8(00000000),
706 Stretch = B8(00000010),
718 Continous = B8(00000001),
719 Integral_Smaller = B8(00001101),
720 Integral_Fill = B8(00010101),
721 Integral_Best = B8(00100101),
723 Tile_Continous = B8(00000001),
724 Tile_Integral_Smaller = B8(00001101),
725 Tile_Integral_Fill = B8(00010101),
726 Tile_Integral_Best = B8(00100101),
727 } HorizontalTiling, VerticalTiling;
730 explicit SizeController2D(TilingType HorizontalTiling=Single, TilingType VerticalTiling=Single,
Alignment::Type Align=Alignment::Middle_Center) :
731 HorizontalTiling(HorizontalTiling), VerticalTiling(VerticalTiling), Align(Align)
735 static const SizeController2D TileFit;
736 static const SizeController2D StretchFit;
737 static const SizeController2D SingleTopLeft;
738 static const SizeController2D SingleBottomRight;
739 static const SizeController2D SingleMiddleCenter;
741 int CalculateWidth(
int W,
int Increment)
const {
742 if(HorizontalTiling==SizeController2D::Tile_Integral_Best) {
745 else if(HorizontalTiling==SizeController2D::Tile_Integral_Smaller) {
746 return (
int)std::floor((
double)
W/Increment)*Increment;
748 else if(HorizontalTiling==SizeController2D::Tile_Integral_Fill) {
749 return (
int)std::ceil((
double)
W/Increment)*Increment;
755 int CalculateWidth(
int W,
int Increment,
int Overhead)
const {
756 if(HorizontalTiling==SizeController2D::Integral_Best) {
757 return (
int)
utils::Round((
double)(
W-Overhead)/Increment)*Increment+Overhead;
759 else if(HorizontalTiling==SizeController2D::Integral_Smaller) {
760 return (
int)std::floor((
double)(
W-Overhead)/Increment)*Increment+Overhead;
762 else if(HorizontalTiling==SizeController2D::Integral_Fill) {
763 return (
int)std::ceil((
double)(
W-Overhead)/Increment)*Increment+Overhead;
769 int CalculateHeight(
int H,
int Increment)
const {
770 if(VerticalTiling==SizeController2D::Tile_Integral_Best) {
773 else if(VerticalTiling==SizeController2D::Tile_Integral_Smaller) {
774 return (
int)std::floor((
double)
H/Increment)*Increment;
776 else if(VerticalTiling==SizeController2D::Tile_Integral_Fill) {
777 return (
int)std::ceil((
double)
H/Increment)*Increment;
783 int CalculateHeight(
int H,
int Increment,
int Overhead)
const {
784 if(VerticalTiling==SizeController2D::Integral_Best) {
785 return (
int)
utils::Round((
double)(
H-Overhead)/Increment)*Increment+Overhead;
787 else if(VerticalTiling==SizeController2D::Integral_Smaller) {
788 return (
int)std::floor((
double)(
H-Overhead)/Increment)*Increment+Overhead;
790 else if(VerticalTiling==SizeController2D::Integral_Fill) {
791 return (
int)std::ceil((
double)(
H-Overhead)/Increment)*Increment+Overhead;
804 os::DeviceHandle
Initialize(os::WindowHandle hWnd,
int BitDepth,
int Width,
int Height);
817 void A8ToA8L8(
int Width,
int Height,
Byte *Source,
Byte *Destination);
835 void PostRender(os::DeviceHandle Device, os::WindowHandle win);
837 void ResizeGL(
int Width,
int Height);
Geometry::Rectangle CalculateArea(const Geometry::Sizef &repeatingsize, const Geometry::Sizef &fixedsize, const Geometry::Sizef &area) const
Calculates the drawing area of the object according to the tiling and placement rules.
Definition: Graphics.h:460
Orientation
2D orientation constants
Definition: Graphics.h:39
Utils::Logger Logger
Definition: HTMLRenderer.cpp:10
Texture GenerateTexture(const Containers::Image &data)
This function generates a texture from the given image data.
Definition: OpenGL.cpp:146
This class allows control over a sizable object.
Definition: Graphics.h:161
@ TopRight
Placed at top right.
@ Start
Placed at the start of the axis.
basic_Image< Byte > Image
Definition: Image.h:1364
@ TopLeft
Placed at top left.
Tiling
Controls how a direction is tiled.
Definition: Graphics.h:164
bool IsPartial() const
Returns whether this texture uses only a part of the GL::Texture.
Definition: Graphics.h:495
ColorMode
Color modes for images.
Definition: Color.h:16
contains the Rectangle class
Pointf Round(Pointf num)
Performs a rounding operation over a floating point point.
Definition: Point.h:604
contains operating system functionality.
@ MiddleLeft
Middle left.
Definition: Template.h:48
void ActivateQuadVertices()
Definition: Graphics.cpp:23
contains the Bounds class
@ Center
Centered along the axis.
@ TopCenter
Top center.
Definition: Template.h:43
T_ Height
Height of this size object.
Definition: Size.h:261
Geometry::Pointf CalculateOffset(const Geometry::Sizef &objectsize, const Geometry::Sizef &area) const
Calculates the size of the object according to the tiling and placement rules.
Definition: Graphics.h:325
virtual ColorMode GetMode() const =0
@ Integral_Best
The drawing is tiled along this axis to cover the given size.
Definition: Graphics.h:195
Geometry::Rectanglef CalculateArea(const Geometry::Sizef &objectsize, const Geometry::Sizef &area) const
Calculates the drawing area of the object according to the tiling and placement rules.
Definition: Graphics.h:336
@ TopLeft
Top left.
Definition: Template.h:41
Alignment
Defines how an object is aligned.
Definition: Graphics.h:53
@ Left
Text is aligned to left.
SizeController()
Creates a default size controller which tiles the object from top-left.
Definition: Graphics.h:199
basic_Size< int > Size
Definition: Size.h:385
Placement
Defines how an object is placed in a 2D axis system.
Definition: Graphics.h:79
@ Right
Text is aligned to right.
Utils::Logger log
Definition: Animation.cpp:11
SizeController(Tiling h, Tiling v, Placement p=Placement::TopLeft)
Creates a new size controller with the given tiling options and placement.
Definition: Graphics.h:206
@ Stretch
The drawing is stretched along this axis to cover the given size.
Definition: Graphics.h:171
Geometry::Sizef CalculateSize(Geometry::Sizef objectsize, const Geometry::Sizef &area) const
Calculates the size of the object according to the tiling rules.
Definition: Graphics.h:267
Tiling
Details which directions a texture should tile.
Definition: Graphics.h:31
Geometry::Size CalculateSize(Geometry::Size repeatingsize, const Geometry::Size &fixedsize, const Geometry::Size &area) const
Calculates the size of the object according to the tiling rules.
Definition: Graphics.h:342
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
virtual const Geometry::Pointf * GetCoordinates() const =0
Should return the coordinates of the texture to be used.
Alignment GetHorizontal(Placement placement)
Returns horizontal alignment from a placement.
Definition: Graphics.h:111
virtual GL::Texture GetID() const =0
Should return GL::Texture to be drawn. This could be 0 to denote no texture is to be used.
Alignment GetVertical(Placement placement)
Returns vertical alignment from a placement.
Definition: Graphics.h:116
void DrawQuadVertices()
Definition: Graphics.cpp:32
@ Center
Text is aligned to center.
Geometry::Size CalculateSize(Geometry::Size objectsize, const Geometry::Size &area) const
Calculates the size of the object according to the tiling rules.
Definition: Graphics.h:216
TextAlignment
Defines how a text is aligned.
Definition: Graphics.h:67
void DestroyTexture(Texture texture)
Destroys the given texture.
Definition: OpenGL.cpp:213
@ BottomCenter
Bottom center.
Definition: Template.h:58
Tiling Horizontal
Horizontal tiling mode.
Definition: Graphics.h:470
Placement Place
Placement method.
Definition: Graphics.h:476
GL::Texture LastTexture
Definition: Graphics.cpp:13
This class represents a 2D point.
Definition: Point.h:32
void Initialize()
Initializes Graphics module, should be performed after an OpenGL context is created.
Definition: Graphics.cpp:37
@ MiddleRight
Middle right.
Definition: Template.h:53
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
Geometry::Rectangle CalculateArea(const Geometry::Size &repeatingsize, const Geometry::Size &fixedsize, const Geometry::Size &area) const
Calculates the drawing area of the object according to the tiling and placement rules.
Definition: Graphics.h:454
@ Integral_Smaller
The drawing is tiled along this axis to cover the given size.
Definition: Graphics.h:184
SizeController(Graphics::Tiling tile, Placement p=Placement::TopLeft)
Creates a new size controller with the given tiling options and placement.
Definition: Graphics.h:209
@ Graphics
Definition: Template.h:164
This interface represents a GL texture source.
Definition: Graphics.h:480
Type
Definition: Shader.h:14
@ MiddleCenter
Middle center, using this position ensures that the components will be inside each other.
Definition: Template.h:51
T_ Width
Width of this size object.
Definition: Size.h:258
@ End
Placed at the end of the axis.
Geometry::Pointf CalculateOffset(const Geometry::Sizef &repeatingsize, const Geometry::Sizef &fixedsize, const Geometry::Sizef &area) const
Calculates the size of the object according to the tiling and placement rules.
Definition: Graphics.h:449
@ BottomRight
Placed at bottom right.
Geometry::Point CalculateOffset(const Geometry::Size &repeatingsize, const Geometry::Size &fixedsize, const Geometry::Size &area) const
Calculates the size of the object according to the tiling and placement rules.
Definition: Graphics.h:444
Geometry::Rectangle CalculateArea(const Geometry::Size &objectsize, const Geometry::Size &area) const
Calculates the drawing area of the object according to the tiling and placement rules.
Definition: Graphics.h:330
Represents a rectangle in a 2D space.
Definition: Rectangle.h:19
Geometry::Point CalculateOffset(Placement place, Geometry::Size remainder)
Returns the offset of the object according to the given placement rule when there is the given remain...
Definition: Graphics.h:123
@ BottomLeft
Placed at bottom.
virtual Geometry::Size GetImageSize() const =0
Should return the size of the image stored in texture. Not the whole texture size.
void UpdateTexture(Texture texture, const Containers::Image &data)
Updates the given texture to contain the given data.
Definition: OpenGL.cpp:177
@ Tile
The drawing is tiled along this axis to cover the given size.
Definition: Graphics.h:178
Tiling Tile(bool horizontal, bool vertical)
Creates a Tiling class from the given horizontal, vertical tiling info.
Definition: Graphics.h:45
GLenum getGLColorMode(Graphics::ColorMode mode)
Definition: OpenGL.cpp:107
Geometry::Size ScreenSize
Definition: Window.cpp:15
Geometry::Sizef CalculateSize(Geometry::Sizef repeatingsize, const Geometry::Sizef &fixedsize, const Geometry::Sizef &area) const
Calculates the size of the object according to the tiling rules.
Definition: Graphics.h:393
@ Single
The drawing is drawn only once with its original size.
Definition: Graphics.h:167
static const Geometry::Pointf fullcoordinates[4]
Coordinates that selects the entire texture to be used.
Definition: Graphics.h:501
Tiling Vertical
Vertical tiling mode.
Definition: Graphics.h:473
Graphics::Tiling GetTiling() const
Definition: Graphics.h:465
@ Normal
Definition: Shader.h:15
Geometry::Point CalculateOffset(const Geometry::Size &objectsize, const Geometry::Size &area) const
Calculates the size of the object according to the tiling and placement rules.
Definition: Graphics.h:319
SizeController(Placement p)
Creates a size controller that places a single object to the given placement.
Definition: Graphics.h:203
@ Integral_Fill
The drawing is tiled along this axis to cover the given size.
Definition: Graphics.h:189