Commit 060ea15a authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3drm: Introduce d3drm_set_color().

parent b86f6b93
......@@ -21,6 +21,7 @@
#ifndef __D3DRM_PRIVATE_INCLUDED__
#define __D3DRM_PRIVATE_INCLUDED__
#include <math.h>
#include "d3drm.h"
#include "dxfile.h"
#include "d3drmwin.h"
......@@ -140,4 +141,19 @@ struct d3drm_file_header
extern char templates[] DECLSPEC_HIDDEN;
static inline BYTE d3drm_color_component(float c)
{
if (c <= 0.0f)
return 0u;
if (c >= 1.0f)
return 0xffu;
return floor(c * 255.0f);
}
static inline void d3drm_set_color(D3DCOLOR *color, float r, float g, float b, float a)
{
*color = RGBA_MAKE(d3drm_color_component(r), d3drm_color_component(g),
d3drm_color_component(b), d3drm_color_component(a));
}
#endif /* __D3DRM_PRIVATE_INCLUDED__ */
......@@ -2004,8 +2004,7 @@ static HRESULT WINAPI d3drm_frame3_SetSceneBackgroundRGB(IDirect3DRMFrame3 *ifac
TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface, red, green, blue);
frame->scenebackground = RGBA_MAKE((BYTE)(red * 255.0f),
(BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff);
d3drm_set_color(&frame->scenebackground, red, green, blue, 1.0f);
return D3DRM_OK;
}
......@@ -2949,7 +2948,7 @@ HRESULT d3drm_frame_create(struct d3drm_frame **frame, IUnknown *parent_frame, I
object->IDirect3DRMFrame3_iface.lpVtbl = &d3drm_frame3_vtbl;
object->d3drm = d3drm;
object->ref = 1;
object->scenebackground = RGBA_MAKE(0, 0, 0, 0xff);
d3drm_set_color(&object->scenebackground, 0.0f, 0.0f, 0.0f, 1.0f);
memcpy(object->transform, identity, sizeof(D3DRMMATRIX4D));
......
......@@ -183,7 +183,7 @@ static HRESULT WINAPI d3drm_light_SetColorRGB(IDirect3DRMLight *iface,
TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface, red, green, blue);
light->color = RGBA_MAKE((BYTE)(red * 255.0f), (BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff);
d3drm_set_color(&light->color, red, green, blue, 1.0f);
return D3DRM_OK;
}
......
......@@ -19,12 +19,10 @@
#define NONAMELESSUNION
#include <math.h>
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "d3drmdef.h"
#include "config.h"
#include "wine/port.h"
#include "d3drm_private.h"
/* Create a RGB color from its components */
D3DCOLOR WINAPI D3DRMCreateColorRGB(D3DVALUE red, D3DVALUE green, D3DVALUE blue)
......@@ -34,20 +32,11 @@ D3DCOLOR WINAPI D3DRMCreateColorRGB(D3DVALUE red, D3DVALUE green, D3DVALUE blue)
/* Create a RGBA color from its components */
D3DCOLOR WINAPI D3DRMCreateColorRGBA(D3DVALUE red, D3DVALUE green, D3DVALUE blue, D3DVALUE alpha)
{
int Red, Green, Blue, Alpha;
Red=floor(red*255);
Green=floor(green*255);
Blue=floor(blue*255);
Alpha=floor(alpha*255);
if (red < 0) Red=0;
if (red > 1) Red=255;
if (green < 0) Green=0;
if (green > 1) Green=255;
if (blue < 0) Blue=0;
if (blue > 1) Blue=255;
if (alpha < 0) Alpha=0;
if (alpha > 1) Alpha=255;
return (RGBA_MAKE(Red, Green, Blue, Alpha));
D3DCOLOR color;
d3drm_set_color(&color, red, green, blue, alpha);
return color;
}
/* Determine the alpha part of a color */
......
......@@ -1235,8 +1235,7 @@ HRESULT load_mesh_data(IDirect3DRMMeshBuilder3 *iface, IDirectXFileData *pData,
values = (float*)ptr;
This->materials[i].color = RGBA_MAKE((BYTE)(values[0] * 255.0f), (BYTE)(values[1] * 255.0f),
(BYTE)(values[2] * 255.0f), (BYTE)(values[3] * 255.0f));
d3drm_set_color(&This->materials[i].color, values[0], values[1], values[2], values[3]);
IDirect3DRMMaterial2_SetAmbient(This->materials[i].material, values[0], values [1], values[2]); /* Alpha ignored */
IDirect3DRMMaterial2_SetPower(This->materials[i].material, values[4]);
......@@ -1694,7 +1693,7 @@ static HRESULT WINAPI d3drm_mesh_builder3_SetColorRGB(IDirect3DRMMeshBuilder3 *i
TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface, red, green, blue);
mesh_builder->color = RGBA_MAKE((BYTE)(red * 255.0f), (BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff);
d3drm_set_color(&mesh_builder->color, red, green, blue, 1.0f);
return D3DRM_OK;
}
......@@ -2595,7 +2594,7 @@ static HRESULT WINAPI d3drm_mesh_SetGroupColorRGB(IDirect3DRMMesh *iface,
if (id >= mesh->nb_groups)
return D3DRMERR_BADVALUE;
mesh->groups[id].color = RGBA_MAKE((BYTE)(red * 255.0f), (BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff);
d3drm_set_color(&mesh->groups[id].color, red, green, blue, 1.0f);
return D3DRM_OK;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment