Last change
on this file since 1184 was 1114, checked in by iritscen, 5 years ago |
Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.
|
File size:
1.6 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using Oni.Imaging;
|
---|
4 |
|
---|
5 | namespace Oni.Motoko
|
---|
6 | {
|
---|
7 | internal class Texture
|
---|
8 | {
|
---|
9 | public readonly List<Surface> Surfaces = new List<Surface>();
|
---|
10 | public int Width;
|
---|
11 | public int Height;
|
---|
12 | public TextureFormat Format;
|
---|
13 | public TextureFlags Flags;
|
---|
14 | public string Name;
|
---|
15 | public Texture EnvMap;
|
---|
16 |
|
---|
17 | public void GenerateMipMaps()
|
---|
18 | {
|
---|
19 | if ((Flags & TextureFlags.HasMipMaps) != 0)
|
---|
20 | return;
|
---|
21 |
|
---|
22 | var surface = Surfaces[0];
|
---|
23 |
|
---|
24 | Surfaces.Clear();
|
---|
25 | Surfaces.Add(surface);
|
---|
26 |
|
---|
27 | if (surface.Format == SurfaceFormat.DXT1)
|
---|
28 | surface = surface.Convert(SurfaceFormat.BGRX5551);
|
---|
29 |
|
---|
30 | int width = surface.Width;
|
---|
31 | int height = surface.Height;
|
---|
32 | var surfaceFormat = Format.ToSurfaceFormat();
|
---|
33 |
|
---|
34 | while (width > 1 || height > 1)
|
---|
35 | {
|
---|
36 | width = Math.Max(width >> 1, 1);
|
---|
37 | height = Math.Max(height >> 1, 1);
|
---|
38 |
|
---|
39 | surface = surface.Resize(width, height);
|
---|
40 |
|
---|
41 | Surfaces.Add(surface);
|
---|
42 | }
|
---|
43 |
|
---|
44 | if (surface.Format != surfaceFormat)
|
---|
45 | {
|
---|
46 | for (int i = 1; i < Surfaces.Count; i++)
|
---|
47 | Surfaces[i] = Surfaces[i].Convert(surfaceFormat);
|
---|
48 | }
|
---|
49 |
|
---|
50 | Flags |= TextureFlags.HasMipMaps;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public bool HasAlpha => Surfaces[0].HasAlpha;
|
---|
54 |
|
---|
55 | public bool WrapU => (Flags & TextureFlags.NoUWrap) == 0;
|
---|
56 | public bool WrapV => (Flags & TextureFlags.NoVWrap) == 0;
|
---|
57 | }
|
---|
58 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.