Przeglądaj źródła

SetMagFiltering and SetMinFiltering for class Texture.

legacy
Benlitz benlitz 11 lat temu
rodzic
commit
d13a006945
4 zmienionych plików z 103 dodań i 0 usunięć
  1. +3
    -0
      src/gpu/shader.cpp
  2. +60
    -0
      src/gpu/texture.cpp
  3. +3
    -0
      src/lol/gpu/shader.h
  4. +37
    -0
      src/lol/gpu/texture.h

+ 3
- 0
src/gpu/shader.cpp Wyświetl plik

@@ -550,6 +550,9 @@ void Shader::SetUniform(ShaderUniform const &uni, ShaderTexture tex, int index)
{
#if defined USE_D3D9 || defined _XBOX
g_d3ddevice->SetTexture(index, (LPDIRECT3DTEXTURE9)tex.m_flags);
g_d3ddevice->SetSamplerState(index, D3DSAMP_MAGFILTER, tex.m_attrib & 0xff);
g_d3ddevice->SetSamplerState(index, D3DSAMP_MINFILTER, (tex.m_attrib >> 8) & 0xff);
g_d3ddevice->SetSamplerState(index, D3DSAMP_MIPFILTER, (tex.m_attrib >> 16) & 0xff);
#elif !defined __CELLOS_LV2__
glActiveTexture(GL_TEXTURE0 + index);
//glEnable(GL_TEXTURE_2D);


+ 60
- 0
src/gpu/texture.cpp Wyświetl plik

@@ -46,6 +46,9 @@ class TextureData

#if defined USE_D3D9
IDirect3DTexture9 *m_texture;
D3DTEXTUREFILTERTYPE m_mag_filter;
D3DTEXTUREFILTERTYPE m_min_filter;
D3DTEXTUREFILTERTYPE m_mip_filter;
#elif defined _XBOX
D3DTexture *m_texture;
#else
@@ -170,6 +173,9 @@ ShaderTexture Texture::GetTexture() const
ShaderTexture ret;
#if defined USE_D3D9 || defined _XBOX
ret.m_flags = (uint64_t)(uintptr_t)m_data->m_texture;
ret.m_attrib = m_data->m_mag_filter;
ret.m_attrib |= m_data->m_min_filter << 8;
ret.m_attrib |= m_data->m_mip_filter << 16;
#else
ret.m_flags = m_data->m_texture;
#endif
@@ -231,6 +237,60 @@ void Texture::SetSubData(ivec2 origin, ivec2 size, void *data)
#endif
}

void Texture::SetMagFiltering(TextureMagFilter filter)
{
#if defined _XBOX || defined USE_D3D9
// In DirectX, texture filtering is a per-texture-unit state
switch (filter)
{
case TextureMagFilter::NEAREST_TEXEL: m_data->m_mag_filter = D3DTEXF_POINT; break;
case TextureMagFilter::LINEAR_TEXEL: m_data->m_mag_filter = D3DTEXF_LINEAR; break;
}
#else
glBindTexture(GL_TEXTURE_2D, m_data->m_texture);
GLenum gl_filter;
switch (filter)
{
case TextureMagFilter::NEAREST_TEXEL: gl_filter = GL_NEAREST; break;
case TextureMagFilter::LINEAR_TEXEL: gl_filter = GL_LINEAR; break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter);
#endif
}

void Texture::SetMinFiltering(TextureMinFilter filter)
{
#if defined _XBOX || defined USE_D3D9
// In DirectX, texture filtering is a per-texture-unit state
#define F(x, y) \
m_data->m_min_filter = x; m_data->m_mip_filter = y;
switch (filter)
{
case TextureMinFilter::NEAREST_TEXEL_NO_MIPMAP: F(D3DTEXF_POINT, D3DTEXF_NONE); break;
case TextureMinFilter::LINEAR_TEXEL_NO_MIPMAP: F(D3DTEXF_POINT, D3DTEXF_NONE); break;
case TextureMinFilter::NEAREST_TEXEL_NEAREST_MIPMAP: F(D3DTEXF_POINT, D3DTEXF_POINT); break;
case TextureMinFilter::LINEAR_TEXEL_NEAREST_MIPMAP: F(D3DTEXF_LINEAR, D3DTEXF_POINT); break;
case TextureMinFilter::NEAREST_TEXEL_LINEAR_MIPMAP: F(D3DTEXF_POINT, D3DTEXF_LINEAR); break;
case TextureMinFilter::LINEAR_TEXEL_LINEAR_MIPMAP: F(D3DTEXF_LINEAR, D3DTEXF_LINEAR); break;
}
#undef F

#else
glBindTexture(GL_TEXTURE_2D, m_data->m_texture);
GLenum gl_filter;
switch (filter)
{
case TextureMinFilter::NEAREST_TEXEL_NO_MIPMAP: gl_filter = GL_NEAREST; break;
case TextureMinFilter::LINEAR_TEXEL_NO_MIPMAP: gl_filter = GL_LINEAR; break;
case TextureMinFilter::NEAREST_TEXEL_NEAREST_MIPMAP: gl_filter = GL_NEAREST_MIPMAP_NEAREST; break;
case TextureMinFilter::NEAREST_TEXEL_LINEAR_MIPMAP: gl_filter = GL_NEAREST_MIPMAP_LINEAR; break;
case TextureMinFilter::LINEAR_TEXEL_NEAREST_MIPMAP: gl_filter = GL_LINEAR_MIPMAP_NEAREST; break;
case TextureMinFilter::LINEAR_TEXEL_LINEAR_MIPMAP: gl_filter = GL_LINEAR_MIPMAP_LINEAR; break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter);
#endif
}

Texture::~Texture()
{
#if defined USE_D3D9 || defined _XBOX


+ 3
- 0
src/lol/gpu/shader.h Wyświetl plik

@@ -57,6 +57,9 @@ public:

private:
uint64_t m_flags;
#if defined USE_D3D9 || defined _XBOX
uint32_t m_attrib;
#endif
};

class ShaderData;


+ 37
- 0
src/lol/gpu/texture.h Wyświetl plik

@@ -54,6 +54,40 @@ struct PixelFormat
}
};

struct TextureMagFilter
{
enum Value
{
Unknown = 0,
NEAREST_TEXEL,
LINEAR_TEXEL,
}
m_value;

inline TextureMagFilter() : m_value(Unknown) {}
inline TextureMagFilter(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

struct TextureMinFilter
{
enum Value
{
Unknown = 0,
NEAREST_TEXEL_NO_MIPMAP,
LINEAR_TEXEL_NO_MIPMAP,
NEAREST_TEXEL_NEAREST_MIPMAP,
NEAREST_TEXEL_LINEAR_MIPMAP,
LINEAR_TEXEL_NEAREST_MIPMAP,
LINEAR_TEXEL_LINEAR_MIPMAP,
}
m_value;

inline TextureMinFilter() : m_value(Unknown) {}
inline TextureMinFilter(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

class Texture
{
public:
@@ -64,6 +98,9 @@ public:
void SetData(void *data);
void SetSubData(ivec2 origin, ivec2 size, void *data);

void SetMagFiltering(TextureMagFilter filter);
void SetMinFiltering(TextureMinFilter filter);

ShaderTexture GetTexture() const;

private:


Ładowanie…
Anuluj
Zapisz