OSDN Git Service

作業部屋#50802 画面キャプチャができなくなっていた問題を暫定対応(F12キー固定で対応中)
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d9 / BaseTexture.cpp
1 #include "stdafx.h"
2 /*
3 * Copyright (c) 2007-2010 SlimDX Group
4
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23 #include <d3d9.h>
24 #include <d3dx9.h>
25 #include <vcclr.h>
26
27 #include "Direct3D9Exception.h"
28
29 #include "Device.h"
30 #include "BaseTexture.h"
31 #include "Texture.h"
32 #include "VolumeTexture.h"
33 #include "CubeTexture.h"
34
35 using namespace System;
36
37 namespace SlimDX
38 {
39 namespace Direct3D9
40 {
41         BaseTexture^ BaseTexture::FromUnmanaged( IDirect3DBaseTexture9 *texture )
42         {
43                 if( texture == NULL )
44                         return nullptr;
45
46                 switch( texture->GetType() )
47                 {
48                 case D3DRTYPE_TEXTURE:
49                         return Texture::FromPointer( static_cast<IDirect3DTexture9*>( texture ) );
50                 case D3DRTYPE_VOLUMETEXTURE:
51                         return VolumeTexture::FromPointer( static_cast<IDirect3DVolumeTexture9*>( texture ) );
52                 case D3DRTYPE_CUBETEXTURE:
53                         return CubeTexture::FromPointer( static_cast<IDirect3DCubeTexture9*>( texture ) );
54
55                 default:
56                         return nullptr;
57                 }
58         }
59
60         void BaseTexture::GenerateMipSublevels()
61         {
62                 InternalPointer->GenerateMipSubLevels();
63         }
64
65         DataStream^ BaseTexture::ToStream( BaseTexture^ texture, ImageFileFormat format, array<PaletteEntry>^ palette )
66         {
67                 ID3DXBuffer *buffer = NULL;
68                 pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];
69                 
70                 HRESULT hr = D3DXSaveTextureToFileInMemory( &buffer, static_cast<D3DXIMAGE_FILEFORMAT>( format ), 
71                         texture->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ) );
72
73                 if( RECORD_D3D9( hr ).IsFailure )
74                         return nullptr;
75
76                 return gcnew DataStream( buffer );
77         }
78
79         DataStream^ BaseTexture::ToStream( BaseTexture^ texture, ImageFileFormat format )
80         {
81                 ID3DXBuffer *buffer = NULL;
82                 
83                 HRESULT hr = D3DXSaveTextureToFileInMemory( &buffer, static_cast<D3DXIMAGE_FILEFORMAT>( format ), 
84                         texture->InternalPointer, NULL );
85
86                 if( RECORD_D3D9( hr ).IsFailure )
87                         return nullptr;
88
89                 return gcnew DataStream( buffer );
90         }
91
92         Result BaseTexture::ToFile( BaseTexture^ texture, String^ fileName, ImageFileFormat format, array<PaletteEntry>^ palette )
93         {
94                 pin_ptr<const wchar_t> pinnedName = PtrToStringChars(fileName);
95                 pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];
96                 
97                 HRESULT hr = D3DXSaveTextureToFile( pinnedName, static_cast<D3DXIMAGE_FILEFORMAT>( format ), 
98                         texture->InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ) );
99                 return RECORD_D3D9( hr );
100         }
101
102         Result BaseTexture::ToFile( BaseTexture^ texture, String^ fileName, ImageFileFormat format )
103         {
104                 pin_ptr<const wchar_t> pinnedName = PtrToStringChars(fileName);
105                 
106                 HRESULT hr = D3DXSaveTextureToFile( pinnedName, static_cast<D3DXIMAGE_FILEFORMAT>( format ), 
107                         texture->InternalPointer, NULL );
108                 return RECORD_D3D9( hr );
109         }
110
111         Result BaseTexture::FilterTexture( int sourceLevel, Filter filter, array<PaletteEntry>^ palette )
112         {
113                 pin_ptr<PaletteEntry> pinnedPalette = palette == nullptr ? nullptr : &palette[0];
114
115                 HRESULT hr = D3DXFilterTexture( InternalPointer, reinterpret_cast<const PALETTEENTRY*>( pinnedPalette ),
116                         sourceLevel, static_cast<DWORD>( filter ) );
117                 return RECORD_D3D9( hr );
118         }
119
120         Result BaseTexture::FilterTexture( int sourceLevel, Filter filter )
121         {
122                 HRESULT hr = D3DXFilterTexture( InternalPointer, NULL, sourceLevel, static_cast<DWORD>( filter ) );
123                 return RECORD_D3D9( hr );
124         }
125 }
126 }