ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

light.c
Go to the documentation of this file.
00001 /* Direct3D Light
00002  * Copyright (c) 1998 / 2002 Lionel ULMER
00003  * Copyright (c) 2006        Stefan DÖSINGER
00004  *
00005  * This file contains the implementation of Direct3DLight.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00020  */
00021 
00022 #include "config.h"
00023 #include "wine/port.h"
00024 
00025 #include "ddraw_private.h"
00026 
00027 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
00028 
00029 /*****************************************************************************
00030  * light_update
00031  *
00032  * Updates the Direct3DDevice7 lighting parameters
00033  *
00034  *****************************************************************************/
00035 static void light_update(IDirect3DLightImpl *light)
00036 {
00037     IDirect3DDeviceImpl *device;
00038 
00039     TRACE("light %p.\n", light);
00040 
00041     if (!light->active_viewport || !light->active_viewport->active_device) return;
00042     device = light->active_viewport->active_device;
00043 
00044     IDirect3DDevice7_SetLight(&device->IDirect3DDevice7_iface, light->dwLightIndex, &light->light7);
00045 }
00046 
00047 /*****************************************************************************
00048  * light_activate
00049  *
00050  * Uses the Direct3DDevice7::LightEnable method to active the light
00051  *
00052  *****************************************************************************/
00053 void light_activate(IDirect3DLightImpl *light)
00054 {
00055     IDirect3DDeviceImpl *device;
00056 
00057     TRACE("light %p.\n", light);
00058 
00059     if (!light->active_viewport || !light->active_viewport->active_device) return;
00060     device = light->active_viewport->active_device;
00061 
00062     light_update(light);
00063     if (!(light->light.dwFlags & D3DLIGHT_ACTIVE))
00064     {
00065         IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, TRUE);
00066         light->light.dwFlags |= D3DLIGHT_ACTIVE;
00067     }
00068 }
00069 
00070 /*****************************************************************************
00071  *
00072  * light_deactivate
00073  *
00074  * Uses the Direct3DDevice7::LightEnable method to deactivate the light
00075  *
00076  *****************************************************************************/
00077 void light_deactivate(IDirect3DLightImpl *light)
00078 {
00079     IDirect3DDeviceImpl *device;
00080 
00081     TRACE("light %p.\n", light);
00082 
00083     if (!light->active_viewport || !light->active_viewport->active_device) return;
00084     device = light->active_viewport->active_device;
00085 
00086     /* If was not active, activate it */
00087     if (light->light.dwFlags & D3DLIGHT_ACTIVE)
00088     {
00089         IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, FALSE);
00090         light->light.dwFlags &= ~D3DLIGHT_ACTIVE;
00091     }
00092 }
00093 
00094 static inline IDirect3DLightImpl *impl_from_IDirect3DLight(IDirect3DLight *iface)
00095 {
00096     return CONTAINING_RECORD(iface, IDirect3DLightImpl, IDirect3DLight_iface);
00097 }
00098 
00099 /*****************************************************************************
00100  * IDirect3DLight::QueryInterface
00101  *
00102  * Queries the object for different interfaces. Unimplemented for this
00103  * object at the moment
00104  *
00105  * Params:
00106  *  riid: Interface id asked for
00107  *  obj: Address to return the resulting pointer at.
00108  *
00109  * Returns:
00110  *  E_NOINTERFACE, because it's a stub
00111  *****************************************************************************/
00112 static HRESULT WINAPI IDirect3DLightImpl_QueryInterface(IDirect3DLight *iface, REFIID riid, void **object)
00113 {
00114     FIXME("iface %p, riid %s, object %p stub!\n", iface, debugstr_guid(riid), object);
00115 
00116     *object = NULL;
00117     return E_NOINTERFACE;
00118 }
00119 
00120 static ULONG WINAPI IDirect3DLightImpl_AddRef(IDirect3DLight *iface)
00121 {
00122     IDirect3DLightImpl *This = impl_from_IDirect3DLight(iface);
00123     ULONG ref = InterlockedIncrement(&This->ref);
00124 
00125     TRACE("%p increasing refcount to %u.\n", This, ref);
00126 
00127     return ref;
00128 }
00129 
00130 static ULONG WINAPI IDirect3DLightImpl_Release(IDirect3DLight *iface)
00131 {
00132     IDirect3DLightImpl *This = impl_from_IDirect3DLight(iface);
00133     ULONG ref = InterlockedDecrement(&This->ref);
00134 
00135     TRACE("%p decreasing refcount to %u.\n", This, ref);
00136 
00137     if (!ref) {
00138         HeapFree(GetProcessHeap(), 0, This);
00139         return 0;
00140     }
00141     return ref;
00142 }
00143 
00144 /*****************************************************************************
00145  * IDirect3DLight Methods.
00146  *****************************************************************************/
00147 
00148 /*****************************************************************************
00149  * IDirect3DLight::Initialize
00150  *
00151  * Initializes the interface. This implementation is a no-op, because
00152  * initialization takes place at creation time
00153  *
00154  * Params:
00155  *  Direct3D: Pointer to an IDirect3D interface.
00156  *
00157  * Returns:
00158  *  D3D_OK
00159  *
00160  *****************************************************************************/
00161 static HRESULT WINAPI IDirect3DLightImpl_Initialize(IDirect3DLight *iface, IDirect3D *d3d)
00162 {
00163     TRACE("iface %p, d3d %p.\n", iface, d3d);
00164 
00165     return D3D_OK;
00166 }
00167 
00168 /*****************************************************************************
00169  * IDirect3DLight::SetLight
00170  *
00171  * Assigns a lighting value to this object
00172  *
00173  * Params:
00174  *  Light: Lighting parameter to set
00175  *
00176  * Returns:
00177  *  D3D_OK on success
00178  *  DDERR_INVALIDPARAMS if Light is NULL
00179  *
00180  *****************************************************************************/
00181 static void dump_light(const D3DLIGHT2 *light)
00182 {
00183     TRACE("    - dwSize : %d\n", light->dwSize);
00184 }
00185 
00186 static const float zero_value[] = {
00187     0.0, 0.0, 0.0, 0.0
00188 };
00189 
00190 static HRESULT WINAPI IDirect3DLightImpl_SetLight(IDirect3DLight *iface, D3DLIGHT *lpLight)
00191 {
00192     IDirect3DLightImpl *This = impl_from_IDirect3DLight(iface);
00193     LPD3DLIGHT7 light7 = &This->light7;
00194 
00195     TRACE("iface %p, light %p.\n", iface, lpLight);
00196 
00197     if (TRACE_ON(ddraw))
00198     {
00199         TRACE("  Light definition :\n");
00200         dump_light((LPD3DLIGHT2) lpLight);
00201     }
00202 
00203     if ( (lpLight->dltType == 0) || (lpLight->dltType > D3DLIGHT_PARALLELPOINT) )
00204          return DDERR_INVALIDPARAMS;
00205 
00206     if ( lpLight->dltType == D3DLIGHT_PARALLELPOINT )
00207         FIXME("D3DLIGHT_PARALLELPOINT no supported\n");
00208 
00209     /* Translate D3DLIGH2 structure to D3DLIGHT7 */
00210     light7->dltType        = lpLight->dltType;
00211     light7->dcvDiffuse     = lpLight->dcvColor;
00212     if ((((LPD3DLIGHT2)lpLight)->dwFlags & D3DLIGHT_NO_SPECULAR) != 0)
00213       light7->dcvSpecular    = lpLight->dcvColor;
00214     else
00215       light7->dcvSpecular    = *(const D3DCOLORVALUE*)zero_value;
00216     light7->dcvAmbient     = lpLight->dcvColor;
00217     light7->dvPosition     = lpLight->dvPosition;
00218     light7->dvDirection    = lpLight->dvDirection;
00219     light7->dvRange        = lpLight->dvRange;
00220     light7->dvFalloff      = lpLight->dvFalloff;
00221     light7->dvAttenuation0 = lpLight->dvAttenuation0;
00222     light7->dvAttenuation1 = lpLight->dvAttenuation1;
00223     light7->dvAttenuation2 = lpLight->dvAttenuation2;
00224     light7->dvTheta        = lpLight->dvTheta;
00225     light7->dvPhi          = lpLight->dvPhi;
00226 
00227     wined3d_mutex_lock();
00228     memcpy(&This->light, lpLight, lpLight->dwSize);
00229     if (This->light.dwFlags & D3DLIGHT_ACTIVE)
00230         light_update(This);
00231     wined3d_mutex_unlock();
00232 
00233     return D3D_OK;
00234 }
00235 
00236 /*****************************************************************************
00237  * IDirect3DLight::GetLight
00238  *
00239  * Returns the parameters currently assigned to the IDirect3DLight object
00240  *
00241  * Params:
00242  *  Light: Pointer to an D3DLIGHT structure to store the parameters
00243  *
00244  * Returns:
00245  *  D3D_OK on success
00246  *  DDERR_INVALIDPARAMS if Light is NULL
00247  *****************************************************************************/
00248 static HRESULT WINAPI IDirect3DLightImpl_GetLight(IDirect3DLight *iface, D3DLIGHT *lpLight)
00249 {
00250     IDirect3DLightImpl *This = impl_from_IDirect3DLight(iface);
00251 
00252     TRACE("iface %p, light %p.\n", iface, lpLight);
00253 
00254     if (TRACE_ON(ddraw))
00255     {
00256         TRACE("  Returning light definition :\n");
00257         dump_light(&This->light);
00258     }
00259 
00260     wined3d_mutex_lock();
00261     memcpy(lpLight, &This->light, lpLight->dwSize);
00262     wined3d_mutex_unlock();
00263 
00264     return DD_OK;
00265 }
00266 
00267 static const struct IDirect3DLightVtbl d3d_light_vtbl =
00268 {
00269     /*** IUnknown Methods ***/
00270     IDirect3DLightImpl_QueryInterface,
00271     IDirect3DLightImpl_AddRef,
00272     IDirect3DLightImpl_Release,
00273     /*** IDirect3DLight Methods ***/
00274     IDirect3DLightImpl_Initialize,
00275     IDirect3DLightImpl_SetLight,
00276     IDirect3DLightImpl_GetLight
00277 };
00278 
00279 void d3d_light_init(IDirect3DLightImpl *light, IDirectDrawImpl *ddraw)
00280 {
00281     light->IDirect3DLight_iface.lpVtbl = &d3d_light_vtbl;
00282     light->ref = 1;
00283     light->ddraw = ddraw;
00284 }
00285 
00286 IDirect3DLightImpl *unsafe_impl_from_IDirect3DLight(IDirect3DLight *iface)
00287 {
00288     if (!iface)
00289         return NULL;
00290     assert(iface->lpVtbl == &d3d_light_vtbl);
00291 
00292     return impl_from_IDirect3DLight(iface);
00293 }

Generated on Sat May 26 2012 04:19:07 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.