Changeset 2001


Ignore:
Timestamp:
Oct 9, 2012, 5:22:37 PM (5 years ago)
Author:
sam
Message:

tutorial: add a new texture generation example.

Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/.gitignore

    r1995 r2001  
    7979tutorial/02_cube
    8080tutorial/03_noise
     81tutorial/04_texture
    8182tutorial/05_easymesh
    8283tutorial/08_fbo
  • trunk/src/gpu/shader.h

    r1849 r2001  
    5151    friend class Shader;
    5252    friend class FrameBuffer;
     53    friend class Texture;
    5354
    5455public:
  • trunk/src/gpu/texture.cpp

    r1994 r2001  
    4646
    4747#if defined USE_D3D9
    48     IDirect3DTexture9 *m_tex;
     48    IDirect3DTexture9 *m_texture;
    4949#elif defined _XBOX
    50     D3DTexture *m_tex;
    51 #else
    52     GLuint m_texid;
     50    D3DTexture *m_texture;
     51#else
     52    GLuint m_texture;
    5353    GLint m_internal_format;
    5454    GLenum m_gl_format, m_gl_type;
     
    102102    g_d3ddevice->CreateTexture(m_data->m_size.x, m_data->m_size.y, 1,
    103103                               d3d_usage, d3d_format,
    104                                D3DPOOL_DEFAULT, &m_data->m_tex, NULL);
     104                               D3DPOOL_DEFAULT, &m_data->m_texture, NULL);
    105105#else
    106106    static struct
     
    144144    m_data->m_gl_type = GET_CLAMPED(gl_formats, format).type;
    145145
    146     glGenTextures(1, &m_data->m_texid);
    147     glBindTexture(GL_TEXTURE_2D, m_data->m_texid);
     146    glGenTextures(1, &m_data->m_texture);
     147    glBindTexture(GL_TEXTURE_2D, m_data->m_texture);
    148148
    149149#   if defined __CELLOS_LV2__
     
    158158}
    159159
     160ShaderTexture Texture::GetTexture() const
     161{
     162    ShaderTexture ret;
     163#if defined USE_D3D9 || defined _XBOX
     164    ret.m_flags = (uint64_t)(uintptr_t)m_data->m_texture;
     165#else
     166    ret.m_flags = m_data->m_texture;
     167#endif
     168    return ret;
     169}
     170
    160171void Texture::Bind()
    161172{
    162173#if defined _XBOX || defined USE_D3D9
    163     g_d3ddevice->SetTexture(0, m_data->m_tex);
     174    g_d3ddevice->SetTexture(0, m_data->m_texture);
    164175#else
    165176#   if !defined HAVE_GLES_2X
    166177    glEnable(GL_TEXTURE_2D);
    167178#   endif
    168     glBindTexture(GL_TEXTURE_2D, m_data->m_texid);
     179    glBindTexture(GL_TEXTURE_2D, m_data->m_texture);
    169180#endif
    170181}
     
    175186    D3DLOCKED_RECT rect;
    176187#   if defined USE_D3D9
    177     m_data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_DISCARD);
    178 #   else
    179     m_data->m_tex->LockRect(0, &rect, NULL, 0);
     188    m_data->m_texture->LockRect(0, &rect, NULL, D3DLOCK_DISCARD);
     189#   else
     190    m_data->m_texture->LockRect(0, &rect, NULL, 0);
    180191#   endif
    181192
    182193    memcpy(rect.pBits, data, rect.Pitch * m_data->m_size.y);
    183194
    184     m_data->m_tex->UnlockRect(0);
     195    m_data->m_texture->UnlockRect(0);
    185196
    186197#else
     
    195206#if defined _XBOX || defined USE_D3D9
    196207    D3DLOCKED_RECT rect;
    197     m_data->m_tex->LockRect(0, &rect, NULL, 0);
     208    m_data->m_texture->LockRect(0, &rect, NULL, 0);
    198209
    199210    for (int j = 0; j < size.y; j++)
     
    205216    }
    206217
    207     m_data->m_tex->UnlockRect(0);
     218    m_data->m_texture->UnlockRect(0);
    208219
    209220#else
     
    216227{
    217228#if defined USE_D3D9 || defined _XBOX
    218     m_data->m_tex->Release();
    219 #else
    220     glDeleteTextures(1, &m_data->m_texid);
     229    m_data->m_texture->Release();
     230#else
     231    glDeleteTextures(1, &m_data->m_texture);
    221232#endif
    222233
  • trunk/src/gpu/texture.h

    r1992 r2001  
    4747    void SetSubData(ivec2 origin, ivec2 size, void *data);
    4848
     49    ShaderTexture GetTexture() const;
     50
    4951private:
    5052    class TextureData *m_data;
  • trunk/tutorial/Makefile.am

    r1981 r2001  
    44AM_CPPFLAGS = -I$(top_srcdir)/src
    55
    6 noinst_PROGRAMS = 01_triangle 02_cube 03_noise 05_easymesh 08_fbo 11_fractal
     6noinst_PROGRAMS = 01_triangle 02_cube 03_noise 04_texture 05_easymesh \
     7                  08_fbo 11_fractal
    78
    8901_triangle_SOURCES = 01_triangle.cpp 01_triangle.lolfx
     
    212203_noise_DEPENDENCIES = $(top_builddir)/src/liblol.a
    2223
     2404_texture_SOURCES = 04_texture.cpp 04_texture.lolfx
     2504_texture_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
     2604_texture_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
     2704_texture_DEPENDENCIES = $(top_builddir)/src/liblol.a
     28
    232905_easymesh_SOURCES = 05_easymesh.cpp
    243005_easymesh_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
Note: See TracChangeset for help on using the changeset viewer.