Ignore:
Timestamp:
Jun 22, 2011, 12:36:47 AM (9 years ago)
Author:
sam
Message:

video: move the last shader from the Video class to Scene itself.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/video.cpp

    r780 r784  
    2828{
    2929
     30class VideoData
     31{
     32    friend class Video;
     33
     34private:
     35    static mat4 proj_matrix, view_matrix;
    3036#if defined ANDROID_NDK
    31 vec2i saved_viewport;
     37    static vec2i saved_viewport;
    3238#endif
     39};
    3340
    34 Shader *stdshader;
    35 mat4 proj_matrix, view_matrix, model_matrix;
     41mat4 VideoData::proj_matrix;
     42mat4 VideoData::view_matrix;
    3643
    37 #define OLD
    38 
    39 static char const *vertexshader =
    40     "#version 130\n"
    41     "\n"
    42 #if defined HAVE_GLES_2X
    43     "attribute vec3 in_Position;\n"
    44     "attribute vec2 in_TexCoord;\n"
    45     "varying vec2 pass_TexCoord;\n"
    46 #else
    47     "in vec3 in_Position;\n"
    48     "in vec2 in_TexCoord;\n"
     44#if defined ANDROID_NDK
     45vec2i VideoData::saved_viewport = 0;
    4946#endif
    50     "uniform mat4 proj_matrix;\n"
    51     "uniform mat4 view_matrix;\n"
    52     "uniform mat4 model_matrix;\n"
    53     "\n"
    54     "void main()\n"
    55     "{\n"
    56     "    gl_Position = proj_matrix * view_matrix * model_matrix"
    57     "                * vec4(in_Position, 1.0);\n"
    58 #if defined HAVE_GLES_2X
    59     "    pass_TexCoord = in_TexCoord;\n"
    60 #else
    61     "    gl_TexCoord[0] = vec4(in_TexCoord, 0.0, 0.0);\n"
    62 #endif
    63     "}\n";
    64 
    65 static char const *fragmentshader =
    66     "#version 130\n"
    67     "\n"
    68     "uniform sampler2D in_Texture;\n"
    69 #if defined HAVE_GLES_2X
    70     "varying vec2 pass_TexCoord;\n"
    71 #endif
    72     "\n"
    73     "void main()\n"
    74     "{\n"
    75 #if defined HAVE_GLES_2X
    76     "    vec4 col = texture2D(in_Texture, pass_TexCoord);\n"
    77     //"    vec4 col = vec4(0.5, 1.0, 0.0, 0.5);\n"
    78     //"    vec4 col = vec4(pass_TexCoord * 4.0, 0.0, 0.25);\n"
    79 #else
    80     "    vec4 col = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n"
    81 #endif
    82 #if 0
    83     "    float mul = 2.0;\n"
    84 #if 0
    85     "    vec2 d1 = mod(vec2(gl_FragCoord), vec2(2.0, 2.0));\n"
    86     "    float t1 = mod(3.0 * d1.x + 2.0 * d1.y, 4.0);\n"
    87     "    float dx2 = mod(floor(gl_FragCoord.x * 0.5), 2.0);\n"
    88     "    float dy2 = mod(floor(gl_FragCoord.y * 0.5), 2.0);\n"
    89     "    float t2 = mod(3.0 * dx2 + 2.0 * dy2, 4.0);\n"
    90     "    float dx3 = mod(floor(gl_FragCoord.x * 0.25), 2.0);\n"
    91     "    float dy3 = mod(floor(gl_FragCoord.y * 0.25), 2.0);\n"
    92     "    float t3 = mod(3.0 * dx3 + 2.0 * dy3, 4.0);\n"
    93     "    float t1 = (1.0 + 16.0 * t1 + 4.0 * t2 + t3) / 65.0;\n"
    94     "    float t2 = t1;\n"
    95     "    float t3 = t1;\n"
    96 #else
    97     "    float rand = sin(gl_FragCoord.x * 1.23456) * 123.456\n"
    98     "               + cos(gl_FragCoord.y * 2.34567) * 789.012;\n"
    99     "    float t1 = mod(sin(rand) * 17.13043, 1.0);\n"
    100     "    float t2 = mod(sin(rand) * 27.13043, 1.0);\n"
    101     "    float t3 = mod(sin(rand) * 37.13043, 1.0);\n"
    102 #endif
    103     "    float fracx = fract(col.x * mul);\n"
    104     "    float fracy = fract(col.y * mul);\n"
    105     "    float fracz = fract(col.z * mul);\n"
    106     "    fracx = fracx > t1 ? 1.0 : 0.0;\n"
    107     "    fracy = fracy > t2 ? 1.0 : 0.0;\n"
    108     "    fracz = fracz > t3 ? 1.0 : 0.0;\n"
    109     "    col.x = (floor(col.x * mul) + fracx) / mul;\n"
    110     "    col.y = (floor(col.y * mul) + fracy) / mul;\n"
    111     "    col.z = (floor(col.z * mul) + fracz) / mul;\n"
    112 #endif
    113     "    gl_FragColor = col;\n"
    114     "}\n";
    11547
    11648/*
     
    12456
    12557#if defined ANDROID_NDK
    126     saved_viewport = vec2i(size.x, size.y);
     58    VideoData::saved_viewport = size;
    12759#endif
    12860
     
    13466    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    13567#endif
    136 
    137     stdshader = Shader::Create(vertexshader, fragmentshader);
    13868}
    13969
     
    14272#undef near /* Fuck Microsoft */
    14373#undef far /* Fuck Microsoft again */
    144     mat4 proj;
    145 
    14674    vec2 size = GetSize();
    14775    float near = -size.x - size.y;
     
    15684    {
    15785        /* The easy way: purely orthogonal projection. */
    158         proj_matrix = mat4::ortho(0, size.x, 0, size.y, near, far);
     86        VideoData::proj_matrix = mat4::ortho(0, size.x, 0, size.y, near, far);
    15987    }
    16088    else
     
    176104        }
    177105
    178         proj_matrix = mat4::frustum(-near * t1, near * t1,
    179                                     -near * t2, near * t2, near, far)
    180                     * mat4::translate(-0.5f * size.x, -0.5f * size.y, -dist);
     106        mat4 proj = mat4::frustum(-near * t1, near * t1,
     107                                  -near * t2, near * t2, near, far);
     108        mat4 trans = mat4::translate(-0.5f * size.x, -0.5f * size.y, -dist);
     109        VideoData::proj_matrix = proj * trans;
    181110    }
    182111
    183     view_matrix = mat4(1.0f);
    184 
    185     stdshader->Bind(); /* Required on GLES 2.x? */
    186 #if !defined __CELLOS_LV2__ // Use cgGetNamedParameter etc.
    187     GLuint uni;
    188     uni = stdshader->GetUniformLocation("proj_matrix");
    189     glUniformMatrix4fv(uni, 1, GL_FALSE, &proj_matrix[0][0]);
    190     uni = stdshader->GetUniformLocation("view_matrix");
    191     glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]);
    192 #endif
     112    VideoData::view_matrix = mat4(1.0f);
    193113}
    194114
     
    212132void Video::Destroy()
    213133{
    214     Shader::Destroy(stdshader);
     134    ;
    215135}
    216136
     
    250170{
    251171#if defined ANDROID_NDK
    252     return saved_viewport;
     172    return VideoData::saved_viewport;
    253173#elif defined __CELLOS_LV2__
    254174    // FIXME: use psglCreateDeviceAuto && psglGetDeviceDimensions
     
    261181}
    262182
     183mat4 const & Video::GetProjMatrix()
     184{
     185    return VideoData::proj_matrix;
     186}
     187
     188mat4 const & Video::GetViewMatrix()
     189{
     190    return VideoData::view_matrix;
     191}
     192
    263193} /* namespace lol */
    264194
Note: See TracChangeset for help on using the changeset viewer.