Changeset 1194


Ignore:
Timestamp:
Apr 5, 2012, 8:43:44 PM (8 years ago)
Author:
sam
Message:

xbox: fix a few problems in the shader handling code; the first tutorial now
works on the Xbox.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/shader.cpp

    r1180 r1194  
    151151#if defined _XBOX
    152152    hr = D3DXCompileShader(frag, (UINT)strlen(frag), NULL, NULL, "main",
    153                            "vs_2_0", 0, &shader_code, &error_msg,
     153                           "ps_2_0", 0, &shader_code, &error_msg,
    154154                           &data->frag_table);
    155155    if (FAILED(hr))
     
    200200{
    201201#if defined _XBOX
    202     D3DXHANDLE hr = data->frag_table->GetConstantByName(NULL, attr);
    203     if (FAILED(hr))
    204         return -1;
    205     UINT count;
    206     D3DXCONSTANT_DESC desc;
    207     data->frag_table->GetConstantDesc(hr, &desc, &count);
    208     return desc.RegisterIndex;
     202    /* FIXME: do we have attribs? */
     203    return 0;
    209204#elif !defined __CELLOS_LV2__
    210205    return glGetAttribLocation(data->prog_id, attr);
     
    218213{
    219214#if defined _XBOX
    220     D3DXHANDLE hr = data->frag_table->GetConstantByName(NULL, uni);
    221     if (FAILED(hr))
    222         return -1;
    223     UINT count;
    224     D3DXCONSTANT_DESC desc;
    225     data->frag_table->GetConstantDesc(hr, &desc, &count);
    226     return desc.RegisterIndex;
     215    D3DXHANDLE hr1 = data->frag_table->GetConstantByName(NULL, uni);
     216    D3DXHANDLE hr2 = data->vert_table->GetConstantByName(NULL, uni);
     217    return (int)(((uint32_t)hr1 << 16) | (uint32_t)hr2);
    227218#elif !defined __CELLOS_LV2__
    228219    return glGetUniformLocation(data->prog_id, uni);
     
    240231{
    241232#if defined _XBOX
     233    SetUniform(uni, vec4(f, 0, 0, 0));
     234#elif !defined __CELLOS_LV2__
     235    glUniform1f(uni, f);
     236#else
     237    cgGLSetParameter1f((CGparameter)(intptr_t)uni, f);
     238#endif
     239}
     240
     241void Shader::SetUniform(int uni, vec2 const &v)
     242{
     243#if defined _XBOX
     244    SetUniform(uni, vec4(v, 0, 0));
     245#elif !defined __CELLOS_LV2__
     246    glUniform2f(uni, v.x, v.y);
     247#else
     248    cgGLSetParameter2f((CGparameter)(intptr_t)uni, v.x, v.y);
     249#endif
     250}
     251
     252void Shader::SetUniform(int uni, vec3 const &v)
     253{
     254#if defined _XBOX
     255    SetUniform(uni, vec4(v, 0));
     256#elif !defined __CELLOS_LV2__
     257    glUniform3f(uni, v.x, v.y, v.z);
     258#else
     259    cgGLSetParameter3f((CGparameter)(intptr_t)uni, v.x, v.y, v.z);
     260#endif
     261}
     262
     263void Shader::SetUniform(int uni, vec4 const &v)
     264{
     265    /* FIXME: use the array versions of these functions */
     266#if defined _XBOX
    242267    extern D3DDevice *g_d3ddevice;
    243     vec4 tmp(f, 0.0f, 0.0f, 0.0f);
    244     g_d3ddevice->SetPixelShaderConstantF(uni, &tmp[0], 1);
    245 #elif !defined __CELLOS_LV2__
    246     glUniform1f(uni, f);
    247 #else
    248     cgGLSetParameter1f((CGparameter)(intptr_t)uni, f);
    249 #endif
    250 }
    251 
    252 void Shader::SetUniform(int uni, vec2 const &v)
     268    D3DXHANDLE hr1 = (uint32_t)uni >> 16;
     269    D3DXHANDLE hr2 = (uint32_t)(uint16_t)uni;
     270    g_d3ddevice->SetPixelShaderConstantF(hr1, &v[0], 1);
     271    g_d3ddevice->SetVertexShaderConstantF(hr2, &v[0], 1);
     272#elif !defined __CELLOS_LV2__
     273    glUniform4f(uni, v.x, v.y, v.z, v.w);
     274#else
     275    cgGLSetParameter4f((CGparameter)(intptr_t)uni, v.x, v.y, v.z, v.w);
     276#endif
     277}
     278
     279void Shader::SetUniform(int uni, mat4 const &m)
    253280{
    254281#if defined _XBOX
    255282    extern D3DDevice *g_d3ddevice;
    256     vec4 tmp(v, 0.0f, 0.0f);
    257     g_d3ddevice->SetPixelShaderConstantF(uni, &tmp[0], 1);
    258 #elif !defined __CELLOS_LV2__
    259     glUniform2f(uni, v.x, v.y);
    260 #else
    261     cgGLSetParameter2f((CGparameter)(intptr_t)uni, v.x, v.y);
    262 #endif
    263 }
    264 
    265 void Shader::SetUniform(int uni, vec3 const &v)
    266 {
    267 #if defined _XBOX
    268     extern D3DDevice *g_d3ddevice;
    269     vec4 tmp(v, 0.0f);
    270     g_d3ddevice->SetPixelShaderConstantF(uni, &tmp[0], 1);
    271 #elif !defined __CELLOS_LV2__
    272     glUniform3f(uni, v.x, v.y, v.z);
    273 #else
    274     cgGLSetParameter3f((CGparameter)(intptr_t)uni, v.x, v.y, v.z);
    275 #endif
    276 }
    277 
    278 void Shader::SetUniform(int uni, vec4 const &v)
    279 {
    280     /* FIXME: use the array versions of these functions */
    281 #if defined _XBOX
    282     extern D3DDevice *g_d3ddevice;
    283     g_d3ddevice->SetPixelShaderConstantF(uni, &v[0], 1);
    284 #elif !defined __CELLOS_LV2__
    285     glUniform4f(uni, v.x, v.y, v.z, v.w);
    286 #else
    287     cgGLSetParameter4f((CGparameter)(intptr_t)uni, v.x, v.y, v.z, v.w);
    288 #endif
    289 }
    290 
    291 void Shader::SetUniform(int uni, mat4 const &m)
    292 {
    293 #if defined _XBOX
    294     extern D3DDevice *g_d3ddevice;
    295     g_d3ddevice->SetPixelShaderConstantF(uni, &m[0][0], 4);
     283    D3DXHANDLE hr1 = (uint32_t)uni >> 16;
     284    D3DXHANDLE hr2 = (uint32_t)(uint16_t)uni;
     285    g_d3ddevice->SetPixelShaderConstantF(hr1, &m[0][0], 4);
     286    g_d3ddevice->SetVertexShaderConstantF(hr2, &m[0][0], 4);
    296287#elif !defined __CELLOS_LV2__
    297288    glUniformMatrix4fv(uni, 1, GL_FALSE, &m[0][0]);
  • trunk/src/platform/xbox/xboxapp.cpp

    r1189 r1194  
    4545{
    4646#if defined _XBOX
     47    Ticker::Setup(fps);
     48    Video::Setup(res);
    4749#endif
    4850}
  • trunk/src/scene.cpp

    r1179 r1194  
    144144void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o)
    145145{
     146#if !defined _XBOX /* No WPOS on Xbox */
    146147    if ((data->ntiles % 1024) == 0)
    147148        data->tiles = (Tile *)realloc(data->tiles,
     
    154155    data->tiles[data->ntiles].o = o;
    155156    data->ntiles++;
     157#endif
    156158}
    157159
    158160void Scene::Render() // XXX: rename to Blit()
    159161{
     162#if !defined _XBOX /* No WPOS on Xbox */
    160163    if (!stdshader)
    161164    {
     
    484487    glDisable(GL_BLEND);
    485488#endif
     489#endif /* _XBOX */
    486490}
    487491
  • trunk/src/video.cpp

    r1189 r1194  
    9595    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    9696
    97     if (!VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, NULL,
    98                                           D3DCREATE_HARDWARE_VERTEXPROCESSING,
    99                                           &d3dpp, &VideoData::d3d_dev))
     97    if (FAILED(VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, NULL,
     98                                                D3DCREATE_HARDWARE_VERTEXPROCESSING,
     99                                                &d3dpp, &VideoData::d3d_dev)))
    100100    {
    101101        Log::Error("cannot create D3D device\n");
  • trunk/test/tutorial/tut01.cpp

    r1192 r1194  
    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
    4145        m_vertices[1] = vec2(-0.8, -0.8);
    4246        m_vertices[2] = vec2( 0.8, -0.8);
     47#endif
    4348        m_ready = false;
    4449    }
     
    6065                "#version 120\n"
    6166                "void main(void) {"
    62                 "    gl_FragColor[0] = 0.0;"
    63                 "    gl_FragColor[1] = 0.0;"
    64                 "    gl_FragColor[2] = 1.0;"
     67                "    gl_FragColor.r = 1.0;"
     68                "    gl_FragColor.g = 1.0;"
     69                "    gl_FragColor.b = 0.0;"
     70                "    gl_FragColor.a = 1.0;"
    6571                "}"
    6672#else
     
    7177
    7278                "void main(out float4 out_FragColor : COLOR) {"
    73                 "    out_FragColor[0] = 0.0;"
    74                 "    out_FragColor[0] = 0.0;"
    75                 "    out_FragColor[0] = 1.0;"
     79                "    out_FragColor.r = 1.0;"
     80                "    out_FragColor.g = 1.0;"
     81                "    out_FragColor.b = 0.0;"
     82                "    out_FragColor.a = 0.0;"
    7683                "}"
    7784#endif
     
    9097#elif defined _XBOX
    9198            extern D3DDevice *g_d3ddevice;
    92             D3DVERTEXELEMENT9 const elements[3] =
     99            D3DVERTEXELEMENT9 const elements[2] =
    93100            {
    94101                { 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
     
    96103            };
    97104            g_d3ddevice->CreateVertexDeclaration(elements, &m_vdecl);
    98             g_d3ddevice->CreateVertexBuffer(sizeof(m_vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL);
     105            if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(m_vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL)))
     106                exit(0);
    99107
    100108            vec2 *vertices;
    101             m_vbo->Lock(0, 0, (void **)&vertices, 0);
     109            if (FAILED(m_vbo->Lock(0, 0, (void **)&vertices, 0)))
     110                exit(0);
    102111            memcpy(vertices, m_vertices, sizeof(m_vertices));
    103112            m_vbo->Unlock();
Note: See TracChangeset for help on using the changeset viewer.