src/render/opengles2/SDL_render_gles2.c
changeset 12156 e5a666405750
parent 12034 b3ae0dc577fd
child 12159 f7398cb0e3bf
equal deleted inserted replaced
12155:751cdc74d55c 12156:e5a666405750
  1532                          const void *vertexData, size_t dataSizeInBytes)
  1532                          const void *vertexData, size_t dataSizeInBytes)
  1533 {
  1533 {
  1534     GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
  1534     GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
  1535 
  1535 
  1536 #if !SDL_GLES2_USE_VBOS
  1536 #if !SDL_GLES2_USE_VBOS
  1537     data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, vertexData);
  1537     data->glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, vertexData);
  1538 #else
  1538 #else
  1539     if (!data->vertex_buffers[attr]) {
  1539     if (!data->vertex_buffers[attr]) {
  1540         data->glGenBuffers(1, &data->vertex_buffers[attr]);
  1540         data->glGenBuffers(1, &data->vertex_buffers[attr]);
  1541     }
  1541     }
  1542 
  1542 
  1547         data->vertex_buffer_size[attr] = dataSizeInBytes;
  1547         data->vertex_buffer_size[attr] = dataSizeInBytes;
  1548     } else {
  1548     } else {
  1549         data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData);
  1549         data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData);
  1550     }
  1550     }
  1551 
  1551 
  1552     data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, 0);
  1552     data->glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, 0);
  1553 #endif
  1553 #endif
  1554 
  1554 
  1555     return 0;
  1555     return 0;
  1556 }
  1556 }
  1557 
  1557 
  1855     data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  1855     data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  1856 
  1856 
  1857     return GL_CheckError("", renderer);
  1857     return GL_CheckError("", renderer);
  1858 }
  1858 }
  1859 
  1859 
       
  1860 #define PI 3.14159265f
       
  1861 
  1860 static int
  1862 static int
  1861 GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
  1863 GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
  1862                  const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
  1864                  const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
  1863 {
  1865 {
  1864     GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
  1866     GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
  1865     GLfloat vertices[8];
  1867     GLfloat vertices[8];
  1866     GLfloat texCoords[8];
  1868     GLfloat texCoords[8];
  1867     GLfloat translate[8];
  1869     GLfloat translate[8];
  1868     GLfloat fAngle[4];
  1870     GLfloat fAngle[8];
  1869     GLfloat tmp;
  1871     GLfloat tmp;
       
  1872     float radian_angle;
  1870 
  1873 
  1871     GLES2_ActivateRenderer(renderer);
  1874     GLES2_ActivateRenderer(renderer);
  1872 
  1875 
  1873     if (GLES2_SetupCopy(renderer, texture) < 0) {
  1876     if (GLES2_SetupCopy(renderer, texture) < 0) {
  1874         return -1;
  1877         return -1;
  1875     }
  1878     }
  1876 
  1879 
  1877     data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_CENTER);
  1880     data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_CENTER);
  1878     data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE);
  1881     data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE);
  1879     fAngle[0] = fAngle[1] = fAngle[2] = fAngle[3] = (GLfloat)(360.0f - angle);
  1882 
       
  1883     radian_angle = PI * (360.0f - angle) / 180.f;
       
  1884     fAngle[0] = fAngle[2] = fAngle[4] = fAngle[6] = (GLfloat)sin(radian_angle);
       
  1885     /* render expects cos value - 1 (see GLES2_VertexSrc_Default_) */
       
  1886     fAngle[1] = fAngle[3] = fAngle[5] = fAngle[7] = (GLfloat)cos(radian_angle) - 1.0f;
  1880     /* Calculate the center of rotation */
  1887     /* Calculate the center of rotation */
  1881     translate[0] = translate[2] = translate[4] = translate[6] = (center->x + dstrect->x);
  1888     translate[0] = translate[2] = translate[4] = translate[6] = (center->x + dstrect->x);
  1882     translate[1] = translate[3] = translate[5] = translate[7] = (center->y + dstrect->y);
  1889     translate[1] = translate[3] = translate[5] = translate[7] = (center->y + dstrect->y);
  1883 
  1890 
  1884     /* Emit the textured quad */
  1891     /* Emit the textured quad */
  1903 
  1910 
  1904     /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle);
  1911     /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle);
  1905     data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate);
  1912     data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate);
  1906     data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
  1913     data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
  1907 
  1914 
  1908     GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 4 * sizeof(GLfloat));
  1915     GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 8 * sizeof(GLfloat));
  1909     GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat));
  1916     GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat));
  1910     GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
  1917     GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
  1911 
  1918 
  1912     texCoords[0] = srcrect->x / (GLfloat)texture->w;
  1919     texCoords[0] = srcrect->x / (GLfloat)texture->w;
  1913     texCoords[1] = srcrect->y / (GLfloat)texture->h;
  1920     texCoords[1] = srcrect->y / (GLfloat)texture->h;