PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: DrawHelpers.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLRENDERER_DRAWHELPERS_H__ 00024 #define __PLRENDERER_DRAWHELPERS_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLMath/Vector2.h> 00032 #include <PLMath/Matrix4x4.h> 00033 #include <PLGraphics/Color/Color4.h> 00034 #include "PLRenderer/PLRenderer.h" 00035 00036 00037 //[-------------------------------------------------------] 00038 //[ Forward declarations ] 00039 //[-------------------------------------------------------] 00040 namespace PLRenderer { 00041 class Font; 00042 class TextureBuffer; 00043 class SamplerStates; 00044 } 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Namespace ] 00049 //[-------------------------------------------------------] 00050 namespace PLRenderer { 00051 00052 00053 //[-------------------------------------------------------] 00054 //[ Classes ] 00055 //[-------------------------------------------------------] 00056 /** 00057 * @brief 00058 * Abstract draw helpers interface 00059 * 00060 * @remarks 00061 * If you want for example to draw a simple point or line with just one line of code, use this 00062 * offered draw helpers. If you want to draw huge point clouds and so on, use vertex buffers 00063 * and draw them all at once using a single draw call - this is the more efficient and universal way! 00064 * The 2D draw helper space looks like this 00065 * 00066 * (0, 0) 00067 * |------ 00068 * | 00069 * | (Width, Height) 00070 * 00071 * The origin is at the upper left which is also usually true for GUI systems. 00072 */ 00073 class DrawHelpers { 00074 00075 00076 //[-------------------------------------------------------] 00077 //[ Public virtual DrawHelpers functions ] 00078 //[-------------------------------------------------------] 00079 public: 00080 //[-------------------------------------------------------] 00081 //[ 2D mode ] 00082 //[-------------------------------------------------------] 00083 /** 00084 * @brief 00085 * Begin 2D mode 00086 * 00087 * @param[in] fX1 00088 * Virtual screen x start position 00089 * @param[in] fY1 00090 * Virtual screen y start position 00091 * @param[in] fX2 00092 * Virtual screen x end position 00093 * @param[in] fY2 00094 * Virtual screen y end position 00095 * 00096 * @note 00097 * - If all parameters are 0.0f, the current viewport settings will be used 00098 * - The projection matrix is set to an orthographic matrix 00099 * - The projection and view matrix will be reset to the old states 00100 * by calling End2DMode(), so be careful when using matrix or render state 00101 * operations withing Begin2DMode() and End2DMode() - or better don't do it! 00102 * - If the renderer is already in the 2D mode the old is ended automatically 00103 * before the new one is started 00104 * - If bitmaps, texts etc. are drawn without an active 2D mode the 2D 00105 * mode is set automatically using the default values 00106 * - When drawing lines, points etc. note that you should go sure that no for instance 00107 * no textures are used else its possible that your lines will be e.g. black 00108 */ 00109 virtual void Begin2DMode(float fX1 = 0.0f, float fY1 = 0.0f, float fX2 = 1.0f, float fY2 = 1.0f) = 0; 00110 00111 /** 00112 * @brief 00113 * Returns whether the renderer is currently in the 2D mode or not 00114 * 00115 * @return 00116 * 'true' if the renderer is currently in the 2D mode, else 'false' 00117 */ 00118 virtual bool Is2DMode() const = 0; 00119 00120 /** 00121 * @brief 00122 * Returns the virtual 2D mode screen size 00123 * 00124 * @param[out] fX1 00125 * Will receive the virtual screen x start position 00126 * @param[out] fY1 00127 * Will receive the virtual screen y start position 00128 * @param[out] fX2 00129 * Will receive the virtual screen x end position 00130 * @param[out] fY2 00131 * Will receive the virtual screen y end position 00132 * 00133 * @return 00134 * 'true' if all went fine, else 'false' (maybe the 2D mode isn't active) 00135 */ 00136 virtual bool Get2DMode(float &fX1, float &fY1, float &fX2, float &fY2) const = 0; 00137 00138 /** 00139 * @brief 00140 * End 2D mode 00141 * 00142 * @see 00143 * - Begin2DMode() 00144 */ 00145 virtual void End2DMode() = 0; 00146 00147 /** 00148 * @brief 00149 * Returns the z value to be used for 2D rendering 00150 * 00151 * @return 00152 * Z value 00153 */ 00154 virtual float Get2DZValue() const = 0; 00155 00156 /** 00157 * @brief 00158 * Sets the Z Value to be used for 2D rendering 00159 * 00160 * @param[in] fZValue 00161 * Z value 00162 */ 00163 virtual void Set2DZValue(float fZValue = 0.0f) = 0; 00164 00165 /** 00166 * @brief 00167 * Returns the 2D mode object space to clip space matrix 00168 * 00169 * @return 00170 * 2D mode object space to clip space matrix 00171 */ 00172 virtual const PLMath::Matrix4x4 &GetObjectSpaceToClipSpaceMatrix() const = 0; 00173 00174 //[-------------------------------------------------------] 00175 //[ Text ] 00176 //[-------------------------------------------------------] 00177 /** 00178 * @brief 00179 * Draws a text at a given 2D position 00180 * 00181 * @param[in] cFont 00182 * Font to use 00183 * @param[in] sText 00184 * Text to draw 00185 * @param[in] cColor 00186 * Text color 00187 * @param[in] vPosition 00188 * Text screen position 00189 * @param[in] nFlags 00190 * Draw flags, see Font::EDrawFlags 00191 * @param[in] vScale 00192 * Font scale 00193 * @param[in] vBias 00194 * Font bias (position offset) 00195 */ 00196 virtual void DrawText(Font &cFont, const PLCore::String &sText, const PLGraphics::Color4 &cColor, const PLMath::Vector2 &vPosition, PLCore::uint32 nFlags = 0, const PLMath::Vector2 &vScale = PLMath::Vector2::One, const PLMath::Vector2 &vBias = PLMath::Vector2::Zero) = 0; 00197 00198 /** 00199 * @brief 00200 * Draws a text at a given 3D position 00201 * 00202 * @param[in] cFont 00203 * Font to use 00204 * @param[in] sText 00205 * Text to draw 00206 * @param[in] cColor 00207 * Text color 00208 * @param[in] vPosition 00209 * Text object space position 00210 * @param[in] mObjectSpaceToClipSpace 00211 * Object space to clip space matrix 00212 * @param[in] nFlags 00213 * Draw flags, see Font::EDrawFlags 00214 * @param[in] vScale 00215 * Font scale 00216 * @param[in] vBias 00217 * Font bias (position offset) 00218 * 00219 * @note 00220 * - "vPosition.To2DCoordinate(mObjectSpaceToClipSpace, cRenderer.GetViewport())" is used to calculate the screen space position 00221 */ 00222 virtual void DrawText(Font &cFont, const PLCore::String &sText, const PLGraphics::Color4 &cColor, const PLMath::Vector3 &vPosition, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace, PLCore::uint32 nFlags = 0, const PLMath::Vector2 &vScale = PLMath::Vector2::One, const PLMath::Vector2 &vBias = PLMath::Vector2::Zero) = 0; 00223 00224 /** 00225 * @brief 00226 * Returns the width of a text 00227 * 00228 * @param[in] cFont 00229 * Font to use 00230 * @param[in] sText 00231 * Text to 'draw' 00232 * 00233 * @return 00234 * The width of a text 00235 */ 00236 virtual float GetTextWidth(Font &cFont, const PLCore::String &sText) const = 0; 00237 00238 /** 00239 * @brief 00240 * Returns the height of a font 00241 * 00242 * @param[in] cFont 00243 * Font to use 00244 * 00245 * @return 00246 * The height of a font 00247 */ 00248 virtual float GetTextHeight(Font &cFont) const = 0; 00249 00250 00251 //[-------------------------------------------------------] 00252 //[ Image ] 00253 //[-------------------------------------------------------] 00254 /** 00255 * @brief 00256 * Draws an image using a given 2D position 00257 * 00258 * @param[in] cTextureBuffer 00259 * Texture buffer holding the image to draw 00260 * @param[in] cSamplerStates 00261 * Sampler states 00262 * @param[in] vPos 00263 * Image position 00264 * @param[in] vSize 00265 * Image size 00266 * @param[in] cColor 00267 * Color to use 00268 * @param[in] fAlphaReference 00269 * Alpha test reference value (0-1), all texels below the value will be discarded, if >= 1, no alpha test will be performed 00270 * @param[in] vTextureCoordinate 00271 * Normalized texture coordinate (0..1) 00272 * @param[in] vTextureCoordinateSize 00273 * Normalized texture coordinate size (0..1) 00274 * @param[in] mTexture 00275 * Texture matrix 00276 * 00277 * @note 00278 * - Usually used together with Begin2DMode() 00279 * - Use counter clockwise culling or deactivate culling 00280 * - If vSize = (0 0), the image size is used 00281 */ 00282 virtual void DrawImage(TextureBuffer &cTextureBuffer, SamplerStates &cSamplerStates, const PLMath::Vector2 &vPos, const PLMath::Vector2 &vSize = PLMath::Vector2::Zero, const PLGraphics::Color4 &cColor = PLGraphics::Color4::White, 00283 float fAlphaReference = 1.0f, const PLMath::Vector2 &vTextureCoordinate = PLMath::Vector2::Zero, const PLMath::Vector2 &vTextureCoordinateSize = PLMath::Vector2::One, const PLMath::Matrix4x4 &mTexture = PLMath::Matrix4x4::Identity) = 0; 00284 00285 /** 00286 * @brief 00287 * Draws an image using a given 3D position 00288 * 00289 * @param[in] cTextureBuffer 00290 * Texture buffer holding the image to draw 00291 * @param[in] cSamplerStates 00292 * Sampler states 00293 * @param[in] vPos 00294 * Image position 00295 * @param[in] mObjectSpaceToClipSpace 00296 * Object space to clip space matrix 00297 * @param[in] vSize 00298 * Image size 00299 * @param[in] cColor 00300 * Color to use 00301 * @param[in] fAlphaReference 00302 * Alpha test reference value (0-1), all texels below the value will be discarded, if >= 1, no alpha test will be performed 00303 * @param[in] vTextureCoordinate 00304 * Normalized texture coordinate (0..1) 00305 * @param[in] vTextureCoordinateSize 00306 * Normalized texture coordinate size (0..1) 00307 * @param[in] mTexture 00308 * Texture matrix 00309 * 00310 * @note 00311 * - The image is drawn on the x/y plane and 'looks' into the positive z axis 00312 * - If vSize = (0 0), the image size is used 00313 */ 00314 virtual void DrawImage(TextureBuffer &cTextureBuffer, SamplerStates &cSamplerStates, const PLMath::Vector3 &vPos, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace, const PLMath::Vector2 &vSize = PLMath::Vector2::Zero, const PLGraphics::Color4 &cColor = PLGraphics::Color4::White, 00315 float fAlphaReference = 1.0f, const PLMath::Vector2 &vTextureCoordinate = PLMath::Vector2::Zero, const PLMath::Vector2 &vTextureCoordinateSize = PLMath::Vector2::One, const PLMath::Matrix4x4 &mTexture = PLMath::Matrix4x4::Identity) = 0; 00316 00317 00318 //[-------------------------------------------------------] 00319 //[ Primitive ] 00320 //[-------------------------------------------------------] 00321 /** 00322 * @brief 00323 * Draws a single colored point using a given 2D position 00324 * 00325 * @param[in] cColor 00326 * Color to use 00327 * @param[in] vPosition 00328 * 2D point position 00329 * @param[in] fSize 00330 * Point size 00331 * 00332 * @note 00333 * - For drawing many points you should use Renderer::DrawPrimitives() with Primitive::PointList 00334 * for better performance. This way you also have more control over 'how' the points 00335 * are rendered. (vertex color and so on) 00336 * - You should use the draw functions for points and lines only for debug 00337 * purposes because often they are not fast and in general not supported 00338 * by each API! (OpenGL supports this function well :) 00339 * 00340 * @see 00341 * - Begin2DMode() 00342 */ 00343 virtual void DrawPoint(const PLGraphics::Color4 &cColor, const PLMath::Vector2 &vPosition, float fSize = 1.0f) = 0; 00344 00345 /** 00346 * @brief 00347 * Draws a single colored point using a given 3D position 00348 * 00349 * @param[in] cColor 00350 * Color to use 00351 * @param[in] vPosition 00352 * 3D object space point position 00353 * @param[in] mObjectSpaceToClipSpace 00354 * Object space to clip space matrix 00355 * @param[in] fSize 00356 * Point size 00357 * 00358 * @see 00359 * - DrawPoint() above 00360 */ 00361 virtual void DrawPoint(const PLGraphics::Color4 &cColor, const PLMath::Vector3 &vPosition, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace, float fSize = 1.0f) = 0; 00362 00363 /** 00364 * @brief 00365 * Draws a single colored line using a given 2D start position and 2D end position 00366 * 00367 * @param[in] cColor 00368 * Color to use 00369 * @param[in] vStartPosition 00370 * 2D start position of the line 00371 * @param[in] vEndPosition 00372 * 2D end position of the line 00373 * @param[in] fWidth 00374 * Width of the line 00375 * 00376 * @note 00377 * - For drawing many lines you should use Renderer::DrawPrimitives() with Primitive::LineList 00378 * for better performance. This way you also have more control over 'how' the lines 00379 * are rendered. (vertex color and so on) 00380 * 00381 * @see 00382 * - Begin2DMode() 00383 * - DrawPoint() 00384 */ 00385 virtual void DrawLine(const PLGraphics::Color4 &cColor, const PLMath::Vector2 &vStartPosition, const PLMath::Vector2 &vEndPosition, float fWidth = 1.0f) = 0; 00386 00387 /** 00388 * @brief 00389 * Draws a single colored line using a given 3D start position and 3D end position 00390 * 00391 * @param[in] cColor 00392 * Color to use 00393 * @param[in] vStartPosition 00394 * 3D object space start position of the line 00395 * @param[in] vEndPosition 00396 * 3D object space end position of the line 00397 * @param[in] mObjectSpaceToClipSpace 00398 * Object space to clip space matrix 00399 * @param[in] fWidth 00400 * Width of the line 00401 * 00402 * @see 00403 * - DrawLine() above 00404 */ 00405 virtual void DrawLine(const PLGraphics::Color4 &cColor, const PLMath::Vector3 &vStartPosition, const PLMath::Vector3 &vEndPosition, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace, float fWidth = 1.0f) = 0; 00406 00407 /** 00408 * @brief 00409 * Draws a colored triangle 00410 * 00411 * @param[in] cColor 00412 * Color to use 00413 * @param[in] vV1 00414 * Object space triangle vertex 1 00415 * @param[in] vV2 00416 * Object space triangle vertex 2 00417 * @param[in] vV3 00418 * Object space triangle vertex 3 00419 * @param[in] mObjectSpaceToClipSpace 00420 * Object space to clip space matrix 00421 * @param[in] fWidth 00422 * Width of the line, if 0, the box is not drawn using lines 00423 * 00424 * @note 00425 * - This function should be used for debugging proposes only! 00426 * Therefore you can use this only to visualize something without to be able 00427 * to define normals, texture coordinates etc. 00428 */ 00429 virtual void DrawTriangle(const PLGraphics::Color4 &cColor, const PLMath::Vector3 &vV1, const PLMath::Vector3 &vV2, const PLMath::Vector3 &vV3, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace, float fWidth = 0.0f) = 0; 00430 00431 /** 00432 * @brief 00433 * Draws a colored 2D quad 00434 * 00435 * @param[in] cColor 00436 * Color to use 00437 * @param[in] vPos 00438 * 2D position 00439 * @param[in] vSize 00440 * 2D size 00441 * @param[in] fWidth 00442 * Width of the line, if 0, the quad is not drawn using lines 00443 * 00444 * @see 00445 * - DrawTriangle() 00446 */ 00447 virtual void DrawQuad(const PLGraphics::Color4 &cColor, const PLMath::Vector2 &vPos, const PLMath::Vector2 &vSize, float fWidth = 0.0f) = 0; 00448 00449 /** 00450 * @brief 00451 * Draws a colored quad using given 3D positions 00452 * 00453 * @param[in] cColor 00454 * Color to use 00455 * @param[in] vV1 00456 * Object space quad vertex 1 00457 * @param[in] vV2 00458 * Object space quad vertex 2 00459 * @param[in] vV3 00460 * Object space quad vertex 3 00461 * @param[in] vV4 00462 * Object space quad vertex 4 00463 * @param[in] mObjectSpaceToClipSpace 00464 * Object space to clip space matrix 00465 * @param[in] fWidth 00466 * Width of the line, if 0, the quad is not drawn using lines 00467 * 00468 * @see 00469 * - DrawTriangle() 00470 */ 00471 virtual void DrawQuad(const PLGraphics::Color4 &cColor, const PLMath::Vector3 &vV1, const PLMath::Vector3 &vV2, const PLMath::Vector3 &vV3, const PLMath::Vector3 &vV4, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace, float fWidth = 0.0f) = 0; 00472 00473 /** 00474 * @brief 00475 * Draws a gradient colored 2D quad 00476 * 00477 * @param[in] cColor1 00478 * First color to use 00479 * @param[in] cColor2 00480 * Second color to use 00481 * @param[in] fAngle 00482 * Clockwise angle (in radian) of the gradient color. 0° means from left to right. 00483 * @param[in] vPos 00484 * 2D position 00485 * @param[in] vSize 00486 * 2D size 00487 * 00488 * @see 00489 * - DrawTriangle() 00490 */ 00491 virtual void DrawGradientQuad(const PLGraphics::Color4 &cColor1, const PLGraphics::Color4 &cColor2, float fAngle, const PLMath::Vector2 &vPos, const PLMath::Vector2 &vSize) = 0; 00492 00493 /** 00494 * @brief 00495 * Draws a gradient colored quad using given 3D positions 00496 * 00497 * @param[in] cColor1 00498 * First color to use 00499 * @param[in] cColor2 00500 * Second color to use 00501 * @param[in] fAngle 00502 * Clockwise angle (in radian) of the gradient color. 0° means from left to right. 00503 * @param[in] vV1 00504 * Object space quad vertex 1 00505 * @param[in] vV2 00506 * Object space quad vertex 2 00507 * @param[in] vV3 00508 * Object space quad vertex 3 00509 * @param[in] vV4 00510 * Object space quad vertex 4 00511 * @param[in] mObjectSpaceToClipSpace 00512 * Object space to clip space matrix 00513 * 00514 * @see 00515 * - DrawTriangle() 00516 */ 00517 virtual void DrawGradientQuad(const PLGraphics::Color4 &cColor1, const PLGraphics::Color4 &cColor2, float fAngle, const PLMath::Vector3 &vV1, const PLMath::Vector3 &vV2, const PLMath::Vector3 &vV3, const PLMath::Vector3 &vV4, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace) = 0; 00518 00519 /** 00520 * @brief 00521 * Draws a colored box 00522 * 00523 * @param[in] cColor 00524 * Color to use 00525 * @param[in] vMin 00526 * Minimum object space position 00527 * @param[in] vMax 00528 * Maximum object space position 00529 * @param[in] mObjectSpaceToClipSpace 00530 * Object space to clip space matrix 00531 * @param[in] fWidth 00532 * Width of the line, if 0, the box is not drawn using lines 00533 * 00534 * @see 00535 * - DrawTriangle() 00536 */ 00537 virtual void DrawBox(const PLGraphics::Color4 &cColor, const PLMath::Vector3 &vMin, const PLMath::Vector3 &vMax, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace, float fWidth = 0.0f) = 0; 00538 00539 /** 00540 * @brief 00541 * Draws a colored plane 00542 * 00543 * @param[in] cColor 00544 * Color to use 00545 * @param[in] vN 00546 * Plane normal (must be normalized) 00547 * @param[in] fD 00548 * Plane d factor 00549 * @param[in] mObjectSpaceToClipSpace 00550 * Object space to clip space matrix 00551 * @param[in] fSize 00552 * Plane size, a plane has an infinite size but often it's useful to limit the visible size... 00553 * @param[in] fLineWidth 00554 * Width of the line, if 0, draw no line to origin 00555 * 00556 * @see 00557 * - DrawTriangle() 00558 */ 00559 virtual void DrawPlane(const PLGraphics::Color4 &cColor, const PLMath::Vector3 &vN, float fD, const PLMath::Matrix4x4 &mObjectSpaceToClipSpace, float fSize = 10000.0f, float fLineWidth = 1.0f) = 0; 00560 00561 00562 //[-------------------------------------------------------] 00563 //[ Protected functions ] 00564 //[-------------------------------------------------------] 00565 protected: 00566 /** 00567 * @brief 00568 * Constructor 00569 */ 00570 PLRENDERER_API DrawHelpers(); 00571 00572 /** 00573 * @brief 00574 * Destructor 00575 */ 00576 PLRENDERER_API virtual ~DrawHelpers(); 00577 00578 00579 //[-------------------------------------------------------] 00580 //[ Private functions ] 00581 //[-------------------------------------------------------] 00582 private: 00583 /** 00584 * @brief 00585 * Copy constructor 00586 * 00587 * @param[in] cSource 00588 * Source to copy from 00589 */ 00590 DrawHelpers(const DrawHelpers &cSource); 00591 00592 /** 00593 * @brief 00594 * Copy operator 00595 * 00596 * @param[in] cSource 00597 * Source to copy from 00598 * 00599 * @return 00600 * Reference to this instance 00601 */ 00602 DrawHelpers &operator =(const DrawHelpers &cSource); 00603 00604 00605 }; 00606 00607 00608 //[-------------------------------------------------------] 00609 //[ Namespace ] 00610 //[-------------------------------------------------------] 00611 } // PLRenderer 00612 00613 00614 #endif // __PLRENDERER_DRAWHELPERS_H__
|