llrenderutils.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /**
  2. * @file llrenderutils.h
  3. * @brief Utility 2D and 3D GL rendering functions declarations.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_RENDERUTILS_H
  33. #define LL_RENDERUTILS_H
  34. #include <vector>
  35. #include "llglslshader.h"
  36. #include "llrect.h"
  37. #include "llvector3.h"
  38. #include "llvector4a.h"
  39. class LLColor4;
  40. class LLGLTexture;
  41. class LLVector2;
  42. // UI colors, defined in indra/llui/llui.cpp
  43. extern const LLColor4 UI_VERTEX_COLOR;
  44. ///////////////////////////////////////////////////////////////////////////////
  45. // 2D rendering functions
  46. void gl_state_for_2d(S32 width, S32 height);
  47. void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2);
  48. void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2, const LLColor4& color);
  49. void gl_triangle_2d(S32 x1, S32 y1, S32 x2, S32 y2, S32 x3, S32 y3,
  50. const LLColor4& color, bool filled);
  51. void gl_draw_x(const LLRect& rect, const LLColor4& color);
  52. void gl_rect_2d_simple(S32 width, S32 height);
  53. void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, bool filled = true);
  54. LL_INLINE void gl_rect_2d(const LLRect& rect, bool filled = true)
  55. {
  56. gl_rect_2d(rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, filled);
  57. }
  58. LL_INLINE void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom,
  59. const LLColor4& color, bool filled = true)
  60. {
  61. gGL.color4fv(color.mV);
  62. gl_rect_2d(left, top, right, bottom, filled);
  63. }
  64. LL_INLINE void gl_rect_2d(const LLRect& rect, const LLColor4& color,
  65. bool filled = true)
  66. {
  67. gGL.color4fv(color.mV);
  68. gl_rect_2d(rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, filled);
  69. }
  70. void gl_drop_shadow(S32 left, S32 top, S32 right, S32 bottom,
  71. const LLColor4& start_color, S32 lines);
  72. void gl_circle_2d(F32 x, F32 y, F32 radius, S32 steps, bool filled);
  73. void gl_arc_2d(F32 center_x, F32 center_y, F32 radius, S32 steps, bool filled,
  74. F32 start_angle, F32 end_angle);
  75. void gl_deep_circle(F32 radius, F32 depth);
  76. void gl_ring(F32 radius, F32 width, const LLColor4& center_color,
  77. const LLColor4& side_color, S32 steps, bool render_center);
  78. void gl_corners_2d(S32 left, S32 top, S32 right, S32 bottom, S32 length,
  79. F32 max_frac);
  80. void gl_washer_2d(F32 outer_radius, F32 inner_radius, S32 steps,
  81. const LLColor4& inner_color, const LLColor4& outer_color);
  82. void gl_washer_segment_2d(F32 outer_radius, F32 inner_radius,
  83. F32 start_radians, F32 end_radians, S32 steps,
  84. const LLColor4& inner_color,
  85. const LLColor4& outer_color);
  86. void gl_washer_spokes_2d(F32 outer_radius, F32 inner_radius, S32 count,
  87. const LLColor4& inner_color,
  88. const LLColor4& outer_color);
  89. void gl_draw_image(S32 x, S32 y, LLGLTexture* texp,
  90. const LLColor4& color = UI_VERTEX_COLOR,
  91. const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
  92. void gl_draw_scaled_image(S32 x, S32 y, S32 width, S32 height,
  93. LLGLTexture* texp,
  94. const LLColor4& color = UI_VERTEX_COLOR,
  95. const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
  96. void gl_draw_rotated_image(S32 x, S32 y, F32 degrees, LLGLTexture* texp,
  97. const LLColor4& color = UI_VERTEX_COLOR,
  98. const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
  99. void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height,
  100. F32 degrees, LLGLTexture* texp,
  101. const LLColor4& color = UI_VERTEX_COLOR,
  102. const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
  103. void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width,
  104. S32 border_height, S32 width, S32 height,
  105. LLGLTexture* texp, const LLColor4& color,
  106. bool solid_color = false,
  107. const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
  108. void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 width, S32 height,
  109. LLGLTexture* texp, const LLColor4& color,
  110. bool solid_color = false,
  111. const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f),
  112. const LLRectf& scale_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
  113. void gl_rect_2d_simple_tex(S32 width, S32 height);
  114. // segmented rectangles
  115. /*
  116. TL |______TOP_________| TR
  117. /| |\
  118. _/_|__________________|_\_
  119. L| | MIDDLE | |R
  120. _|_|__________________|_|_
  121. \ | BOTTOM | /
  122. BL\|__________________|/ BR
  123. | |
  124. */
  125. typedef enum e_rounded_edge
  126. {
  127. ROUNDED_RECT_LEFT = 0x1,
  128. ROUNDED_RECT_TOP = 0x2,
  129. ROUNDED_RECT_RIGHT = 0x4,
  130. ROUNDED_RECT_BOTTOM = 0x8,
  131. ROUNDED_RECT_ALL = 0xf
  132. } ERoundedEdge;
  133. void gl_segmented_rect_2d_tex(S32 left, S32 top, S32 right, S32 bottom,
  134. S32 texture_width, S32 texture_height,
  135. S32 border_size, U32 edges = ROUNDED_RECT_ALL);
  136. void gl_segmented_rect_2d_fragment_tex(S32 left, S32 top, S32 right, S32 bot,
  137. S32 texture_width, S32 texture_height,
  138. S32 border_size, F32 start_fragment,
  139. F32 end_fragment,
  140. U32 edges = ROUNDED_RECT_ALL);
  141. ///////////////////////////////////////////////////////////////////////////////
  142. // 3D rendering functions
  143. void gl_segmented_rect_3d_tex(const LLVector2& border_scale,
  144. const LLVector3& border_width,
  145. const LLVector3& border_height,
  146. const LLVector3& width_vec,
  147. const LLVector3& height_vec,
  148. U32 edges = ROUNDED_RECT_ALL);
  149. LL_INLINE void gl_segmented_rect_3d_tex_top(const LLVector2& border_scale,
  150. const LLVector3& border_width,
  151. const LLVector3& border_height,
  152. const LLVector3& width_vec,
  153. const LLVector3& height_vec)
  154. {
  155. gl_segmented_rect_3d_tex(border_scale, border_width, border_height,
  156. width_vec, height_vec, ROUNDED_RECT_TOP);
  157. }
  158. // The gl_draw_box*() functions below used to be drawBox*() functions
  159. // implemented in llspatialpartition.cpp (for debug display features) but are
  160. // also used elsewhere, so I grouped them here. HB
  161. // Note: unbinds the current vertex buffer.
  162. void gl_draw_box(const LLVector3& c, const LLVector3& r);
  163. LL_INLINE void gl_draw_box(const LLVector4a& c, const LLVector4a& r)
  164. {
  165. gl_draw_box(reinterpret_cast<const LLVector3&>(c),
  166. reinterpret_cast<const LLVector3&>(r));
  167. }
  168. void gl_draw_box_outline(const LLVector3& pos, const LLVector3& size);
  169. LL_INLINE void gl_draw_box_outline(const LLVector4a& pos,
  170. const LLVector4a& size)
  171. {
  172. gl_draw_box_outline(reinterpret_cast<const LLVector3&>(pos),
  173. reinterpret_cast<const LLVector3&>(size));
  174. }
  175. // Must be preceeded with gGL.begin(LLRender::LINES)
  176. void gl_draw_3d_cross_lines(const LLVector3& center, F32 dx, F32 dy, F32 dz);
  177. void gl_draw_3d_line_cube(F32 width, const LLVector3& center);
  178. // This used to be in llbox.h
  179. class LLBox
  180. {
  181. public:
  182. void prerender();
  183. void cleanupGL();
  184. void renderface(S32 which_face);
  185. void render();
  186. LL_INLINE U32 getTriangleCount() { return mTriangleCount; }
  187. protected:
  188. F32 mVertex[8][3];
  189. U32 mTriangleCount;
  190. };
  191. extern LLBox gBox;
  192. // This used to be in llcylinder.h
  193. class LLCone
  194. {
  195. public:
  196. void render(S32 sides = 12);
  197. };
  198. extern LLCone gCone;
  199. // This used to be in llrendersphere.h
  200. class LLRenderSphere
  201. {
  202. public:
  203. void render(); // Render at highest LOD
  204. void renderGGL(); // Render using LLRender
  205. private:
  206. std::vector<std::vector<LLVector3> > mSpherePoints;
  207. };
  208. extern LLRenderSphere gSphere;
  209. #endif // LL_RENDERUTILS_H