Changeset 1196


Ignore:
Timestamp:
Apr 6, 2012, 7:54:16 PM (11 years ago)
Author:
sam
Message:

tutorial: port the rotating cube tutorial to the Xbox 360 and
tweak the triangle tutorial to make it shorter.

Location:
trunk/test/tutorial
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/tutorial/tut01.cpp

    r1194 r1196  
    3939    {
    4040        m_vertices[0] = vec2( 0.0,  0.8);
    41 #if defined _XBOX
    42         m_vertices[2] = vec2(-0.8, -0.8);
    43         m_vertices[1] = vec2( 0.8, -0.8);
    44 #else
    4541        m_vertices[1] = vec2(-0.8, -0.8);
    4642        m_vertices[2] = vec2( 0.8, -0.8);
    47 #endif
    4843        m_ready = false;
    4944    }
     
    5853#if !defined __CELLOS_LV2__ && !defined _XBOX
    5954                "#version 120\n"
    60                 "attribute vec2 coord2d;"
     55                "attribute vec2 in_Position;"
    6156                "void main(void) {"
    62                 "    gl_Position = vec4(coord2d, 0.0, 1.0);"
     57                "    gl_Position = vec4(in_Position, 0.0, 1.0);"
    6358                "}",
    6459
    6560                "#version 120\n"
    6661                "void main(void) {"
    67                 "    gl_FragColor.r = 1.0;"
    68                 "    gl_FragColor.g = 1.0;"
    69                 "    gl_FragColor.b = 0.0;"
    70                 "    gl_FragColor.a = 1.0;"
    71                 "}"
     62                "    gl_FragColor = vec4(0.7, 0.5, 0.2, 1.0);"
     63                "}");
    7264#else
    73                 "void main(float2 coord2d : POSITION,"
     65                "void main(float2 in_Position : POSITION,"
    7466                "          out float4 out_Position : POSITION) {"
    75                 "    out_Position = float4(coord2d, 0.0, 1.0);"
     67                "    out_Position = float4(in_Position, 0.0, 1.0);"
    7668                "}",
    7769
    7870                "void main(out float4 out_FragColor : COLOR) {"
    79                 "    out_FragColor.r = 1.0;"
    80                 "    out_FragColor.g = 1.0;"
    81                 "    out_FragColor.b = 0.0;"
    82                 "    out_FragColor.a = 0.0;"
     71                "    out_FragColor = float4(0.7, 0.5, 0.2, 1.0);"
    8372                "}"
    8473#endif
    8574            );
    86             m_attrib = m_shader->GetAttribLocation("coord2d");
     75#if !defined _XBOX
     76            m_attrib = m_shader->GetAttribLocation("in_Position");
     77#endif
    8778            m_ready = true;
    8879
     
    120111#if defined _XBOX
    121112        extern D3DDevice *g_d3ddevice;
     113        g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
    122114        g_d3ddevice->SetVertexDeclaration(m_vdecl);
    123115        g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices));
     
    160152    D3DVertexDeclaration *m_vdecl;
    161153    D3DVertexBuffer *m_vbo;
    162 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
     154#else
     155    int m_attrib;
     156#   if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    163157    GLuint m_vbo;
     158#   endif
    164159#endif
    165     int m_attrib;
    166160    bool m_ready;
    167161};
  • trunk/test/tutorial/tut02.cpp

    r1179 r1196  
    9393        {
    9494            m_shader = Shader::Create(
     95#if !defined __CELLOS_LV2__ && !defined _XBOX
    9596                "#version 120\n"
    9697                "attribute vec3 in_Vertex;"
     
    109110                "void main(void) {"
    110111                "    gl_FragColor = vec4(pass_Color, 1.0);"
    111                 "}");
     112                "}"
     113#else
     114                "void main(float3 in_Vertex : POSITION,"
     115                "          float3 in_Color : COLOR,"
     116                "          uniform float4x4 in_Matrix,"
     117                "          out float4 out_Position : POSITION,"
     118                "          out float3 pass_Color : COLOR) {"
     119                "    pass_Color = in_Color;"
     120                "    out_Position = mul(in_Matrix, float4(in_Vertex, 1.0));"
     121                "}",
     122
     123                "void main(float3 pass_Color : COLOR,"
     124                "          out float4 out_FragColor : COLOR) {"
     125                "    out_FragColor = float4(pass_Color, 1.0);"
     126                "}"
     127#endif
     128            );
     129#if !defined _XBOX
    112130            m_coord = m_shader->GetAttribLocation("in_Vertex");
    113131            m_color = m_shader->GetAttribLocation("in_Color");
     132#endif
    114133            m_mvp = m_shader->GetUniformLocation("in_Matrix");
    115134            m_ready = true;
    116135
    117 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
     136#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX
    118137            /* Method 1: store vertex buffer on the GPU memory */
    119138            glGenBuffers(1, &m_vbo);
     
    129148            glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_indices), m_indices,
    130149                         GL_STATIC_DRAW);
    131 #else
     150#elif defined _XBOX
     151            extern D3DDevice *g_d3ddevice;
     152            D3DVERTEXELEMENT9 const elements[] =
     153            {
     154                { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
     155                { 1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
     156                D3DDECL_END()
     157            };
     158            g_d3ddevice->CreateVertexDeclaration(elements, &m_vdecl);
     159
     160            if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(m_vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL)))
     161                exit(0);
     162
     163            vec3 *vertices;
     164            if (FAILED(m_vbo->Lock(0, 0, (void **)&vertices, 0)))
     165                exit(0);
     166            memcpy(vertices, m_vertices, sizeof(m_vertices));
     167            m_vbo->Unlock();
     168
     169            if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(m_colors), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_cbo, NULL)))
     170                exit(0);
     171
     172            vec3 *colors;
     173            if (FAILED(m_cbo->Lock(0, 0, (void **)&colors, 0)))
     174                exit(0);
     175            memcpy(colors, m_colors, sizeof(m_colors));
     176            m_cbo->Unlock();
     177
     178            int16_t *indices;
     179            if (FAILED(g_d3ddevice->CreateIndexBuffer(sizeof(m_indices), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_ibo, NULL)))
     180                exit(0);
     181            if (FAILED(m_ibo->Lock(0, 0, (void **)&indices, 0)))
     182                exit(0);
     183            memcpy(indices, m_indices, sizeof(m_indices));
     184            m_ibo->Unlock();
     185#else
     186            /* TODO */
    132187#endif
    133188
     
    137192        m_shader->Bind();
    138193        m_shader->SetUniform(m_mvp, m_matrix);
    139 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
     194#if defined _XBOX
     195        extern D3DDevice *g_d3ddevice;
     196        g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
     197        g_d3ddevice->SetVertexDeclaration(m_vdecl);
     198        g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices));
     199        g_d3ddevice->SetStreamSource(1, m_cbo, 0, sizeof(*m_colors));
     200        g_d3ddevice->SetIndices(m_ibo);
     201        g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices));
     202#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    140203        glEnableVertexAttribArray(m_coord);
    141204        glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
     
    170233    i16vec3 m_indices[12];
    171234    Shader *m_shader;
     235#if defined _XBOX
     236    D3DVertexDeclaration *m_vdecl;
     237    D3DVertexBuffer *m_vbo, *m_cbo;
     238    D3DIndexBuffer *m_ibo;
     239#else
     240    int m_coord, m_color;
    172241#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    173242    GLuint m_vbo, m_cbo, m_ibo;
    174243#endif
    175     int m_coord, m_color, m_mvp;
     244#endif
     245    int m_mvp;
    176246    bool m_ready;
    177247};
     
    181251    Application app("Tutorial 2: Cube", ivec2(640, 480), 60.0f);
    182252
    183 #if defined _MSC_VER
     253#if defined _MSC_VER && !defined _XBOX
    184254    _chdir("..");
    185 #elif defined _WIN32
     255#elif defined _WIN32 && !defined _XBOX
    186256    _chdir("../..");
    187257#endif
Note: See TracChangeset for help on using the changeset viewer.