1 /************************************************************************************ 2 3 AstroMenace 4 Hardcore 3D space scroll-shooter with spaceship upgrade possibilities. 5 Copyright (c) 2006-2019 Mikhail Kurinnoi, Viewizard 6 7 8 AstroMenace is free software: you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 AstroMenace is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with AstroMenace. If not, see <https://www.gnu.org/licenses/>. 20 21 22 Website: https://viewizard.com/ 23 Project: https://github.com/viewizard/astromenace 24 E-mail: viewizard@viewizard.com 25 26 *************************************************************************************/ 27 28 // TODO check sources, direct OpenGL usage outside 'graphics' are prohibited, 29 // for 'graphics' code - switch to "vw_*" functions-wrappers for OpenGL if possible. 30 31 /* 32 Direct OpenGL usage outside 'graphics' are prohibited. 33 'graphics' code should also use "vw_*" functions-wrappers for OpenGL if possible. 34 35 Since OpenGL is evolving, more and more features allowed for new hardware. 36 'graphics' provide "vw_*" functions-wrappers for OpenGL, that use best solutions 37 for current hardware (and supported by code at this moment). 38 */ 39 40 #ifndef CORE_GRAPHICS_GRAPHICS_H 41 #define CORE_GRAPHICS_GRAPHICS_H 42 43 #include "../base.h" 44 #include "opengl.h" 45 46 namespace viewizard { 47 48 struct sRECT; 49 struct sVECTOR3D; 50 class cTexture; 51 52 enum class eOrigin { 53 upper_left, 54 bottom_left 55 }; 56 57 enum class ePrimitiveType : GLenum { 58 LINES = GL_LINES, 59 TRIANGLES = GL_TRIANGLES, 60 TRIANGLE_STRIP = GL_TRIANGLE_STRIP, 61 TRIANGLE_FAN = GL_TRIANGLE_FAN 62 }; 63 64 enum class eCompareFunc : GLint { 65 LEQUAL = GL_LEQUAL, 66 GEQUAL = GL_GEQUAL, 67 LESS = GL_LESS, 68 GREATER = GL_GREATER, 69 EQUAL = GL_EQUAL, 70 NOTEQUAL = GL_NOTEQUAL, 71 ALWAYS = GL_ALWAYS, 72 NEVER = GL_NEVER 73 }; 74 75 enum class eMatrixMode : GLenum { 76 PROJECTION = GL_PROJECTION, 77 MODELVIEW = GL_MODELVIEW, 78 TEXTURE = GL_TEXTURE 79 }; 80 81 enum class eMatrixPname : GLenum { 82 PROJECTION = GL_PROJECTION_MATRIX, 83 MODELVIEW = GL_MODELVIEW_MATRIX, 84 TEXTURE = GL_TEXTURE_MATRIX 85 }; 86 87 enum class eTextureBlendFactor : GLenum { 88 ZERO = GL_ZERO, 89 ONE = GL_ONE, 90 SRC_COLOR = GL_SRC_COLOR, 91 ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR, 92 DST_COLOR = GL_DST_COLOR, 93 MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR, 94 SRC_ALPHA = GL_SRC_ALPHA, 95 ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA, 96 DST_ALPHA = GL_DST_ALPHA, 97 ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA, 98 CONSTANT_COLOR = GL_CONSTANT_COLOR, 99 ONE_MINUS_CONSTANT_COLOR = GL_ONE_MINUS_CONSTANT_COLOR, 100 CONSTANT_ALPHA = GL_CONSTANT_ALPHA, 101 ONE_MINUS_CONSTANT_ALPHA = GL_ONE_MINUS_CONSTANT_ALPHA, 102 SRC_ALPHA_SATURATE = GL_SRC_ALPHA_SATURATE, 103 SRC1_COLOR = GL_SRC1_COLOR, 104 ONE_MINUS_SRC1_COLOR = GL_ONE_MINUS_SRC1_COLOR, 105 SRC1_ALPHA = GL_SRC1_ALPHA, 106 ONE_MINUS_SRC1_ALPHA = GL_ONE_MINUS_SRC1_ALPHA 107 }; 108 109 enum class eTextureEnvMode : GLint { 110 DECAL = GL_DECAL, 111 BLEND = GL_BLEND, 112 REPLACE = GL_REPLACE, 113 ADD = GL_ADD, 114 COMBINE = GL_COMBINE, 115 MODULATE = GL_MODULATE 116 }; 117 118 enum class eTextureDepthMode : GLint { 119 LUMINANCE = GL_LUMINANCE, 120 INTENSITY = GL_INTENSITY, 121 ALPHA = GL_ALPHA 122 }; 123 124 enum class eTextureCompareMode : GLint { 125 REF_TO_TEXTURE = GL_COMPARE_REF_TO_TEXTURE, 126 NONE = GL_NONE 127 }; 128 129 enum class eTextureWrapCoord : GLenum { 130 S = GL_TEXTURE_WRAP_S, 131 T = GL_TEXTURE_WRAP_T, 132 R = GL_TEXTURE_WRAP_R 133 }; 134 135 enum class eTextureWrapMode : GLint { 136 CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE, 137 CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER, 138 MIRRORED_REPEAT = GL_MIRRORED_REPEAT, 139 REPEAT = GL_REPEAT, 140 MIRROR_CLAMP_TO_EDGE = GL_MIRROR_CLAMP_TO_EDGE 141 }; 142 143 struct sTextureWrap { 144 eTextureWrapMode S{eTextureWrapMode::REPEAT}; 145 eTextureWrapMode T{eTextureWrapMode::REPEAT}; 146 eTextureWrapMode R{eTextureWrapMode::REPEAT}; 147 148 sTextureWrap() = default; sTextureWrapsTextureWrap149 explicit sTextureWrap(eTextureWrapMode param) : 150 S{param}, 151 T{param}, 152 R{param} 153 {} 154 }; 155 156 enum class eTextureMinFilter : GLint { 157 NEAREST = GL_NEAREST, 158 LINEAR = GL_LINEAR, 159 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST, 160 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST, 161 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR, 162 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR 163 }; 164 165 enum class eTextureMagFilter : GLint { 166 NEAREST = GL_NEAREST, 167 LINEAR = GL_LINEAR 168 }; 169 170 enum class eTextureBasicFilter { 171 NONE, 172 BILINEAR, 173 TRILINEAR 174 }; 175 176 struct sTextureFilter { 177 eTextureMinFilter Min{eTextureMinFilter::NEAREST_MIPMAP_LINEAR}; 178 eTextureMagFilter Mag{eTextureMagFilter::LINEAR}; 179 180 sTextureFilter() = default; sTextureFiltersTextureFilter181 explicit sTextureFilter(eTextureBasicFilter Filter) 182 { 183 switch (Filter) { 184 case eTextureBasicFilter::NONE: 185 Min = eTextureMinFilter::NEAREST; 186 Mag = eTextureMagFilter::NEAREST; 187 break; 188 case eTextureBasicFilter::BILINEAR: 189 Min = eTextureMinFilter::LINEAR; 190 Mag = eTextureMagFilter::LINEAR; 191 break; 192 case eTextureBasicFilter::TRILINEAR: 193 Min = eTextureMinFilter::LINEAR_MIPMAP_LINEAR; 194 Mag = eTextureMagFilter::LINEAR; 195 break; 196 } 197 } 198 }; 199 200 enum class eTextureCombinerName : GLenum { 201 COMBINE_RGB = GL_COMBINE_RGB 202 }; 203 204 enum class eTextureCombinerOp : GLint { 205 ADD = GL_ADD 206 }; 207 208 enum class eTextureCompressionType : int { 209 NONE = 0, 210 S3TC = 1, 211 BPTC = 2 212 }; 213 214 enum class eMaterialParameter : GLenum { 215 AMBIENT = GL_AMBIENT, 216 DIFFUSE = GL_DIFFUSE, 217 SPECULAR = GL_SPECULAR, 218 EMISSION = GL_EMISSION, 219 SHININESS = GL_SHININESS 220 }; 221 222 enum class eLightParameter : GLenum { 223 SPOT_EXPONENT = GL_SPOT_EXPONENT, 224 SPOT_CUTOFF = GL_SPOT_CUTOFF, 225 CONSTANT_ATTENUATION = GL_CONSTANT_ATTENUATION, 226 LINEAR_ATTENUATION = GL_LINEAR_ATTENUATION, 227 QUADRATIC_ATTENUATION = GL_QUADRATIC_ATTENUATION 228 }; 229 230 enum class eLightVParameter : GLenum { 231 SPOT_EXPONENT = GL_SPOT_EXPONENT, 232 SPOT_CUTOFF = GL_SPOT_CUTOFF, 233 CONSTANT_ATTENUATION = GL_CONSTANT_ATTENUATION, 234 LINEAR_ATTENUATION = GL_LINEAR_ATTENUATION, 235 QUADRATIC_ATTENUATION = GL_QUADRATIC_ATTENUATION, 236 AMBIENT = GL_AMBIENT, 237 DIFFUSE = GL_DIFFUSE, 238 SPECULAR = GL_SPECULAR, 239 POSITION = GL_POSITION, 240 SPOT_DIRECTION = GL_SPOT_DIRECTION 241 }; 242 243 enum class eBufferObject : GLenum { 244 Vertex = GL_ARRAY_BUFFER, 245 Index = GL_ELEMENT_ARRAY_BUFFER 246 }; 247 248 enum class eBufferObjectUsage : GLenum { 249 STREAM = GL_STREAM_DRAW, // The data store contents will be modified once and used at most a few times. 250 STATIC = GL_STATIC_DRAW, // The data store contents will be modified once and used many times. 251 DYNAMIC = GL_DYNAMIC_DRAW // The data store contents will be modified repeatedly and used many times. 252 }; 253 254 enum class eCullFace : GLenum { 255 NONE = GL_NONE, 256 BACK = GL_BACK, 257 FRONT = GL_FRONT, 258 FRONT_AND_BACK = GL_FRONT_AND_BACK 259 }; 260 261 struct sCoverageModes { 262 int ColorSamples{0}; 263 int CoverageSamples{0}; 264 265 sCoverageModes() = default; sCoverageModessCoverageModes266 explicit sCoverageModes(int _ColorSamples, int _CoverageSamples) : 267 ColorSamples{_ColorSamples}, 268 CoverageSamples{_CoverageSamples} 269 {} 270 }; 271 272 enum class eRGBCOLOR { 273 white, 274 black, 275 red, 276 green, 277 blue, 278 yellow, 279 orange 280 }; 281 282 struct sRGBCOLOR { 283 float r{0.0f}; 284 float g{0.0f}; 285 float b{0.0f}; 286 287 sRGBCOLOR() = default; sRGBCOLORsRGBCOLOR288 explicit sRGBCOLOR(float _r, float _g, float _b) : 289 r{_r}, 290 g{_g}, 291 b{_b} 292 {} sRGBCOLORsRGBCOLOR293 explicit sRGBCOLOR(eRGBCOLOR color) 294 { 295 switch (color) { 296 case eRGBCOLOR::white: 297 r = 1.0f; 298 g = 1.0f; 299 b = 1.0f; 300 break; 301 case eRGBCOLOR::black: 302 r = 0.0f; 303 g = 0.0f; 304 b = 0.0f; 305 break; 306 case eRGBCOLOR::red: 307 r = 1.0f; 308 g = 0.0f; 309 b = 0.0f; 310 break; 311 case eRGBCOLOR::green: 312 r = 0.0f; 313 g = 1.0f; 314 b = 0.0f; 315 break; 316 case eRGBCOLOR::blue: 317 r = 0.0f; 318 g = 0.0f; 319 b = 1.0f; 320 break; 321 case eRGBCOLOR::yellow: 322 r = 1.0f; 323 g = 1.0f; 324 b = 0.0f; 325 break; 326 case eRGBCOLOR::orange: 327 r = 1.0f; 328 g = 0.5f; 329 b = 0.0f; 330 break; 331 } 332 } 333 }; 334 335 struct sDevCaps { 336 int OpenGLmajorVersion{0}; 337 int OpenGLminorVersion{0}; 338 int MaxTextureWidth{0}; 339 int MaxTextureHeight{0}; 340 int MaxActiveLights{0}; 341 GLint MaxAnisotropyLevel{0}; // could be 0 (not supported by hardware/drivers) 342 // MSAA + CSAA modes 343 std::vector<sCoverageModes> MultisampleCoverageModes{}; 344 // available depth's size for FBO 345 GLint FramebufferObjectDepthSize{0}; 346 347 bool OpenGL_1_3_supported{false}; 348 bool OpenGL_1_5_supported{false}; 349 bool OpenGL_2_0_supported{false}; 350 bool OpenGL_2_1_supported{false}; 351 bool OpenGL_3_0_supported{false}; 352 bool OpenGL_4_2_supported{false}; 353 354 bool EXT_texture_compression_s3tc{false}; 355 bool ARB_texture_compression_bptc{false}; // note, bptc also part of OpenGL 4.2 356 bool ARB_texture_non_power_of_two{false}; 357 bool SGIS_generate_mipmap{false}; 358 }; 359 360 // Buffer clear bit 361 #define RI_COLOR_BUFFER 0x1000 362 #define RI_DEPTH_BUFFER 0x0100 363 #define RI_ACCUM_BUFFER 0x0010 364 #define RI_STENCIL_BUFFER 0x0001 365 366 // Data format 367 #define RI_COORD 0x000F000 368 #define RI_3f_XYZ 0x0001000 369 #define RI_2f_XY 0x0002000 370 #define RI_NORMAL 0x0000F00 371 #define RI_3f_NORMAL 0x0000100 372 #define RI_COLOR 0x00000F0 373 #define RI_4f_COLOR 0x0000010 374 #define RI_TEXTURE 0x0F00000 375 #define RI_2f_TEX 0x0200000 376 // кол-во текстур 377 #define RI_TEX_COUNT 0x000000F 378 #define RI_1_TEX 0x0000001 379 #define RI_2_TEX 0x0000002 380 #define RI_3_TEX 0x0000003 381 #define RI_4_TEX 0x0000004 382 #define RI_5_TEX 0x0000005 383 #define RI_6_TEX 0x0000006 384 #define RI_7_TEX 0x0000007 385 #define RI_8_TEX 0x0000008 386 // тип работы с координатами текстуры 387 #define RI_TEX_COORD_TYPE 0xF000000 388 #define RI_SEPARATE_TEX_COORD 0x0000000 389 #define RI_DUBLICATE_TEX_COORD 0x1000000 390 391 392 /* 393 * gl_main 394 */ 395 396 // Create window. 397 bool vw_CreateWindow(const char *Title, int Width, int Height, bool Fullscreen, int DisplayIndex); 398 // Destroy window. 399 void vw_DestroyWindow(); 400 // Get SDL window handle. 401 SDL_Window *vw_GetSDLWindow(); 402 // Create OpenGL context. 403 bool vw_CreateOpenGLContext(int VSync); 404 // Delete OpenGL context. 405 void vw_DeleteOpenGLContext(); 406 // Initialize (or reinitialize) and setup OpenGL related stuff. 407 void vw_InitOpenGLStuff(int Width, int Height, int *MSAA, int *CSAA); 408 // Release OpenGL related stuff. 409 void vw_ReleaseOpenGLStuff(); 410 // Get device capability. 411 const sDevCaps &vw_DevCaps(); 412 413 // Set virtual internal resolution size and status. 414 void vw_SetInternalResolution(float Width, float Height, bool Status); 415 // Get virtual internal resolution. 416 bool vw_GetInternalResolution(float *Width, float *Height); 417 418 // Set viewport data. 419 void vw_SetViewport(GLint x, GLint y, GLsizei width, GLsizei height, eOrigin Origin = eOrigin::upper_left); 420 // Get viewport data. 421 void vw_GetViewport(float *x = nullptr, float *y = nullptr, float *width = nullptr, float *height = nullptr); 422 // Get viewport data. 423 void vw_GetViewport(int *x = nullptr, int *y = nullptr, int *width = nullptr, int *height = nullptr); 424 // Set depth range. 425 void vw_DepthRange(GLdouble zNear, GLdouble zFar); 426 // Resize scene. 427 void vw_ResizeScene(float FieldOfViewAngle, float AspectRatio, float zNearClip, float zFarClip); 428 429 // Begin rendering. 430 void vw_BeginRendering(int mask); 431 // End rendering. 432 void vw_EndRendering(); 433 // Clear buffers. 434 void vw_Clear(int mask); 435 // Specify clear values for the color buffers. 436 void vw_SetClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); 437 // Specifies whether the individual color components in the frame buffer can or cannot be written. 438 void vw_SetColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); 439 // Set color. 440 void vw_SetColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); 441 // Set what facets can be culled. 442 void vw_CullFace(eCullFace mode); 443 // Set depth buffer. 444 void vw_DepthTest(bool mode, eCompareFunc func); 445 // Set the scale and units used to calculate depth values. 446 void vw_PolygonOffset(bool status, GLfloat factor, GLfloat units); 447 448 /* 449 * gl_texture 450 */ 451 452 // Create texture. 453 GLtexture vw_BuildTexture(const std::unique_ptr<uint8_t[]> &PixelsArray, 454 GLsizei Width, GLsizei Height, bool MipMap, int Bytes, 455 eTextureCompressionType CompressionType); 456 // Select active texture unit (starts from 0, for GL_TEXTURE0 unit). 457 void vw_SelectActiveTextureUnit(GLenum Unit); 458 // Bind texture for particular texture unit (starts from 0, for GL_TEXTURE0 unit). 459 void vw_BindTexture(GLenum Unit, GLtexture TextureID); 460 // Delete texture. 461 void vw_DeleteTexture(GLtexture TextureID); 462 // Set texture filtering mode. 463 void vw_SetTextureFiltering(eTextureMinFilter MinFilter, eTextureMagFilter MagFilter); 464 // Set texture filtering mode. 465 void vw_SetTextureFiltering(const sTextureFilter &Filter); 466 // Set texture Anisotropy Level. 467 void vw_SetTextureAnisotropy(GLint AnisotropyLevel); 468 // Set texture address mode. 469 void vw_SetTextureAddressMode(eTextureWrapCoord coord, eTextureWrapMode mode); 470 // Set texture address mode. 471 void vw_SetTextureAddressMode(const sTextureWrap &wrap); 472 // Set texture Alpha Test value that specifies a reference alpha value against which pixels are tested. 473 void vw_SetTextureAlphaTest(bool flag, eCompareFunc func, GLclampf ref); 474 // Set texture blending factor. 475 void vw_SetTextureBlend(bool flag, eTextureBlendFactor sfactor, eTextureBlendFactor dfactor); 476 // Set texture blending mode. 477 void vw_SetTextureBlendMode(eTextureCombinerName name, eTextureCombinerOp param); 478 // Set texture env mode. 479 void vw_SetTextureEnvMode(eTextureEnvMode mode); 480 // Set texture compare mode. 481 void vw_SetTextureCompare(eTextureCompareMode mode, eCompareFunc func); 482 // Set texture depth mode. 483 void vw_SetTextureDepthMode(eTextureDepthMode mode); 484 485 /* 486 * gl_draw3d 487 */ 488 489 // Draw 3D primitives. 490 void vw_Draw3D(ePrimitiveType mode, GLsizei count, int DataFormat, GLvoid *VertexArray, 491 GLsizei Stride, GLuint VertexBO = 0, unsigned int RangeStart = 0, 492 unsigned int *IndexArray = nullptr, GLuint IndexBO = 0, GLuint VAO = 0); 493 494 /* 495 * gl_matrix 496 */ 497 498 // Replace the current matrix with the identity matrix. 499 void vw_LoadIdentity(); 500 // Produce a translation by sVECTOR3D. 501 void vw_Translate(sVECTOR3D Location); 502 // Produce a rotation of angle degrees around the vector x, y and z. 503 void vw_Rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); 504 // Produce a nonuniform scaling along the x, y, and z axes. 505 void vw_Scale(GLfloat x, GLfloat y, GLfloat z); 506 // Push the current matrix stack. 507 void vw_PushMatrix(); 508 // Pop the current matrix stack. 509 void vw_PopMatrix(); 510 // Get matrix from the top of the matrix stack. 511 void vw_GetMatrix(eMatrixPname pname, GLfloat *params); 512 // Replace the current matrix with an arbitrary matrix. 513 void vw_SetMatrix(const GLfloat *matrix); 514 // Sets the current matrix mode. 515 void vw_MatrixMode(eMatrixMode mode); 516 // Multiply the current matrix by an arbitrary matrix. 517 void vw_MultMatrix(const GLfloat *matrix); 518 519 /* 520 * gl_light 521 */ 522 523 // Set lighting status. 524 void vw_Lighting(bool param); 525 // Enable light. 526 void vw_LightEnable(GLenum light, bool param); 527 // Set light parameter. 528 void vw_SetLight(GLenum light, eLightParameter pname, GLfloat param); 529 // Set light parameter by array. 530 void vw_SetLightV(GLenum light, eLightVParameter pname, const GLfloat *param); 531 // Set material parameter by array. 532 void vw_MaterialV(eMaterialParameter pname, const GLfloat *param); 533 534 /* 535 * gl_vbo 536 */ 537 538 // Build buffer object (size in bytes). 539 bool vw_BuildBufferObject(eBufferObject target, GLsizeiptr size, const GLvoid *data, 540 GLuint &buffer, eBufferObjectUsage usage = eBufferObjectUsage::STATIC); 541 // Bind buffer object. 542 void vw_BindBufferObject(eBufferObject target, GLuint buffer); 543 // Delete buffer object. 544 void vw_DeleteBufferObject(GLuint &buffer); 545 546 /* 547 * gl_vao 548 */ 549 550 // Build vertex array object. 551 bool vw_BuildVAO(GLuint &VAO, int DataFormat, GLsizei Stride, GLuint VertexBO, GLuint IndexBO); 552 // Bind vertex array object. 553 void vw_BindVAO(GLuint VAO); 554 // Delete vertex array object. 555 void vw_DeleteVAO(GLuint &VAO); 556 557 /* 558 * gl_fbo 559 */ 560 561 struct sFBO { 562 friend std::shared_ptr<sFBO> vw_BuildFBO(GLsizei Width, GLsizei Height, bool NeedColor, 563 bool NeedDepth, GLsizei MSAA, GLsizei *CSAA); 564 public: 565 GLrenderbuffer ColorBuffer{0}; 566 GLrenderbuffer DepthBuffer{0}; 567 GLtexture ColorTexture{0}; 568 GLtexture DepthTexture{0}; 569 GLint DepthSize{0}; 570 GLframebuffer FrameBufferObject{0}; 571 // we are safe with sIF_dual_type here, since Width and Height not exceed 'float' 572 sIF_dual_type<GLsizei, float> Width{0}; 573 sIF_dual_type<GLsizei, float> Height{0}; 574 575 private: 576 // Don't allow direct new/delete usage in code, only vw_BuildFBO() 577 // allowed for FBO creation and release setup (deleter must be provided). 578 sFBO() = default; 579 ~sFBO(); 580 }; 581 582 // Build FBO. 583 std::shared_ptr<sFBO> vw_BuildFBO(GLsizei Width, GLsizei Height, bool NeedColor, 584 bool NeedDepth, GLsizei MSAA = 0, GLsizei *CSAA = nullptr); 585 // Bind FBO. 586 void vw_BindFBO(std::shared_ptr<sFBO> &FBO); 587 // Get current FBO (nullptr if FrameBuffer). 588 std::weak_ptr<sFBO> &vw_GetCurrentFBO(); 589 // Blit color part of source FBO to target FBO (need this one in order to work with multi samples). 590 void vw_BlitFBO(std::shared_ptr<sFBO> &SourceFBO, std::shared_ptr<sFBO> &TargetFBO); 591 // Draw source FBO (color texture) to target FBO (if null, to FrameBuffer). 592 void vw_DrawColorFBO(std::shared_ptr<sFBO> &SourceFBO, std::shared_ptr<sFBO> &TargetFBO); 593 594 /* 595 * gl_glsl 596 */ 597 598 struct cGLSL; 599 600 // Create shader program. 601 std::weak_ptr<cGLSL> vw_CreateShader(const std::string &ShaderName, 602 const std::string &VertexShaderFileName, 603 const std::string &FragmentShaderFileName); 604 // Release all shaders. 605 void vw_ReleaseAllShaders(); 606 // Check, is shaders Map empty. 607 bool vw_ShadersMapEmpty(); 608 // Find shader by name. 609 std::weak_ptr<cGLSL> vw_FindShaderByName(const std::string &Name); 610 // Find and store uniform location in shader. Return internal storage number for future use. 611 int vw_FindShaderUniformLocation(std::weak_ptr<cGLSL> &GLSL, const std::string &UniformName); 612 // Get previously found in shader uniform's location by internal storage number. 613 GLint vw_GetShaderUniformLocation(std::shared_ptr<cGLSL> sharedGLSL, int UniformNumber); 614 // Links a program object. 615 bool vw_LinkShaderProgram(std::weak_ptr<cGLSL> &GLSL); 616 // Installs a program object as part of current rendering state. 617 bool vw_UseShaderProgram(std::shared_ptr<cGLSL> &sharedGLSL); 618 // Installs a program object as part of current rendering state. 619 bool vw_UseShaderProgram(std::weak_ptr<cGLSL> &GLSL); 620 // Switch to fixed-function program object as part of current rendering state. 621 bool vw_StopShaderProgram(); 622 // Returns the location of a uniform variable. 623 GLint vw_GetUniformLocation(std::weak_ptr<cGLSL> &GLSL, const std::string &Name); 624 // Specify the value of a uniform variable for the current program object. 625 bool vw_Uniform1i(GLint UniformLocation, int data); 626 // Specify the value of a uniform variable for the current program object. 627 bool vw_Uniform1f(GLint UniformLocation, float data); 628 // Specify the value of a uniform variable for the current program object. 629 bool vw_Uniform3f(GLint UniformLocation, float data1, float data2, float data3); 630 631 /* 632 * gl_draw2d 633 */ 634 635 // Switch to 2D rendering mode. Origin is upper left corner. 636 void vw_Start2DMode(GLdouble zNear, GLdouble zFar); 637 // Switch back to 3D rendering mode. 638 void vw_End2DMode(); 639 // Draw transparent. Origin is upper left corner. 640 void vw_Draw2D(const sRECT &DstRect, const sRECT &SrcRect, GLtexture Texture, bool Alpha, float Transp = 1.0f, 641 float RotateAngle = 0.0f, const sRGBCOLOR &Color = sRGBCOLOR{eRGBCOLOR::white}); 642 643 /* 644 * misc 645 */ 646 647 // Create screenshot from current OpenGL surface. 648 int vw_Screenshot(int Width, int Height, const std::string &FileName); 649 650 } // viewizard namespace 651 652 #endif // CORE_GRAPHICS_GRAPHICS_H 653