Changeset 1179


Ignore:
Timestamp:
Mar 29, 2012, 7:19:47 PM (8 years ago)
Author:
sam
Message:

win32: add a lot of DirectX stubs.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scene.cpp

    r1083 r1179  
    6060    float angle;
    6161
     62#if defined _XBOX
     63#   define STR0(x) #x
     64#   define STR(x) STR0(x)
     65#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene not implemented")
     66#   undef STR
     67#   undef STR0
     68#else
    6269#if defined HAVE_GL_2X && !defined __APPLE__
    6370    GLuint vao;
     
    6572    GLuint *bufs;
    6673    int nbufs;
     74#endif
    6775
    6876    static Scene *scene;
     
    8290    data->angle = angle;
    8391
     92#if defined _XBOX
     93#   define STR0(x) #x
     94#   define STR(x) STR0(x)
     95#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Scene() not implemented")
     96#   undef STR
     97#   undef STR0
     98#else
    8499    data->bufs = 0;
    85100    data->nbufs = 0;
     101#endif
    86102
    87103#if defined HAVE_GL_2X && !defined __APPLE__
     
    92108Scene::~Scene()
    93109{
     110#if defined _XBOX
     111#   define STR0(x) #x
     112#   define STR(x) STR0(x)
     113#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::~Scene() not implemented")
     114#   undef STR
     115#   undef STR0
     116#else
    94117    /* FIXME: this must be done while the GL context is still active.
    95118     * Change the code architecture to make sure of that. */
     
    101124#endif
    102125    free(data->bufs);
     126#endif
    103127    delete data;
    104128}
     
    136160    if (!stdshader)
    137161    {
    138 #if !defined __CELLOS_LV2__
     162#if !defined _XBOX && !defined __CELLOS_LV2__
    139163        stdshader = Shader::Create(
    140164#if !defined HAVE_GLES_2X
     
    300324    // XXX: end of debug stuff
    301325
    302     GLuint uni_mat, uni_tex, attr_pos, attr_tex;
     326    int uni_mat, uni_tex, attr_pos, attr_tex;
    303327#if !defined __CELLOS_LV2__
    304328    attr_pos = stdshader->GetAttribLocation("in_Position");
     
    315339    stdshader->SetUniform(uni_mat, data->model_matrix);
    316340
    317 #if !defined __CELLOS_LV2__
     341#if defined _XBOX
     342#   define STR0(x) #x
     343#   define STR(x) STR0(x)
     344#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented")
     345#   undef STR
     346#   undef STR0
     347#elif !defined __CELLOS_LV2__
    318348    uni_tex = stdshader->GetUniformLocation("in_Texture");
    319349    glUniform1i(uni_tex, 0);
     
    324354#endif
    325355
     356#if defined _XBOX
     357#   define STR0(x) #x
     358#   define STR(x) STR0(x)
     359#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented")
     360#   undef STR
     361#   undef STR0
     362#else
    326363#if !defined HAVE_GLES_2X
    327364    glEnable(GL_TEXTURE_2D);
     
    335372    glEnable(GL_BLEND);
    336373    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     374#endif
    337375
    338376    for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2)
    339377    {
     378#if defined _XBOX
     379#   define STR0(x) #x
     380#   define STR(x) STR0(x)
     381#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented")
     382#   undef STR
     383#   undef STR0
     384#else
    340385        /* Generate new vertex / texture coord buffers if necessary */
    341386        if (buf + 2 > data->nbufs)
    342387        {
    343             data->bufs = (GLuint *)realloc(data->bufs, (buf + 2) * sizeof(GLuint));
     388            data->bufs = (uint32_t *)realloc(data->bufs, (buf + 2) * sizeof(uint32_t));
    344389            glGenBuffers(buf + 2 - data->nbufs, data->bufs + data->nbufs);
    345390            data->nbufs = buf + 2;
    346391        }
     392#endif
    347393
    348394        /* Count how many quads will be needed */
     
    371417        glBindVertexArray(data->vao);
    372418#endif
     419#if defined _XBOX
     420#   define STR0(x) #x
     421#   define STR(x) STR0(x)
     422#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented")
     423#   undef STR
     424#   undef STR0
     425#else
    373426#if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc.
    374427        glEnableVertexAttribArray(attr_pos);
     
    405458        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    406459#endif
     460#endif
    407461
    408462        free(vertex);
     
    414468    data->ntiles = 0;
    415469
     470#if defined _XBOX
     471#   define STR0(x) #x
     472#   define STR(x) STR0(x)
     473#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented")
     474#   undef STR
     475#   undef STR0
     476#else
    416477#if !defined HAVE_GLES_2X
    417478    glDisable(GL_TEXTURE_2D);
     
    422483#endif
    423484    glDisable(GL_BLEND);
     485#endif
    424486}
    425487
  • trunk/src/shader/shader.cpp

    r1174 r1179  
    4040private:
    4141#if defined _XBOX
    42 
     42    D3DVertexShader *vert_shader;
     43    D3DPixelShader *frag_shader;
     44    ID3DXConstantTable *vert_table, *frag_table;
    4345#elif !defined __CELLOS_LV2__
    4446    GLuint prog_id, vert_id, frag_id;
     
    9193  : data(new ShaderData())
    9294{
    93 #if !defined __CELLOS_LV2__
     95#if defined _XBOX
     96    extern D3DDevice *g_d3ddevice;
     97    ID3DXBuffer *shader_code, *error_msg;
     98    HRESULT hr;
     99#elif !defined __CELLOS_LV2__
    94100    char buf[4096], errbuf[4096];
    95101    char const *shader = buf;
     
    104110    /* Compile vertex shader */
    105111    data->vert_crc = Hash::Crc32(vert);
    106 #if !defined __CELLOS_LV2__
     112#if defined _XBOX
     113    hr = D3DXCompileShader(vert, (UINT)strlen(vert), NULL, NULL, "main",
     114                           "vs_2_0", 0, &shader_code, &error_msg,
     115                           &data->vert_table);
     116    if (FAILED(hr))
     117    {
     118        Log::Error("failed to compile vertex shader: %s",
     119                   error_msg ? error_msg->GetBufferPointer() : "error");
     120        Log::Error("shader source:\n%s\n", vert);
     121    }
     122    g_d3ddevice->CreateVertexShader((DWORD *)shader_code->GetBufferPointer(),
     123                                    &data->vert_shader);
     124    shader_code->Release();
     125#elif !defined __CELLOS_LV2__
    107126    ShaderData::Patch(buf, vert, NULL);
    108127    data->vert_id = glCreateShader(GL_VERTEX_SHADER);
     
    130149    /* Compile fragment shader */
    131150    data->frag_crc = Hash::Crc32(frag);
    132 #if !defined __CELLOS_LV2__
     151#if defined _XBOX
     152    hr = D3DXCompileShader(frag, (UINT)strlen(frag), NULL, NULL, "main",
     153                           "vs_2_0", 0, &shader_code, &error_msg,
     154                           &data->frag_table);
     155    if (FAILED(hr))
     156    {
     157        Log::Error("failed to compile fragment shader: %s",
     158                   error_msg ? error_msg->GetBufferPointer() : "error");
     159        Log::Error("shader source:\n%s\n", frag);
     160    }
     161    g_d3ddevice->CreatePixelShader((DWORD *)shader_code->GetBufferPointer(),
     162                                   &data->frag_shader);
     163    shader_code->Release();
     164#elif !defined __CELLOS_LV2__
    133165    ShaderData::Patch(buf, NULL, frag);
    134166    data->frag_id = glCreateShader(GL_FRAGMENT_SHADER);
     
    154186#endif
    155187
    156 #if !defined __CELLOS_LV2__
     188#if !defined _XBOX && !defined __CELLOS_LV2__
    157189    /* Create program */
    158190    data->prog_id = glCreateProgram();
     
    167199int Shader::GetAttribLocation(char const *attr) const
    168200{
    169 #if !defined __CELLOS_LV2__
     201#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;
     209#elif !defined __CELLOS_LV2__
    170210    return glGetAttribLocation(data->prog_id, attr);
    171211#else
     
    177217int Shader::GetUniformLocation(char const *uni) const
    178218{
    179 #if !defined __CELLOS_LV2__
     219#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;
     227#elif !defined __CELLOS_LV2__
    180228    return glGetUniformLocation(data->prog_id, uni);
    181229#else
     
    191239void Shader::SetUniform(int uni, float f)
    192240{
    193 #if !defined __CELLOS_LV2__
     241#if defined _XBOX
     242    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__
    194246    glUniform1f(uni, f);
    195247#else
     
    200252void Shader::SetUniform(int uni, vec2 const &v)
    201253{
    202 #if !defined __CELLOS_LV2__
     254#if defined _XBOX
     255    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__
    203259    glUniform2f(uni, v.x, v.y);
    204260#else
     
    209265void Shader::SetUniform(int uni, vec3 const &v)
    210266{
    211 #if !defined __CELLOS_LV2__
     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__
    212272    glUniform3f(uni, v.x, v.y, v.z);
    213273#else
     
    219279{
    220280    /* FIXME: use the array versions of these functions */
    221 #if !defined __CELLOS_LV2__
     281#if defined _XBOX
     282    extern D3DDevice *g_d3ddevice;
     283    g_d3ddevice->SetPixelShaderConstantF(uni, &v[0], 1);
     284#elif !defined __CELLOS_LV2__
    222285    glUniform4f(uni, v.x, v.y, v.z, v.w);
    223286#else
     
    228291void Shader::SetUniform(int uni, mat4 const &m)
    229292{
    230 #if !defined __CELLOS_LV2__
     293#if defined _XBOX
     294    extern D3DDevice *g_d3ddevice;
     295    g_d3ddevice->SetPixelShaderConstantF(uni, &m[0][0], 4);
     296#elif !defined __CELLOS_LV2__
    231297    glUniformMatrix4fv(uni, 1, GL_FALSE, &m[0][0]);
    232298#else
     
    237303void Shader::Bind() const
    238304{
    239 #if !defined __CELLOS_LV2__
     305#if defined _XBOX
     306    extern D3DDevice *g_d3ddevice;
     307    g_d3ddevice->SetVertexShader(data->vert_shader);
     308    g_d3ddevice->SetPixelShader(data->frag_shader);
     309#elif !defined __CELLOS_LV2__
    240310    glUseProgram(data->prog_id);
    241311#else
     
    249319Shader::~Shader()
    250320{
    251 #if !defined __CELLOS_LV2__
     321#if defined _XBOX
     322    extern D3DDevice *g_d3ddevice;
     323    data->vert_shader->Release();
     324    data->vert_table->Release();
     325    data->frag_shader->Release();
     326    data->frag_table->Release();
     327#elif !defined __CELLOS_LV2__
    252328    glDetachShader(data->prog_id, data->vert_id);
    253329    glDetachShader(data->prog_id, data->frag_id);
     
    267343    static int version = 0;
    268344
    269 #if !defined __CELLOS_LV2__
     345#if !defined _XBOX && !defined __CELLOS_LV2__
    270346    if (!version)
    271347    {
  • trunk/src/tileset.cpp

    r1134 r1179  
    4646
    4747    Image *img;
     48#if defined _XBOX
     49#   define STR0(x) #x
     50#   define STR(x) STR0(x)
     51#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet not implemented")
     52#   undef STR
     53#   undef STR0
     54#else
    4855    GLuint texture;
     56#endif
    4957};
    5058
     
    6169
    6270    data->tiles = NULL;
     71#if defined _XBOX
     72#   define STR0(x) #x
     73#   define STR(x) STR0(x)
     74#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented")
     75#   undef STR
     76#   undef STR0
     77#else
    6378    data->texture = 0;
     79#endif
    6480    data->img = new Image(path);
    6581    data->isize = data->img->GetSize();
     
    103119        if (data->img)
    104120            delete data->img;
     121#if defined _XBOX
     122#   define STR0(x) #x
     123#   define STR(x) STR0(x)
     124#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented")
     125#   undef STR
     126#   undef STR0
     127#else
    105128        else
    106129            glDeleteTextures(1, &data->texture);
     130#endif
    107131    }
    108132    else if (data->img)
    109133    {
     134#if defined _XBOX
     135#   define STR0(x) #x
     136#   define STR(x) STR0(x)
     137#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented")
     138#   undef STR
     139#   undef STR0
     140#else
    110141        GLuint format;
    111142        int planes;
     
    150181        if (pixels != data->img->GetData())
    151182            free(pixels);
     183#endif
    152184        delete data->img;
    153185        data->img = NULL;
     
    172204void TileSet::Bind()
    173205{
     206#if defined _XBOX
     207#   define STR0(x) #x
     208#   define STR(x) STR0(x)
     209#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::Bind() not implemented")
     210#   undef STR
     211#   undef STR0
     212#else
    174213    if (!data->img && data->texture)
    175214    {
     
    177216        glBindTexture(GL_TEXTURE_2D, data->texture);
    178217    }
     218#endif
    179219}
    180220
     
    190230    int dz = o ? data->size.y : 0;
    191231
     232#if defined _XBOX
     233#   define STR0(x) #x
     234#   define STR(x) STR0(x)
     235#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented")
     236#   undef STR
     237#   undef STR0
     238#else
    192239    if (!data->img && data->texture)
    193240    {
     
    235282        memset(texture, 0, 2 * sizeof(float));
    236283    }
     284#endif
    237285}
    238286
  • trunk/src/video.cpp

    r1173 r1179  
    167167void Video::SetDepth(bool set)
    168168{
     169#if defined _XBOX
     170#   define STR0(x) #x
     171#   define STR(x) STR0(x)
     172#   pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetDepth() not implemented")
     173#else
    169174    if (set)
    170175        glEnable(GL_DEPTH_TEST);
    171176    else
    172177        glDisable(GL_DEPTH_TEST);
     178#endif
    173179}
    174180
  • trunk/test/tutorial/tut01.cpp

    r1178 r1179  
    3030#if defined _WIN32
    3131#   undef main /* FIXME: still needed? */
     32#   include <direct.h>
    3233#endif
    3334
  • trunk/test/tutorial/tut02.cpp

    r1178 r1179  
    2626#if defined _WIN32
    2727#   undef main /* FIXME: still needed? */
     28#   include <direct.h>
    2829#endif
    2930
Note: See TracChangeset for help on using the changeset viewer.