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