os/graphics/m3g/m3gcore11/inc/m3g_appearance.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: Appearance interface
    15 *
    16 */
    17 
    18 #ifndef __M3G_APPEARANCE_H__
    19 #define __M3G_APPEARANCE_H__
    20 
    21 /*!
    22  * \internal
    23  * \file
    24  * \brief Appearance interface
    25  */
    26 
    27 #include "m3g_object.h"
    28 #include "m3g_compositingmode.h"
    29 #include "m3g_polygonmode.h"
    30 #include "m3g_material.h"
    31 #include "m3g_texture.h"
    32 #include "m3g_fog.h"
    33 #include "m3g_rendercontext.h"
    34 
    35 /* Limits for user settable layer */
    36 #define M3G_APPEARANCE_MIN_LAYER      -63
    37 #define M3G_APPEARANCE_MAX_LAYER       63
    38 #define M3G_APPEARANCE_HARD_SORT_BITS   8
    39 
    40 typedef /*@dependent@*//*@null@*/ Texture *TexturePtr;
    41 
    42 /*!
    43  * \internal
    44  * \brief Appearance object
    45  */
    46 struct M3GAppearanceImpl
    47 {
    48     Object object;
    49 
    50     /*@dependent@*//*@null@*/
    51     Material *material;
    52 
    53     /*@dependent@*//*@null@*/
    54     CompositingMode *compositingMode;
    55 
    56     /*@dependent@*//*@null@*/
    57     PolygonMode *polygonMode;
    58 
    59     /*@dependent@*//*@null@*/
    60     Fog *fog;
    61 
    62     TexturePtr texture[M3G_NUM_TEXTURE_UNITS];
    63 
    64     M3Guint sortKey;
    65     
    66     M3Gshort layer;
    67     M3Gushort vertexMask;
    68 };
    69 
    70 /*----------------------------------------------------------------------
    71  * Internal functions
    72  *--------------------------------------------------------------------*/
    73 
    74 static void m3gApplyAppearance(const Appearance *appearance,
    75 							   RenderContext *ctx,
    76                                M3Gint alphaFactor);
    77 
    78 /*!
    79  * \internal
    80  * \brief Get vertex mask
    81  *
    82  * \param app Appearance object
    83  * \return vertex mask
    84  */
    85 static M3G_INLINE M3Gbitmask m3gGetVertexMask(const Appearance *app)
    86 {
    87     return app->vertexMask;
    88 }
    89 
    90 /*!
    91  * \internal
    92  * \brief Shortcut getter for color mask
    93  */
    94 static M3G_INLINE M3Gbool m3gColorMask(const Appearance *app)
    95 {
    96     if (app) {
    97         const CompositingMode *cm = app->compositingMode;
    98         return !cm || cm->colorWrite;
    99     }
   100     return M3G_FALSE;
   101 }
   102 
   103 /*!
   104  * \internal
   105  * \brief Shortcut getter for alpha mask
   106  */
   107 static M3G_INLINE M3Gbool m3gAlphaMask(const Appearance *app)
   108 {
   109     if (app) {
   110         const CompositingMode *cm = app->compositingMode;
   111         return !cm || cm->alphaWrite;
   112     }
   113     return M3G_FALSE;
   114 }
   115 
   116 /*!
   117  * \internal
   118  * \brief Get sortkey for render queue
   119  *
   120  * Sort key is a combination of user settable layer and
   121  * blending mode. Blended objects are always drawn last.
   122  *
   123  * \param appearance    Appearance object
   124  * \return              sort key
   125  */
   126 static M3G_INLINE M3Guint m3gGetAppearanceSortKey(const Appearance *appearance)
   127 {
   128     if (appearance) {
   129         M3Guint key = appearance->sortKey;
   130 
   131         /* The blending state bit is set dynamically, as it may change
   132          * without changing the appearance (we have no signaling from
   133          * CompositingMode for that) */
   134         
   135         if (appearance->compositingMode != NULL
   136             && appearance->compositingMode->blendingMode != M3G_REPLACE) {
   137             key |= (1u << (32 - M3G_APPEARANCE_HARD_SORT_BITS));
   138         }
   139 
   140         if (m3gGetColorMaskWorkaround(M3G_INTERFACE(appearance))) {
   141             /* Override the top 2 bits of the sorting key so that ColorMask
   142              * changes are minimized */
   143             if (appearance) {
   144                 key &= ~(0x03 << 22);
   145                 key |= (((M3Guint) m3gColorMask(appearance)) & 1) << 23;
   146                 key |= (((M3Guint) m3gAlphaMask(appearance)) & 1) << 22;
   147             }
   148         }
   149 
   150         return key;
   151     } 
   152 
   153     return M3G_FALSE;
   154 }
   155 
   156 /*!
   157  * \internal
   158  * \brief Release the textures bound for this appearance
   159  */
   160 static void m3gReleaseTextures(const Appearance *appearance);
   161 
   162 #endif /*__M3G_APPEARANCE_H__*/