/**************************************************************************** ** ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the Qt scene graph research project. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the Technology Preview License Agreement accompanying ** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. ** ** ** ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef ADAPTATIONINTERFACES_H #define ADAPTATIONINTERFACES_H #include #include #include #include #include #include #include "node.h" class Node; class QImage; class TextureReference; // TODO: Rename from XInterface to AbstractX. class RectangleNodeInterface : public GeometryNode { public: RectangleNodeInterface() : m_radius(0), m_opacity(1), m_pen_width(0) { } virtual void setRect(const QRectF &rect) = 0; QRectF rect() const { return m_rect; } virtual void setColor(const QColor &color) = 0; QColor color() const { return m_color; } virtual void setPenColor(const QColor &color) = 0; QColor penColor() const { return m_pen_color; } virtual void setPenWidth(int width) = 0; int penWidth() const { return m_pen_width; } virtual void setOpacity(qreal opacity) = 0; qreal opacity() const { return m_opacity; } virtual void setGradientStops(const QGradientStops &stops) = 0; QGradientStops gradientStops() const { return m_gradient_stops; } virtual void setRadius(qreal radius) = 0; qreal radius() const { return m_radius; } protected: QRectF m_rect; QGradientStops m_gradient_stops; QColor m_color; QColor m_pen_color; qreal m_radius; qreal m_opacity; int m_pen_width; }; class TextureNodeInterface : public GeometryNode { public: TextureNodeInterface() : m_texture(0), m_opacity(1), m_clamp_to_edge(true), m_linear_filtering(false) { } virtual void setRect(const QRectF &rect) = 0; QRectF rect() const { return m_rect; } // Normalized source coordinates.. virtual void setSourceRect(const QRectF &rect) = 0; QRectF sourceRect() const { return m_source_rect; } virtual void setOpacity(qreal opacity) = 0; qreal opacity() const { return m_opacity; } virtual void setTexture(const TextureReference *ref) = 0; const TextureReference *texture() const; virtual void setClampToEdge(bool clampToEdge) = 0; bool clampToEdge() const { return m_clamp_to_edge; } virtual void setLinearFiltering(bool linearFiltering) = 0; bool linearFiltering() const { return m_linear_filtering; } protected: const TextureReference *m_texture; QRectF m_rect; QRectF m_source_rect; qreal m_opacity; bool m_clamp_to_edge; bool m_linear_filtering; }; class TextureReference : public QObject { Q_OBJECT public: enum Status { Null, Uploaded, Uploading, Error }; TextureReference(); ~TextureReference(); void setTextureId(int id) { m_texture_id = id; } int textureId() const { return m_texture_id; } void setTextureSize(const QSize &size) { m_texture_size = size; } QSize textureSize() const { return m_texture_size; } void setSubRect(const QRectF &subrect) { m_sub_rect = subrect; } QRectF subRect() const { return m_sub_rect; } void setAlphaChannel(bool hasAlpha) { m_has_alpha = hasAlpha; } bool hasAlphaChannel() const { return m_has_alpha; } void setOwnsTexture(bool owns) { m_owns_texture = owns; } bool ownsTexture() const { return m_owns_texture; } void setMipmaps(bool mipmapped) { m_mipmap = mipmapped; } bool hasMipmaps() const { return m_mipmap; } /* ### gunnar: the texture reference is potentially written to in a thread while uploading, so ANY access to the other accessors is strictly not allowed until status returns Uploaded. To support fetching and writing status from multiple threads, which I'm unsure if will happen, we should change status to be an QAtomicInt */ void setStatus(Status s); Status status() const { return m_status; } signals: void statusChanged(int status); protected: Status m_status; int m_texture_id; QSize m_texture_size; QRectF m_sub_rect; uint m_has_alpha : 1; uint m_owns_texture : 1; uint m_mipmap : 1; }; class TextureManager { public: enum UploadHint { SynchronousUploadHint = 0x0001, CanUseAtlasUploadHint = 0x0002, GenerateMipmapUploadHint = 0x0004, DefaultUploadHints = 0 }; Q_DECLARE_FLAGS(UploadHints, UploadHint); virtual ~TextureManager() { }; virtual const TextureReference *requestUploadedTexture(const QImage &image, UploadHints hints = DefaultUploadHints, QObject *listener = 0, const char *slot = 0); }; //typedef QSharedPointer QGLTexture2DConstPtr; //typedef QSharedPointer QGLTexture2DPtr; //class TextureAtlasInterface //{ //public: // enum Flag // { // DynamicFlag = 0x01 // Set if images are added to the texture atlas every few frames. // }; // TextureAtlasInterface(uint flags) : m_flags(flags) { } // virtual ~TextureAtlasInterface() { } // virtual QGLTexture2DConstPtr texture() = 0; // virtual QRect allocate(const QImage &image, bool clampToEdge) = 0; // virtual void deallocate(const QRect &rect) = 0; // uint flags() const { return m_flags; } //protected: // uint m_flags; //}; class GlyphNodeInterface: public GeometryNode { public: GlyphNodeInterface() : m_opacity(1.0) {} virtual void setGlyphs(const QPointF &position, const QGlyphs &glyphs) = 0; QPointF position() const { return m_position; } QGlyphs glyphs() const { return m_glyphs; } virtual void setOpacity(qreal opacity) = 0; qreal opacity() const { return m_opacity; } virtual void setColor(const QColor &color) = 0; QColor color() const { return m_color; } virtual QPointF baseLine() const = 0; protected: qreal m_opacity; QGlyphs m_glyphs; QPointF m_position; QColor m_color; }; class AdaptationLayerInterface { public: virtual RectangleNodeInterface *createRectangleNode() = 0; virtual TextureNodeInterface *createTextureNode() = 0; virtual GlyphNodeInterface *createGlyphNode() = 0; virtual Renderer *createRenderer() = 0; virtual TextureManager *textureManager() = 0; }; #endif