Changeset 1325


Ignore:
Timestamp:
May 1, 2012, 3:40:56 PM (9 years ago)
Author:
sam
Message:

core: move some of the camera view logic from the Video class to the
Scene and Camera classes.

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/camera.cpp

    r1310 r1325  
    3030{
    3131    m_gamegroup = GAMEGROUP_BEFORE;
     32    m_drawgroup = DRAWGROUP_CAMERA;
    3233
    3334    SetPosition(position);
     
    6566{
    6667    WorldEntity::TickDraw(seconds);
     68
     69    Scene::GetDefault()->SetViewMatrix(m_view_matrix);
     70    Scene::GetDefault()->SetProjMatrix(m_proj_matrix);
    6771}
    6872
  • trunk/src/entity.h

    r1310 r1325  
    5555    {
    5656        DRAWGROUP_BEFORE = GAMEGROUP_END,
     57        DRAWGROUP_CAMERA,
    5758        DRAWGROUP_DEFAULT,
    5859        DRAWGROUP_HUD,
  • trunk/src/gradient.cpp

    r1310 r1325  
    187187
    188188    uni_mat = data->shader->GetUniformLocation("proj_matrix");
    189     data->shader->SetUniform(uni_mat, Video::GetProjMatrix());
     189    data->shader->SetUniform(uni_mat, Scene::GetDefault()->GetProjMatrix());
    190190    uni_mat = data->shader->GetUniformLocation("view_matrix");
    191     data->shader->SetUniform(uni_mat, Video::GetViewMatrix());
     191    data->shader->SetUniform(uni_mat, Scene::GetDefault()->GetViewMatrix());
    192192    uni_mat = data->shader->GetUniformLocation("model_matrix");
    193193    data->shader->SetUniform(uni_mat, model_matrix);
  • trunk/src/scene.cpp

    r1241 r1325  
    3636};
    3737
    38 static Shader *stdshader = NULL;
    39 
    4038/*
    4139 * Scene implementation class
     
    5553    }
    5654
    57     mat4 model_matrix;
     55    mat4 m_model_matrix;
     56    mat4 m_view_matrix;
     57    mat4 m_proj_matrix;
    5858
    5959    Tile *tiles;
    6060    int ntiles;
    61     float angle;
    62 
     61
     62    Shader *m_shader;
    6363    VertexDeclaration *m_vdecl;
    6464    VertexBuffer **bufs;
     
    7474 */
    7575
    76 Scene::Scene(float angle)
     76Scene::Scene()
    7777  : data(new SceneData())
    7878{
     79    data->m_model_matrix = mat4(1.f);
     80    data->m_view_matrix = mat4(1.f);
     81    data->m_proj_matrix = mat4::ortho(0, Video::GetSize().x,
     82                                      0, Video::GetSize().y, -1000.f, 1000.f);
     83
    7984    data->tiles = 0;
    8085    data->ntiles = 0;
    81     data->angle = angle;
    82 
     86
     87    data->m_shader = 0;
    8388    data->bufs = 0;
    8489    data->nbufs = 0;
     
    9297    /* FIXME: this must be done while the GL context is still active.
    9398     * Change the code architecture to make sure of that. */
    94     /* XXX: The test is necessary because of a crash with PSGL. */
     99    /* FIXME: also, make sure we do not add code to Reset() that will
     100     * reallocate stuff */
     101    Reset();
     102
     103    delete data->m_vdecl;
     104    delete data;
     105}
     106
     107Scene *Scene::GetDefault()
     108{
     109    if (!SceneData::scene)
     110        SceneData::scene = new Scene();
     111    return SceneData::scene;
     112}
     113
     114void Scene::Reset()
     115{
    95116    for (int i = 0; i < data->nbufs; i++)
    96117        delete data->bufs[i];
    97118    free(data->bufs);
    98 
    99     delete data->m_vdecl;
    100     delete data;
    101 }
    102 
    103 Scene *Scene::GetDefault()
    104 {
    105     if (!SceneData::scene)
    106         SceneData::scene = new Scene(0.0f);
    107     return SceneData::scene;
    108 }
    109 
    110 void Scene::Reset()
    111 {
    112     if (SceneData::scene)
    113         delete SceneData::scene;
    114     SceneData::scene = NULL;
     119    data->bufs = 0;
     120    data->nbufs = 0;
     121}
     122
     123void Scene::SetViewMatrix(mat4 const &m)
     124{
     125    data->m_view_matrix = m;
     126}
     127
     128void Scene::SetProjMatrix(mat4 const &m)
     129{
     130    data->m_proj_matrix = m;
     131}
     132
     133mat4 const &Scene::GetViewMatrix(void)
     134{
     135    return data->m_view_matrix;
     136}
     137
     138mat4 const &Scene::GetProjMatrix(void)
     139{
     140    return data->m_proj_matrix;
    115141}
    116142
     
    132158void Scene::Render() // XXX: rename to Blit()
    133159{
    134     if (!stdshader)
     160    if (!data->m_shader)
    135161    {
    136162#if !defined _XBOX && !defined __CELLOS_LV2__ && !defined USE_D3D9
    137         stdshader = Shader::Create(
     163        data->m_shader = Shader::Create(
    138164#   if !defined HAVE_GLES_2X
    139165            "#version 130\n"
     
    217243            "}\n");
    218244#else
    219         stdshader = Shader::Create(
     245        data->m_shader = Shader::Create(
    220246            "void main(float4 in_Position : POSITION,"
    221247            "          float2 in_TexCoord : TEXCOORD0,"
     
    289315
    290316    // XXX: debug stuff
    291     data->model_matrix = mat4::translate(320.0f, 240.0f, 0.0f);
    292     data->model_matrix *= mat4::rotate(-data->angle, 1.0f, 0.0f, 0.0f);
     317    data->m_model_matrix = mat4::translate(320.0f, 240.0f, 0.0f);
    293318#if 0
    294319    static float f = 0.0f;
    295320    f += 0.01f;
    296     data->model_matrix *= mat4::rotate(6.0f * sinf(f), 1.0f, 0.0f, 0.0f);
    297     data->model_matrix *= mat4::rotate(17.0f * cosf(f), 0.0f, 0.0f, 1.0f);
    298 #endif
    299     data->model_matrix *= mat4::translate(-320.0f, -240.0f, 0.0f);
     321    data->m_model_matrix *= mat4::rotate(6.0f * sinf(f), 1.0f, 0.0f, 0.0f);
     322    data->m_model_matrix *= mat4::rotate(17.0f * cosf(f), 0.0f, 0.0f, 1.0f);
     323#endif
     324    data->m_model_matrix *= mat4::translate(-320.0f, -240.0f, 0.0f);
    300325    // XXX: end of debug stuff
    301326
    302327    ShaderUniform uni_mat, uni_tex;
    303328    ShaderAttrib attr_pos, attr_tex;
    304     attr_pos = stdshader->GetAttribLocation("in_Position", VertexUsage::Position, 0);
    305     attr_tex = stdshader->GetAttribLocation("in_TexCoord", VertexUsage::TexCoord, 0);
    306 
    307     stdshader->Bind();
    308 
    309     uni_mat = stdshader->GetUniformLocation("proj_matrix");
    310     stdshader->SetUniform(uni_mat, Video::GetProjMatrix());
    311     uni_mat = stdshader->GetUniformLocation("view_matrix");
    312     stdshader->SetUniform(uni_mat, Video::GetViewMatrix());
    313     uni_mat = stdshader->GetUniformLocation("model_matrix");
    314     stdshader->SetUniform(uni_mat, data->model_matrix);
     329    attr_pos = data->m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0);
     330    attr_tex = data->m_shader->GetAttribLocation("in_TexCoord", VertexUsage::TexCoord, 0);
     331
     332    data->m_shader->Bind();
     333
     334    uni_mat = data->m_shader->GetUniformLocation("proj_matrix");
     335    data->m_shader->SetUniform(uni_mat, data->m_proj_matrix);
     336    uni_mat = data->m_shader->GetUniformLocation("view_matrix");
     337    data->m_shader->SetUniform(uni_mat, data->m_view_matrix);
     338    uni_mat = data->m_shader->GetUniformLocation("model_matrix");
     339    data->m_shader->SetUniform(uni_mat, data->m_model_matrix);
    315340
    316341#if defined USE_D3D9 || defined _XBOX
    317342#else
    318     uni_tex = stdshader->GetUniformLocation("in_Texture");
    319     stdshader->SetUniform(uni_tex, 0);
     343    uni_tex = data->m_shader->GetUniformLocation("in_Texture");
     344    data->m_shader->SetUniform(uni_tex, 0);
    320345
    321346#if !defined HAVE_GLES_2X
     
    386411    data->ntiles = 0;
    387412
    388     stdshader->Unbind();
     413    data->m_shader->Unbind();
    389414
    390415#if defined USE_D3D9 || defined _XBOX
  • trunk/src/scene.h

    r1198 r1325  
    2929{
    3030public:
    31     Scene(float angle);
     31    Scene();
    3232    ~Scene();
    3333
    3434    static Scene *GetDefault();
    35     static void Reset();
    3635
     36    void SetViewMatrix(mat4 const &m);
     37    void SetProjMatrix(mat4 const &m);
     38    mat4 const &GetViewMatrix(void);
     39    mat4 const &GetProjMatrix(void);
     40
     41    void Reset();
     42    void Render();
     43
     44    /* FIXME: this should be deprecated -- it doesn't really match
     45     * the architecture we want to build */
    3746    void AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale);
    38     void Render();
    3947
    4048private:
  • trunk/src/ticker.cpp

    r1310 r1325  
    343343    Profiler::Start(Profiler::STAT_TICK_DRAW);
    344344
    345     Video::Clear();
    346 
    347     Scene::GetDefault();
    348 
    349345    /* Tick objects for the draw loop */
    350346    for (int i = Entity::DRAWGROUP_BEGIN; i < Entity::DRAWGROUP_END; i++)
     
    352348        switch (i)
    353349        {
     350        case Entity::DRAWGROUP_BEGIN:
     351            Scene::GetDefault()->Reset();
     352            Video::Clear();
     353            break;
    354354        case Entity::DRAWGROUP_HUD:
    355             Scene::GetDefault()->Render();
    356355            Video::SetDepth(false);
    357356            break;
     
    376375#endif
    377376            }
    378     }
    379 
    380     Scene::GetDefault()->Render();
    381     Scene::Reset();
     377
     378        /* Do this render step */
     379        Scene::GetDefault()->Render();
     380    }
    382381
    383382    Profiler::Stop(Profiler::STAT_TICK_DRAW);
  • trunk/src/video.cpp

    r1303 r1325  
    5252
    5353private:
    54     static mat4 proj_matrix, view_matrix;
     54    static mat4 proj_matrix;
    5555    static ivec2 saved_viewport;
    5656#if defined USE_D3D9
     
    6666
    6767mat4 VideoData::proj_matrix;
    68 mat4 VideoData::view_matrix;
    6968ivec2 VideoData::saved_viewport(0, 0);
    7069
     
    195194        VideoData::proj_matrix = proj * trans;
    196195    }
    197 
    198     VideoData::view_matrix = mat4(1.0f);
    199196}
    200197
     
    298295}
    299296
    300 mat4 const & Video::GetProjMatrix()
    301 {
    302     return VideoData::proj_matrix;
    303 }
    304 
    305 mat4 const & Video::GetViewMatrix()
    306 {
    307     return VideoData::view_matrix;
    308 }
    309 
    310297} /* namespace lol */
    311298
  • trunk/src/video.h

    r1199 r1325  
    3434    static void Capture(uint32_t *buffer);
    3535    static ivec2 GetSize();
    36     static mat4 const & GetProjMatrix();
    37     static mat4 const & GetViewMatrix();
    3836};
    3937
Note: See TracChangeset for help on using the changeset viewer.