1 /*
2   LICENSE
3   -------
4 Copyright 2005-2013 Nullsoft, Inc.
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10   * Redistributions of source code must retain the above copyright notice,
11     this list of conditions and the following disclaimer.
12 
13   * Redistributions in binary form must reproduce the above copyright notice,
14     this list of conditions and the following disclaimer in the documentation
15     and/or other materials provided with the distribution.
16 
17   * Neither the name of Nullsoft nor the names of its contributors may be used to
18     endorse or promote products derived from this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
21 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 #ifndef __NULLSOFT_DX9_EXAMPLE_PLUGIN_SUPPORT_H__
31 #define __NULLSOFT_DX9_EXAMPLE_PLUGIN_SUPPORT_H__ 1
32 
33 #include <d3dx9.h>
34 
35 void MakeWorldMatrix( D3DXMATRIX* pOut,
36                       float xpos, float ypos, float zpos,
37                       float sx,   float sy,   float sz,
38                       float pitch, float yaw, float roll);
39 void MakeProjectionMatrix( D3DXMATRIX* pOut,
40                            const float near_plane, // Distance to near clipping plane
41                            const float far_plane,  // Distance to far clipping plane
42                            const float fov_horiz,  // Horizontal field of view angle, in radians
43                            const float fov_vert);   // Vertical field of view angle, in radians
44 void PrepareFor3DDrawing(
45         IDirect3DDevice9 *pDevice,
46         int viewport_width,
47         int viewport_height,
48         float fov_in_degrees,
49         float near_clip,
50         float far_clip,
51         D3DXVECTOR3* pvEye,
52         D3DXVECTOR3* pvLookat,
53         D3DXVECTOR3* pvUp
54     );
55 void PrepareFor2DDrawing(IDirect3DDevice9 *pDevice);
56 
57 // Define vertex formats you'll be using here:
58 // note: layout must match the vertex declaration in plugin.cpp!
59 typedef struct _MYVERTEX
60 {
61     float x, y, z;     // screen position + Z-buffer depth
62     DWORD Diffuse;     // diffuse color
63     float tu, tv;           // DYNAMIC
64      float tu_orig, tv_orig; // STATIC
65     float rad, ang;         // STATIC
66 } MYVERTEX, *LPMYVERTEX;
67 
68 // note: layout must match the vertex declaration in plugin.cpp!
69 typedef struct _WFVERTEX
70 {
71     float x, y, z;
72     DWORD Diffuse;   // diffuse color. also acts as filler; aligns struct to 16 bytes (good for random access/indexed prims)
73 } WFVERTEX, *LPWFVERTEX;
74 
75 // note: layout must match the vertex declaration in plugin.cpp!
76 typedef struct _SPRITEVERTEX
77 {
78     float x, y;      // screen position
79     float z;         // Z-buffer depth
80     DWORD Diffuse;   // diffuse color. also acts as filler; aligns struct to 16 bytes (good for random access/indexed prims)
81     float tu, tv;    // texture coordinates for texture #0
82 } SPRITEVERTEX, *LPSPRITEVERTEX;
83 
84 // Also prepare vertex format descriptors for each
85 //   of the 3 kinds of vertices we'll be using:
86 // note: D3DFVF_TEXCOORDSIZEm(n): m = the dimension, n = the index
87 // AVOID D3DFVF_TEXCOORDSIZE4 - I've seen probs (blending between shader and non-shader presets) on vaio laptop w/6200!
88 #define MYVERTEX_FORMAT     (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) | D3DFVF_TEXCOORDSIZE2(2))
89 #define WFVERTEX_FORMAT     (D3DFVF_XYZ | D3DFVF_DIFFUSE              )
90 #define SPRITEVERTEX_FORMAT (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0) )
91 
92 void    GetWinampSongTitle(HWND hWndWinamp, wchar_t *szSongTitle, int nSize);
93 void    GetWinampSongPosAsText(HWND hWndWinamp, wchar_t *szSongPos);
94 void    GetWinampSongLenAsText(HWND hWndWinamp, wchar_t *szSongLen);
95 float   GetWinampSongPos(HWND hWndWinamp);      // returns answer in seconds
96 float   GetWinampSongLen(HWND hWndWinamp);      // returns answer in seconds
97 
98 //#define PROFILING
99 #ifdef PROFILING
100     #define PROFILE_BEGIN    LARGE_INTEGER tx, freq, ty; QueryPerformanceCounter(&tx); QueryPerformanceFrequency(&freq);
101     #define PROFILE_END(s)   { QueryPerformanceCounter(&ty); float dt = (float)((double)(ty.QuadPart - tx.QuadPart) / (double)freq.QuadPart); char buf[256]; sprintf(buf, "  %s = %.1f ms\n", s, dt*1000 ); OutputDebugString(buf); tx = ty; }
102 #else
103     #define PROFILE_BEGIN
104     #define PROFILE_END(s)
105 #endif
106 
107 int GetDX9TexFormatBitsPerPixel(D3DFORMAT fmt);
108 
109 #endif