Changeset View
Changeset View
Standalone View
Standalone View
libkwineffects/kwinglutils.h
Show First 20 Lines • Show All 201 Lines • ▼ Show 20 Line(s) | |||||
202 | * @author Martin Gräßlin <mgraesslin@kde.org> | 202 | * @author Martin Gräßlin <mgraesslin@kde.org> | ||
203 | * @since 4.7 | 203 | * @since 4.7 | ||
204 | **/ | 204 | **/ | ||
205 | class KWINGLUTILS_EXPORT ShaderManager | 205 | class KWINGLUTILS_EXPORT ShaderManager | ||
206 | { | 206 | { | ||
207 | public: | 207 | public: | ||
208 | /** | 208 | /** | ||
209 | * Returns a shader with the given traits, creating it if necessary. | 209 | * Returns a shader with the given traits, creating it if necessary. | ||
210 | */ | 210 | **/ | ||
211 | GLShader *shader(ShaderTraits traits); | 211 | GLShader *shader(ShaderTraits traits); | ||
212 | 212 | | |||
213 | /** | 213 | /** | ||
214 | * @return The currently bound shader or @c null if no shader is bound. | 214 | * @return The currently bound shader or @c null if no shader is bound. | ||
215 | **/ | 215 | **/ | ||
216 | GLShader *getBoundShader() const; | 216 | GLShader *getBoundShader() const; | ||
217 | 217 | | |||
218 | /** | 218 | /** | ||
219 | * @return @c true if a shader is bound, @c false otherwise | 219 | * @return @c true if a shader is bound, @c false otherwise | ||
220 | **/ | 220 | **/ | ||
221 | bool isShaderBound() const; | 221 | bool isShaderBound() const; | ||
222 | /** | 222 | /** | ||
223 | * Is @c true if the environment variable KWIN_GL_DEBUG is set to 1. | 223 | * Is @c true if the environment variable KWIN_GL_DEBUG is set to 1. | ||
224 | * In that case shaders are compiled with KWIN_SHADER_DEBUG defined. | 224 | * In that case shaders are compiled with KWIN_SHADER_DEBUG defined. | ||
225 | * @returns @c true if shaders are compiled with debug information | 225 | * @returns @c true if shaders are compiled with debug information | ||
226 | * @since 4.8 | 226 | * @since 4.8 | ||
227 | **/ | 227 | **/ | ||
228 | bool isShaderDebug() const; | 228 | bool isShaderDebug() const; | ||
229 | 229 | | |||
230 | /** | 230 | /** | ||
231 | * Pushes the current shader onto the stack and binds a shader | 231 | * Pushes the current shader onto the stack and binds a shader | ||
232 | * with the given traits. | 232 | * with the given traits. | ||
233 | */ | 233 | **/ | ||
234 | GLShader *pushShader(ShaderTraits traits); | 234 | GLShader *pushShader(ShaderTraits traits); | ||
235 | 235 | | |||
236 | /** | 236 | /** | ||
237 | * Binds the @p shader. | 237 | * Binds the @p shader. | ||
238 | * To unbind the shader use popShader. A previous bound shader will be rebound. | 238 | * To unbind the shader use popShader. A previous bound shader will be rebound. | ||
239 | * To bind a built-in shader use the more specific method. | 239 | * To bind a built-in shader use the more specific method. | ||
240 | * @param shader The shader to be bound | 240 | * @param shader The shader to be bound | ||
241 | * @see popShader | 241 | * @see popShader | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
299 | * @see generateCustomShader | 299 | * @see generateCustomShader | ||
300 | * @since 5.6 | 300 | * @since 5.6 | ||
301 | **/ | 301 | **/ | ||
302 | GLShader *generateShaderFromResources(ShaderTraits traits, const QString &vertexFile = QString(), const QString &fragmentFile = QString()); | 302 | GLShader *generateShaderFromResources(ShaderTraits traits, const QString &vertexFile = QString(), const QString &fragmentFile = QString()); | ||
303 | 303 | | |||
304 | /** | 304 | /** | ||
305 | * Compiles and tests the dynamically generated shaders. | 305 | * Compiles and tests the dynamically generated shaders. | ||
306 | * Returns true if successful and false otherwise. | 306 | * Returns true if successful and false otherwise. | ||
307 | */ | 307 | **/ | ||
308 | bool selfTest(); | 308 | bool selfTest(); | ||
309 | 309 | | |||
310 | /** | 310 | /** | ||
311 | * @return a pointer to the ShaderManager instance | 311 | * @return a pointer to the ShaderManager instance | ||
312 | **/ | 312 | **/ | ||
313 | static ShaderManager *instance(); | 313 | static ShaderManager *instance(); | ||
314 | 314 | | |||
315 | /** | 315 | /** | ||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Line(s) | 419 | public: | |||
530 | } | 530 | } | ||
531 | 531 | | |||
532 | /** | 532 | /** | ||
533 | * The scale of the OpenGL window currently being rendered to | 533 | * The scale of the OpenGL window currently being rendered to | ||
534 | * | 534 | * | ||
535 | * @returns the ratio between the virtual geometry space the rendering | 535 | * @returns the ratio between the virtual geometry space the rendering | ||
536 | * system uses and the target | 536 | * system uses and the target | ||
537 | * @since 5.10 | 537 | * @since 5.10 | ||
538 | */ | 538 | **/ | ||
539 | static void setVirtualScreenScale(qreal scale) { | 539 | static void setVirtualScreenScale(qreal scale) { | ||
540 | s_virtualScreenScale = scale; | 540 | s_virtualScreenScale = scale; | ||
541 | } | 541 | } | ||
542 | 542 | | |||
543 | static qreal virtualScreenScale() { | 543 | static qreal virtualScreenScale() { | ||
544 | return s_virtualScreenScale; | 544 | return s_virtualScreenScale; | ||
545 | } | 545 | } | ||
546 | 546 | | |||
Show All 26 Lines | |||||
573 | }; | 573 | }; | ||
574 | 574 | | |||
575 | /** | 575 | /** | ||
576 | * Describes the format of a vertex attribute stored in a buffer object. | 576 | * Describes the format of a vertex attribute stored in a buffer object. | ||
577 | * | 577 | * | ||
578 | * The attribute format consists of the attribute index, the number of | 578 | * The attribute format consists of the attribute index, the number of | ||
579 | * vector components, the data type, and the offset of the first element | 579 | * vector components, the data type, and the offset of the first element | ||
580 | * relative to the start of the vertex data. | 580 | * relative to the start of the vertex data. | ||
581 | */ | 581 | **/ | ||
582 | struct GLVertexAttrib | 582 | struct GLVertexAttrib | ||
583 | { | 583 | { | ||
584 | int index; /** The attribute index */ | 584 | int index; /** The attribute index */ | ||
585 | int size; /** The number of components [1..4] */ | 585 | int size; /** The number of components [1..4] */ | ||
586 | GLenum type; /** The type (e.g. GL_FLOAT) */ | 586 | GLenum type; /** The type (e.g. GL_FLOAT) */ | ||
587 | int relativeOffset; /** The relative offset of the attribute */ | 587 | int relativeOffset; /** The relative offset of the attribute */ | ||
588 | }; | 588 | }; | ||
589 | 589 | | |||
590 | /** | 590 | /** | ||
591 | * @short Vertex Buffer Object | 591 | * @short Vertex Buffer Object | ||
592 | * | 592 | * | ||
593 | * This is a short helper class to use vertex buffer objects (VBO). A VBO can be used to buffer | 593 | * This is a short helper class to use vertex buffer objects (VBO). A VBO can be used to buffer | ||
594 | * vertex data and to store them on graphics memory. It is the only allowed way to pass vertex | 594 | * vertex data and to store them on graphics memory. It is the only allowed way to pass vertex | ||
595 | * data to the GPU in OpenGL ES 2 and OpenGL 3 with forward compatible mode. | 595 | * data to the GPU in OpenGL ES 2 and OpenGL 3 with forward compatible mode. | ||
596 | * | 596 | * | ||
597 | * If VBOs are not supported on the used OpenGL profile this class falls back to legacy | 597 | * If VBOs are not supported on the used OpenGL profile this class falls back to legacy | ||
598 | * rendering using client arrays. Therefore this class should always be used for rendering geometries. | 598 | * rendering using client arrays. Therefore this class should always be used for rendering geometries. | ||
599 | * | 599 | * | ||
600 | * @author Martin Gräßlin <mgraesslin@kde.org> | 600 | * @author Martin Gräßlin <mgraesslin@kde.org> | ||
601 | * @since 4.6 | 601 | * @since 4.6 | ||
602 | */ | 602 | **/ | ||
603 | class KWINGLUTILS_EXPORT GLVertexBuffer | 603 | class KWINGLUTILS_EXPORT GLVertexBuffer | ||
604 | { | 604 | { | ||
605 | public: | 605 | public: | ||
606 | /** | 606 | /** | ||
607 | * Enum to define how often the vertex data in the buffer object changes. | 607 | * Enum to define how often the vertex data in the buffer object changes. | ||
608 | */ | 608 | **/ | ||
609 | enum UsageHint { | 609 | enum UsageHint { | ||
610 | Dynamic, ///< frequent changes, but used several times for rendering | 610 | Dynamic, ///< frequent changes, but used several times for rendering | ||
611 | Static, ///< No changes to data | 611 | Static, ///< No changes to data | ||
612 | Stream ///< Data only used once for rendering, updated very frequently | 612 | Stream ///< Data only used once for rendering, updated very frequently | ||
613 | }; | 613 | }; | ||
614 | 614 | | |||
615 | explicit GLVertexBuffer(UsageHint hint); | 615 | explicit GLVertexBuffer(UsageHint hint); | ||
616 | ~GLVertexBuffer(); | 616 | ~GLVertexBuffer(); | ||
Show All 17 Lines | |||||
634 | * const GLVertexAttrib attribs[] = { | 634 | * const GLVertexAttrib attribs[] = { | ||
635 | * { VA_Position, 3, GL_FLOAT, offsetof(Vertex, position) }, | 635 | * { VA_Position, 3, GL_FLOAT, offsetof(Vertex, position) }, | ||
636 | * { VA_TexCoord, 2, GL_FLOAT, offsetof(Vertex, texcoord) } | 636 | * { VA_TexCoord, 2, GL_FLOAT, offsetof(Vertex, texcoord) } | ||
637 | * }; | 637 | * }; | ||
638 | * | 638 | * | ||
639 | * Vertex vertices[6]; | 639 | * Vertex vertices[6]; | ||
640 | * vbo->setAttribLayout(attribs, 2, sizeof(Vertex)); | 640 | * vbo->setAttribLayout(attribs, 2, sizeof(Vertex)); | ||
641 | * vbo->setData(vertices, sizeof(vertices)); | 641 | * vbo->setData(vertices, sizeof(vertices)); | ||
642 | */ | 642 | **/ | ||
643 | void setAttribLayout(const GLVertexAttrib *attribs, int count, int stride); | 643 | void setAttribLayout(const GLVertexAttrib *attribs, int count, int stride); | ||
644 | 644 | | |||
645 | /** | 645 | /** | ||
646 | * Uploads data into the buffer object's data store. | 646 | * Uploads data into the buffer object's data store. | ||
647 | */ | 647 | **/ | ||
648 | void setData(const void *data, size_t sizeInBytes); | 648 | void setData(const void *data, size_t sizeInBytes); | ||
649 | 649 | | |||
650 | /** | 650 | /** | ||
651 | * Sets the number of vertices that will be drawn by the render() method. | 651 | * Sets the number of vertices that will be drawn by the render() method. | ||
652 | */ | 652 | **/ | ||
653 | void setVertexCount(int count); | 653 | void setVertexCount(int count); | ||
654 | 654 | | |||
655 | /** | 655 | /** | ||
656 | * Sets the vertex data. | 656 | * Sets the vertex data. | ||
657 | * @param numberVertices The number of vertices in the arrays | 657 | * @param numberVertices The number of vertices in the arrays | ||
658 | * @param dim The dimension of the vertices: 2 for x/y, 3 for x/y/z | 658 | * @param dim The dimension of the vertices: 2 for x/y, 3 for x/y/z | ||
659 | * @param vertices The vertices, size must equal @a numberVertices * @a dim | 659 | * @param vertices The vertices, size must equal @a numberVertices * @a dim | ||
660 | * @param texcoords The texture coordinates for each vertex. | 660 | * @param texcoords The texture coordinates for each vertex. | ||
661 | * Size must equal 2 * @a numberVertices. | 661 | * Size must equal 2 * @a numberVertices. | ||
662 | */ | 662 | **/ | ||
663 | void setData(int numberVertices, int dim, const float* vertices, const float* texcoords); | 663 | void setData(int numberVertices, int dim, const float* vertices, const float* texcoords); | ||
664 | 664 | | |||
665 | /** | 665 | /** | ||
666 | * Maps an unused range of the data store into the client's address space. | 666 | * Maps an unused range of the data store into the client's address space. | ||
667 | * | 667 | * | ||
668 | * The data store will be reallocated if it is smaller than the given size. | 668 | * The data store will be reallocated if it is smaller than the given size. | ||
669 | * | 669 | * | ||
670 | * The buffer object is mapped for writing, not reading. Attempts to read from | 670 | * The buffer object is mapped for writing, not reading. Attempts to read from | ||
671 | * the mapped buffer range may result in system errors, including program | 671 | * the mapped buffer range may result in system errors, including program | ||
672 | * termination. The data in the mapped region is undefined until it has been | 672 | * termination. The data in the mapped region is undefined until it has been | ||
673 | * written to. If subsequent GL calls access unwritten memory, the results are | 673 | * written to. If subsequent GL calls access unwritten memory, the results are | ||
674 | * undefined and system errors, including program termination, may occur. | 674 | * undefined and system errors, including program termination, may occur. | ||
675 | * | 675 | * | ||
676 | * No GL calls that access the buffer object must be made while the buffer | 676 | * No GL calls that access the buffer object must be made while the buffer | ||
677 | * object is mapped. The returned pointer must not be passed as a parameter | 677 | * object is mapped. The returned pointer must not be passed as a parameter | ||
678 | * value to any GL function. | 678 | * value to any GL function. | ||
679 | * | 679 | * | ||
680 | * It is assumed that the GL_ARRAY_BUFFER_BINDING will not be changed while | 680 | * It is assumed that the GL_ARRAY_BUFFER_BINDING will not be changed while | ||
681 | * the buffer object is mapped. | 681 | * the buffer object is mapped. | ||
682 | */ | 682 | **/ | ||
683 | GLvoid *map(size_t size); | 683 | GLvoid *map(size_t size); | ||
684 | 684 | | |||
685 | /** | 685 | /** | ||
686 | * Flushes the mapped buffer range and unmaps the buffer. | 686 | * Flushes the mapped buffer range and unmaps the buffer. | ||
687 | */ | 687 | **/ | ||
688 | void unmap(); | 688 | void unmap(); | ||
689 | 689 | | |||
690 | /** | 690 | /** | ||
691 | * Binds the vertex arrays to the context. | 691 | * Binds the vertex arrays to the context. | ||
692 | */ | 692 | **/ | ||
693 | void bindArrays(); | 693 | void bindArrays(); | ||
694 | 694 | | |||
695 | /** | 695 | /** | ||
696 | * Disables the vertex arrays. | 696 | * Disables the vertex arrays. | ||
697 | */ | 697 | **/ | ||
698 | void unbindArrays(); | 698 | void unbindArrays(); | ||
699 | 699 | | |||
700 | /** | 700 | /** | ||
701 | * Draws count vertices beginning with first. | 701 | * Draws count vertices beginning with first. | ||
702 | */ | 702 | **/ | ||
703 | void draw(GLenum primitiveMode, int first, int count); | 703 | void draw(GLenum primitiveMode, int first, int count); | ||
704 | 704 | | |||
705 | /** | 705 | /** | ||
706 | * Draws count vertices beginning with first. | 706 | * Draws count vertices beginning with first. | ||
707 | */ | 707 | **/ | ||
708 | void draw(const QRegion ®ion, GLenum primitiveMode, int first, int count, bool hardwareClipping = false); | 708 | void draw(const QRegion ®ion, GLenum primitiveMode, int first, int count, bool hardwareClipping = false); | ||
709 | 709 | | |||
710 | /** | 710 | /** | ||
711 | * Renders the vertex data in given @a primitiveMode. | 711 | * Renders the vertex data in given @a primitiveMode. | ||
712 | * Please refer to OpenGL documentation of glDrawArrays or glDrawElements for allowed | 712 | * Please refer to OpenGL documentation of glDrawArrays or glDrawElements for allowed | ||
713 | * values for @a primitiveMode. Best is to use GL_TRIANGLES or similar to be future | 713 | * values for @a primitiveMode. Best is to use GL_TRIANGLES or similar to be future | ||
714 | * compatible. | 714 | * compatible. | ||
715 | */ | 715 | **/ | ||
716 | void render(GLenum primitiveMode); | 716 | void render(GLenum primitiveMode); | ||
717 | /** | 717 | /** | ||
718 | * Same as above restricting painting to @a region if @a hardwareClipping is true. | 718 | * Same as above restricting painting to @a region if @a hardwareClipping is true. | ||
719 | * It's within the caller's responsibility to enable GL_SCISSOR_TEST. | 719 | * It's within the caller's responsibility to enable GL_SCISSOR_TEST. | ||
720 | */ | 720 | **/ | ||
721 | void render(const QRegion& region, GLenum primitiveMode, bool hardwareClipping = false); | 721 | void render(const QRegion& region, GLenum primitiveMode, bool hardwareClipping = false); | ||
722 | /** | 722 | /** | ||
723 | * Sets the color the geometry will be rendered with. | 723 | * Sets the color the geometry will be rendered with. | ||
724 | * For legacy rendering glColor is used before rendering the geometry. | 724 | * For legacy rendering glColor is used before rendering the geometry. | ||
725 | * For core shader a uniform "geometryColor" is expected and is set. | 725 | * For core shader a uniform "geometryColor" is expected and is set. | ||
726 | * @param color The color to render the geometry | 726 | * @param color The color to render the geometry | ||
727 | * @param enableColor Whether the geometry should be rendered with a color or not | 727 | * @param enableColor Whether the geometry should be rendered with a color or not | ||
728 | * @see setUseColor | 728 | * @see setUseColor | ||
Show All 24 Lines | |||||
753 | * @since 4.7 | 753 | * @since 4.7 | ||
754 | **/ | 754 | **/ | ||
755 | void reset(); | 755 | void reset(); | ||
756 | 756 | | |||
757 | /** | 757 | /** | ||
758 | * Notifies the vertex buffer that we are done painting the frame. | 758 | * Notifies the vertex buffer that we are done painting the frame. | ||
759 | * | 759 | * | ||
760 | * @internal | 760 | * @internal | ||
761 | */ | 761 | **/ | ||
762 | void endOfFrame(); | 762 | void endOfFrame(); | ||
763 | 763 | | |||
764 | /** | 764 | /** | ||
765 | * Notifies the vertex buffer that we have posted the frame. | 765 | * Notifies the vertex buffer that we have posted the frame. | ||
766 | * | 766 | * | ||
767 | * @internal | 767 | * @internal | ||
768 | */ | 768 | **/ | ||
769 | void framePosted(); | 769 | void framePosted(); | ||
770 | 770 | | |||
771 | /** | 771 | /** | ||
772 | * @internal | 772 | * @internal | ||
773 | */ | 773 | **/ | ||
774 | static void initStatic(); | 774 | static void initStatic(); | ||
775 | 775 | | |||
776 | /** | 776 | /** | ||
777 | * @internal | 777 | * @internal | ||
778 | */ | 778 | **/ | ||
779 | static void cleanup(); | 779 | static void cleanup(); | ||
780 | 780 | | |||
781 | /** | 781 | /** | ||
782 | * Returns true if indexed quad mode is supported, and false otherwise. | 782 | * Returns true if indexed quad mode is supported, and false otherwise. | ||
783 | */ | 783 | **/ | ||
784 | static bool supportsIndexedQuads(); | 784 | static bool supportsIndexedQuads(); | ||
785 | 785 | | |||
786 | /** | 786 | /** | ||
787 | * @return A shared VBO for streaming data | 787 | * @return A shared VBO for streaming data | ||
788 | * @since 4.7 | 788 | * @since 4.7 | ||
789 | **/ | 789 | **/ | ||
790 | static GLVertexBuffer *streamingBuffer(); | 790 | static GLVertexBuffer *streamingBuffer(); | ||
791 | 791 | | |||
792 | /** | 792 | /** | ||
793 | * Sets the virtual screen geometry to @p g. | 793 | * Sets the virtual screen geometry to @p g. | ||
794 | * This is the geometry of the OpenGL window currently being rendered to | 794 | * This is the geometry of the OpenGL window currently being rendered to | ||
795 | * in the virtual geometry space the rendering geometries use. | 795 | * in the virtual geometry space the rendering geometries use. | ||
796 | * @since 5.9 | 796 | * @since 5.9 | ||
797 | **/ | 797 | **/ | ||
798 | static void setVirtualScreenGeometry(const QRect &g) { | 798 | static void setVirtualScreenGeometry(const QRect &g) { | ||
799 | s_virtualScreenGeometry = g; | 799 | s_virtualScreenGeometry = g; | ||
800 | } | 800 | } | ||
801 | 801 | | |||
802 | /** | 802 | /** | ||
803 | * The scale of the OpenGL window currently being rendered to | 803 | * The scale of the OpenGL window currently being rendered to | ||
804 | * | 804 | * | ||
805 | * @returns the ratio between the virtual geometry space the rendering | 805 | * @returns the ratio between the virtual geometry space the rendering | ||
806 | * system uses and the target | 806 | * system uses and the target | ||
807 | * @since 5.11.3 | 807 | * @since 5.11.3 | ||
808 | */ | 808 | **/ | ||
809 | static void setVirtualScreenScale(qreal s) { | 809 | static void setVirtualScreenScale(qreal s) { | ||
810 | s_virtualScreenScale = s; | 810 | s_virtualScreenScale = s; | ||
811 | } | 811 | } | ||
812 | 812 | | |||
813 | private: | 813 | private: | ||
814 | GLVertexBufferPrivate* const d; | 814 | GLVertexBufferPrivate* const d; | ||
815 | static QRect s_virtualScreenGeometry; | 815 | static QRect s_virtualScreenGeometry; | ||
816 | static qreal s_virtualScreenScale; | 816 | static qreal s_virtualScreenScale; | ||
Show All 9 Lines |