- Main Page
- Classes
- Files

- File List
- File Members

# flGraphics2d.c

Go to the documentation of this file.

    00001 #include "flGlobal.h"
    00002 #if FL_GRAPHICS_2D != 0
    00003 #include <pspgu.h>
    00004 #include <pspgum.h>
    00005
    00006 #if FL_MATH == 0
    00007 #include <math.h>
    00008 #endif
    00009
    00010 #if FL_INCLUDE_ALL_C == 0
    00011 #include "flGraphics2d.h"
    00012 #include "flGraphics.h"
    00013 #include "flMemory.h"
    00014
    00015 #if FL_COLOR != 0
    00016 #include "flColor.h"
    00017 #endif
    00018
    00019 #if FL_MATH != 0
    00020 #include "flMath.h"
    00021 #endif
    00022 #endif
    00023
    00024 void graphics2dDrawLineGrad(int inSourceX, int inSourceY, u32 inSourceColor, int inTargetX, int inTargetY, u32 inTargetColor) {
    00025      sceGuDisable(GU_DEPTH_TEST);
    00026      sceGuDisable(GU_TEXTURE_2D);
    00027
    00028      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) << 1);
    00029
    00030      tempVerts[0].vertColor = inSourceColor;
    00031      tempVerts[0].vertX = inSourceX;
    00032      tempVerts[0].vertY = inSourceY;
    00033      tempVerts[0].vertZ = 0;
    00034
    00035      tempVerts[1].vertColor = inTargetColor;
    00036      tempVerts[1].vertX = inTargetX;
    00037      tempVerts[1].vertY = inTargetY;
    00038      tempVerts[1].vertZ = 0;
    00039
    00040      sceGuDrawArray(GU_LINES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, tempVerts);
    00041
    00042      sceGuEnable(GU_TEXTURE_2D);
    00043      sceGuEnable(GU_DEPTH_TEST);
    00044 }
    00045
    00046 void graphics2dDrawTriangleGrad(int inX0, int inY0, u32 inColor0, int inX1, int inY1, u32 inColor1, int inX2, int inY2, u32 inColor2) {
    00047      sceGuDisable(GU_DEPTH_TEST);
    00048      sceGuDisable(GU_TEXTURE_2D);
    00049
    00050      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) << 2);
    00051
    00052      tempVerts[0].vertColor = inColor0;
    00053      tempVerts[0].vertX = inX0;
    00054      tempVerts[0].vertY = inY0;
    00055      tempVerts[0].vertZ = 0;
    00056
    00057      tempVerts[1].vertColor = inColor1;
    00058      tempVerts[1].vertX = inX1;
    00059      tempVerts[1].vertY = inY1;
    00060      tempVerts[1].vertZ = 0;
    00061
    00062      tempVerts[2].vertColor = inColor2;
    00063      tempVerts[2].vertX = inX2;
    00064      tempVerts[2].vertY = inY2;
    00065      tempVerts[2].vertZ = 0;
    00066
    00067      tempVerts[3].vertColor = inColor0;
    00068      tempVerts[3].vertX = inX0;
    00069      tempVerts[3].vertY = inY0;
    00070      tempVerts[3].vertZ = 0;
    00071
    00072      sceGuDrawArray(GU_LINE_STRIP, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 4, 0, tempVerts);
    00073
    00074      sceGuEnable(GU_TEXTURE_2D);
    00075      sceGuEnable(GU_DEPTH_TEST);
    00076 }
    00077
    00078 void graphics2dDrawTriangleFilledGrad(int inX0, int inY0, u32 inColor0, int inX1, int inY1, u32 inColor1, int inX2, int inY2, u32 inColor2) {
    00079      sceGuDisable(GU_DEPTH_TEST);
    00080      sceGuDisable(GU_TEXTURE_2D);
    00081      sceGuDisable(GU_CULL_FACE);
    00082
    00083      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) * 3);
    00084
    00085      tempVerts[0].vertColor = inColor0;
    00086      tempVerts[0].vertX = inX0;
    00087      tempVerts[0].vertY = inY0;
    00088      tempVerts[0].vertZ = 0;
    00089
    00090      tempVerts[1].vertColor = inColor1;
    00091      tempVerts[1].vertX = inX1;
    00092      tempVerts[1].vertY = inY1;
    00093      tempVerts[1].vertZ = 0;
    00094
    00095      tempVerts[2].vertColor = inColor2;
    00096      tempVerts[2].vertX = inX2;
    00097      tempVerts[2].vertY = inY2;
    00098      tempVerts[2].vertZ = 0;
    00099
    00100      sceGuDrawArray(GU_TRIANGLES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 3, 0, tempVerts);
    00101
    00102      sceGuEnable(GU_CULL_FACE);
    00103      sceGuEnable(GU_TEXTURE_2D);
    00104      sceGuEnable(GU_DEPTH_TEST);
    00105 }
    00106
    00107 void graphics2dDrawQuadGrad(int inX0, int inY0, u32 inColor0, int inX1, int inY1, u32 inColor1, int inX2, int inY2, u32 inColor2, int inX3, int inY3, u32 inColor3) {
    00108      sceGuDisable(GU_DEPTH_TEST);
    00109      sceGuDisable(GU_TEXTURE_2D);
    00110
    00111      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) * 5);
    00112
    00113      tempVerts[0].vertColor = inColor0;
    00114      tempVerts[0].vertX = inX0;
    00115      tempVerts[0].vertY = inY0;
    00116      tempVerts[0].vertZ = 0;
    00117
    00118      tempVerts[1].vertColor = inColor1;
    00119      tempVerts[1].vertX = inX1;
    00120      tempVerts[1].vertY = inY1;
    00121      tempVerts[1].vertZ = 0;
    00122
    00123      tempVerts[2].vertColor = inColor2;
    00124      tempVerts[2].vertX = inX2;
    00125      tempVerts[2].vertY = inY2;
    00126      tempVerts[2].vertZ = 0;
    00127
    00128      tempVerts[3].vertColor = inColor3;
    00129      tempVerts[3].vertX = inX3;
    00130      tempVerts[3].vertY = inY3;
    00131      tempVerts[3].vertZ = 0;
    00132
    00133      tempVerts[4].vertColor = inColor0;
    00134      tempVerts[4].vertX = inX0;
    00135      tempVerts[4].vertY = inY0;
    00136      tempVerts[4].vertZ = 0;
    00137
    00138      sceGuDrawArray(GU_LINE_STRIP, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 5, 0, tempVerts);
    00139
    00140      sceGuEnable(GU_TEXTURE_2D);
    00141      sceGuEnable(GU_DEPTH_TEST);
    00142 }
    00143
    00144 void graphics2dDrawQuadFilledGrad(int inX0, int inY0, u32 inColor0, int inX1, int inY1, u32 inColor1, int inX2, int inY2, u32 inColor2, int inX3, int inY3, u32 inColor3) {
    00145      sceGuDisable(GU_DEPTH_TEST);
    00146      sceGuDisable(GU_TEXTURE_2D);
    00147      sceGuDisable(GU_CULL_FACE);
    00148
    00149      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) << 2);
    00150
    00151      tempVerts[0].vertColor = inColor0;
    00152      tempVerts[0].vertX = inX0;
    00153      tempVerts[0].vertY = inY0;
    00154      tempVerts[0].vertZ = 0;
    00155
    00156      tempVerts[1].vertColor = inColor1;
    00157      tempVerts[1].vertX = inX1;
    00158      tempVerts[1].vertY = inY1;
    00159      tempVerts[1].vertZ = 0;
    00160
    00161      tempVerts[2].vertColor = inColor2;
    00162      tempVerts[2].vertX = inX2;
    00163      tempVerts[2].vertY = inY2;
    00164      tempVerts[2].vertZ = 0;
    00165
    00166      tempVerts[3].vertColor = inColor3;
    00167      tempVerts[3].vertX = inX3;
    00168      tempVerts[3].vertY = inY3;
    00169      tempVerts[3].vertZ = 0;
    00170
    00171      sceGuDrawArray(GU_TRIANGLE_FAN, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 4, 0, tempVerts);
    00172
    00173      sceGuEnable(GU_CULL_FACE);
    00174      sceGuEnable(GU_TEXTURE_2D);
    00175      sceGuEnable(GU_DEPTH_TEST);
    00176 }
    00177
    00178 void graphics2dDrawEllipseFilledGrad(int inX, int inY, int inWidth, int inHeight, u32 inInnerColor, u32 inOuterColor) {
    00179      sceGuDisable(GU_DEPTH_TEST);
    00180      sceGuDisable(GU_TEXTURE_2D);
    00181      sceGuDisable(GU_CULL_FACE);
    00182
    00183      inWidth = pos(inWidth);
    00184      inHeight = pos(inHeight);
    00185
    00186      float tempAvgRad = sqrtf((float)((inWidth * inWidth) + (inHeight * inHeight)));
    00187      u32 tempPoints = max(FL_GRAPHICS_2D_ELLIPSE_MINLINES, (int)(tempAvgRad * FL_GRAPHICS_2D_ELLIPSE_EDGESPERRAD));
    00188
    00189      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) * (tempPoints + 2));
    00190
    00191      inWidth >>= 1;
    00192      inHeight >>= 1;
    00193      inX += inWidth;
    00194      inY += inHeight;
    00195
    00196      tempVerts[0].vertColor = inInnerColor;
    00197      tempVerts[0].vertX = inX;
    00198      tempVerts[0].vertY = inY;
    00199      tempVerts[0].vertZ = 0;
    00200
    00201      u32 i;
    00202      float tempAngle = 0;
    00203      for(i = 0; i <= tempPoints; i++) {
    00204           tempAngle = i * ((2 * MATH_PI) / tempPoints);
    00205           tempVerts[i + 1].vertColor = inOuterColor;
    00206           #if FL_MATH != 0
    00207           tempVerts[i + 1].vertX = inX + (inWidth * mathSinf(tempAngle));
    00208           tempVerts[i + 1].vertY = inY + (inHeight * mathCosf(tempAngle));
    00209           #else
    00210           tempVerts[i + 1].vertX = inX + (inWidth * sinf(tempAngle));
    00211           tempVerts[i + 1].vertY = inY + (inHeight * cosf(tempAngle));
    00212           #endif
    00213           tempVerts[i + 1].vertZ = 0;
    00214      }
    00215
    00216      sceGuDrawArray(GU_TRIANGLE_FAN, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, (tempPoints + 2), 0, tempVerts);
    00217
    00218      sceGuEnable(GU_CULL_FACE);
    00219      sceGuEnable(GU_TEXTURE_2D);
    00220      sceGuEnable(GU_DEPTH_TEST);
    00221 }
    00222
    00223
    00224
    00225
    00226
    00227
    00228
    00229
    00230
    00231
    00232
    00233 void graphics2dDrawPoint(int inX, int inY, u32 inColor) {
    00234      sceGuDisable(GU_DEPTH_TEST);
    00235      sceGuDisable(GU_TEXTURE_2D);
    00236
    00237      sceGuColor(inColor);
    00238
    00239      vertVs* tempVerts = (vertVs*)sceGuGetMemory(sizeof(vertVs));
    00240
    00241      tempVerts[0].vertX = inX;
    00242      tempVerts[0].vertY = inY;
    00243      tempVerts[0].vertZ = 0;
    00244
    00245      sceGuDrawArray(GU_POINTS, GU_VERTEX_16BIT | GU_TRANSFORM_2D, 1, 0, tempVerts);
    00246
    00247      sceGuColor(0xFFFFFFFF);
    00248
    00249      sceGuEnable(GU_TEXTURE_2D);
    00250      sceGuEnable(GU_DEPTH_TEST);
    00251 }
    00252
    00253 void graphics2dDrawLine(int inSourceX, int inSourceY, int inTargetX, int inTargetY, u32 inColor) {
    00254      sceGuDisable(GU_DEPTH_TEST);
    00255      sceGuDisable(GU_TEXTURE_2D);
    00256
    00257      sceGuColor(inColor);
    00258
    00259      vertVs* tempVerts = (vertVs*)sceGuGetMemory(sizeof(vertVs) << 1);
    00260
    00261      tempVerts[0].vertX = inSourceX;
    00262      tempVerts[0].vertY = inSourceY;
    00263      tempVerts[0].vertZ = 0;
    00264
    00265      tempVerts[1].vertX = inTargetX;
    00266      tempVerts[1].vertY = inTargetY;
    00267      tempVerts[1].vertZ = 0;
    00268
    00269      sceGuDrawArray(GU_LINES, GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, tempVerts);
    00270
    00271      sceGuColor(0xFFFFFFFF);
    00272
    00273      sceGuEnable(GU_TEXTURE_2D);
    00274      sceGuEnable(GU_DEPTH_TEST);
    00275 }
    00276
    00277 void graphics2dDrawTriangle(int inX0, int inY0, int inX1, int inY1, int inX2, int inY2, u32 inColor) {
    00278      graphics2dDrawTriangleGrad(inX0, inY0, inColor, inX1, inY1, inColor, inX2, inY2, inColor);
    00279 }
    00280
    00281 void graphics2dDrawTriangleFilled(int inX0, int inY0, int inX1, int inY1, int inX2, int inY2, u32 inColor) {
    00282      graphics2dDrawTriangleFilledGrad(inX0, inY0, inColor, inX1, inY1, inColor, inX2, inY2, inColor);
    00283 }
    00284
    00285 void graphics2dDrawQuad(int inX0, int inY0, int inX1, int inY1, int inX2, int inY2, int inX3, int inY3, u32 inColor) {
    00286      graphics2dDrawQuadGrad(inX0, inY0, inColor, inX1, inY1, inColor, inX2, inY2, inColor, inX3, inY3, inColor);
    00287 }
    00288
    00289 void graphics2dDrawQuadFilled(int inX0, int inY0, int inX1, int inY1, int inX2, int inY2, int inX3, int inY3, u32 inColor) {
    00290      graphics2dDrawQuadFilledGrad(inX0, inY0, inColor, inX1, inY1, inColor, inX2, inY2, inColor, inX3, inY3, inColor);
    00291 }
    00292
    00293 void graphics2dDrawRect(int inX, int inY, int inWidth, int inHeight, u32 inColor) {
    00294      sceGuDisable(GU_DEPTH_TEST);
    00295      sceGuDisable(GU_TEXTURE_2D);
    00296
    00297      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) * 6);
    00298
    00299
    00300      tempVerts[0].vertColor = inColor;
    00301      tempVerts[0].vertX = inX;
    00302      tempVerts[0].vertY = inY;
    00303      tempVerts[0].vertZ = 0;
    00304
    00305      tempVerts[1].vertColor = inColor;
    00306      tempVerts[1].vertX = inX + inWidth - 1;
    00307      tempVerts[1].vertY = inY;
    00308      tempVerts[1].vertZ = 0;
    00309
    00310      tempVerts[2].vertColor = inColor;
    00311      tempVerts[2].vertX = inX + inWidth - 1;
    00312      tempVerts[2].vertY = inY + inHeight;
    00313      tempVerts[2].vertZ = 0;
    00314
    00315      tempVerts[3].vertColor = inColor;
    00316      tempVerts[3].vertX = inX + inWidth - 1;
    00317      tempVerts[3].vertY = inY + inHeight - 1;
    00318      tempVerts[3].vertZ = 0;
    00319
    00320      tempVerts[4].vertColor = inColor;
    00321      tempVerts[4].vertX = inX;
    00322      tempVerts[4].vertY = inY + inHeight - 1;
    00323      tempVerts[4].vertZ = 0;
    00324
    00325      tempVerts[5].vertColor = inColor;
    00326      tempVerts[5].vertX = inX;
    00327      tempVerts[5].vertY = inY;
    00328      tempVerts[5].vertZ = 0;
    00329
    00330      sceGuDrawArray(GU_LINE_STRIP, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 3, 0, tempVerts);
    00331      sceGuDrawArray(GU_LINE_STRIP, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 3, 0, &tempVerts[3]);
    00332
    00333      sceGuEnable(GU_TEXTURE_2D);
    00334      sceGuEnable(GU_DEPTH_TEST);
    00335 }
    00336
    00337 void graphics2dDrawRectFilled(int inX, int inY, int inWidth, int inHeight, u32 inColor) {
    00338      sceGuDisable(GU_DEPTH_TEST);
    00339      sceGuDisable(GU_TEXTURE_2D);
    00340
    00341      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) << 1);
    00342
    00343      tempVerts[0].vertColor = inColor;
    00344      tempVerts[0].vertX = inX;
    00345      tempVerts[0].vertY = inY;
    00346      tempVerts[0].vertZ = 0;
    00347
    00348      tempVerts[1].vertColor = inColor;
    00349      tempVerts[1].vertX = inX + inWidth;
    00350      tempVerts[1].vertY = inY + inHeight;
    00351      tempVerts[1].vertZ = 0;
    00352
    00353      sceGuDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, tempVerts);
    00354
    00355      sceGuEnable(GU_TEXTURE_2D);
    00356      sceGuEnable(GU_DEPTH_TEST);
    00357 }
    00358
    00359 void graphics2dDrawEllipse(int inX, int inY, int inWidth, int inHeight, u32 inColor) {
    00360      sceGuDisable(GU_DEPTH_TEST);
    00361      sceGuDisable(GU_TEXTURE_2D);
    00362
    00363      inWidth = pos(inWidth);
    00364      inHeight = pos(inHeight);
    00365
    00366      float tempAvgRad = sqrtf((float)((inWidth * inWidth) + (inHeight * inHeight)));
    00367      u32 tempPoints = max(FL_GRAPHICS_2D_ELLIPSE_MINLINES, (int)(tempAvgRad * FL_GRAPHICS_2D_ELLIPSE_EDGESPERRAD));
    00368
    00369      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) * (tempPoints + 1));
    00370
    00371      inWidth >>= 1;
    00372      inHeight >>= 1;
    00373      inX += inWidth;
    00374      inY += inHeight;
    00375
    00376      u32 i;
    00377      float tempAngle = 0;
    00378      for(i = 0; i <= tempPoints; i++) {
    00379           tempAngle = i * ((2 * MATH_PI) / tempPoints);
    00380           tempVerts[i].vertColor = inColor;
    00381           #if FL_MATH != 0
    00382           tempVerts[i].vertX = inX + (inWidth * mathSinf(tempAngle));
    00383           tempVerts[i].vertY = inY + (inHeight * mathCosf(tempAngle));
    00384           #else
    00385           tempVerts[i].vertX = inX + (inWidth * sinf(tempAngle));
    00386           tempVerts[i].vertY = inY + (inHeight * cosf(tempAngle));
    00387           #endif
    00388           tempVerts[i].vertZ = 0;
    00389      }
    00390
    00391      sceGuDrawArray(GU_LINE_STRIP, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, (tempPoints + 1), 0, tempVerts);
    00392
    00393      sceGuEnable(GU_TEXTURE_2D);
    00394      sceGuEnable(GU_DEPTH_TEST);
    00395 }
    00396
    00397 void graphics2dDrawEllipseFilled(int inX, int inY, int inWidth, int inHeight, u32 inColor) {
    00398      graphics2dDrawEllipseFilledGrad(inX, inY, inWidth, inHeight, inColor, inColor);
    00399 }
    00400
    00401
    00402
    00403
    00404
    00405 #if FL_COLOR != 0
    00406 void graphics2dDrawSpheroidShaded(int inX, int inY, int inWidth, int inHeight, u32 inColor, float inShadeAngle) { //bool inHShading) {
    00407      sceGuDisable(GU_DEPTH_TEST);
    00408      sceGuDisable(GU_TEXTURE_2D);
    00409      sceGuDisable(GU_CULL_FACE);
    00410
    00411      inWidth = pos(inWidth);
    00412      inHeight = pos(inHeight);
    00413      float tempAvgRad = sqrtf((float)((inWidth * inWidth) + (inHeight * inHeight)));
    00414      u32 tempPoints = max(FL_GRAPHICS_2D_ELLIPSE_MINLINES, (int)(tempAvgRad * FL_GRAPHICS_2D_ELLIPSE_EDGESPERRAD));
    00415
    00416      vertCVs* tempVerts = (vertCVs*)sceGuGetMemory(sizeof(vertCVs) * (tempPoints + 2));
    00417
    00418      inWidth >>= 1;
    00419      inHeight >>= 1;
    00420      inX += inWidth;
    00421      inY += inHeight;
    00422
    00423      tempVerts[0].vertColor = inColor;
    00424      tempVerts[0].vertX = inX;
    00425      tempVerts[0].vertY = inY;
    00426      tempVerts[0].vertZ = 0;
    00427
    00428      u32 i;
    00429      float tempAngle = 0.0f;;
    00430      float tempFract = 0.0f;
    00431      for(i = 0; i <= tempPoints; i++) {
    00432           tempAngle = i * ((2 * MATH_PI) / tempPoints);
    00433
    00434           #if FL_MATH != 0
    00435           tempVerts[i + 1].vertX = inX + (inWidth * mathSinf(tempAngle));
    00436           tempVerts[i + 1].vertY = inY + (inHeight * mathCosf(tempAngle));
    00437           tempFract = (tempAngle - inShadeAngle);
    00438           tempFract = 1.0f + (0.0f - mathCosf(tempFract));
    00439           #else
    00440           tempVerts[i + 1].vertX = inX + (inWidth * sinf(tempAngle));
    00441           tempVerts[i + 1].vertY = inY + (inHeight * cosf(tempAngle));
    00442           tempFract = (tempAngle - inShadeAngle);
    00443           tempFract = 1.0f + (0.0f - cosf(tempFract));
    00444           #endif
    00445
    00446           tempVerts[i + 1].vertColor = colorLumMult8888(inColor, tempFract);
    00447           //if(inHShading)
    00448           //     tempVerts[i + 1].vertColor = colorLumMult8888(inColor, ((float)((tempVerts[i + 1].vertX - inX) + inWidth) / (float)(inWidth << 1)));
    00449           //else
    00450           //     tempVerts[i + 1].vertColor = colorLumMult8888(inColor, ((float)((tempVerts[i + 1].vertY - inY) + inHeight) / (float)(inHeight << 1)));
    00451           tempVerts[i + 1].vertZ = 0;
    00452      }
    00453
    00454      sceGuDrawArray(GU_TRIANGLE_FAN, GU_COLOR_8888 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, (tempPoints + 2), 0, tempVerts);
    00455
    00456      sceGuEnable(GU_CULL_FACE);
    00457      sceGuEnable(GU_TEXTURE_2D);
    00458      sceGuEnable(GU_DEPTH_TEST);
    00459 }
    00460 #endif
    00461
    00462
    00463
    00464
    00465
    00466
    00467
    00468
    00469
    00470 #if FL_TEXTURE != 0
    00471 void graphics2dDrawTexture(int inX, int inY, int inWidth, int inHeight, Texture* inTex) {
    00472      if(!inTex) {
    00473           #if FL_DEBUG_WARNING != 0
    00474           debugWarning("Trying to draw NULL texture.");
    00475           #endif
    00476           return;
    00477      }
    00478
    00479      #if (FL_GRAPHICS_2D_USEDMA != 0) && (FL_TEXTURE_PRESERVENONALPHA != 0)
    00480      if(!inTex->texAlpha && (inTex->texPixelFormat == GU_PSM_8888)) {
    00481           if((inWidth == inTex->texWidth) && (inHeight == inTex->texHeight)) {
    00482                #if FL_MEMORY != 0
    00483                sceGuCopyImage(GU_PSM_8888, 0, 0, inTex->texDataWidth, inTex->texHeight, inTex->texStride, inTex->texData, inX, inY, SCREEN_PITCH, vmemAbsolutePtr(graphicsDrawBuffer));
    00484                #else
    00485                sceGuCopyImage(GU_PSM_8888, 0, 0, inTex->texDataWidth, inTex->texHeight, inTex->texStride, inTex->texData, inX, inY, SCREEN_PITCH, (void*)((unsigned int)graphicsDrawBuffer | 0x04000000));
    00486                #endif
    00487                return;
    00488           }
    00489      }
    00490      #endif
    00491
    00492      sceGuDisable(GU_DEPTH_TEST);
    00493
    00494      texBind(inTex);
    00495      sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
    00496
    00497      if(inWidth == inTex->texWidth) {
    00498           if(inHeight == inTex->texHeight)
    00499                sceGuTexFilter(GU_NEAREST, GU_NEAREST);
    00500           // The slicewidth calculation was taken from some benchmarks on ps2dev, maybe possible make a better calculation.
    00501           int tempSliceWidth = (inTex->texPixelFormat == GU_PSM_T4 ? 32 : 64);
    00502           int i;
    00503           for(i = 0; i < inTex->texWidth; i += tempSliceWidth) {
    00504                if((i + tempSliceWidth) > inTex->texWidth)
    00505                     tempSliceWidth = (inTex->texWidth - i);
    00506
    00507                vertTsVs* tempVerts = (vertTsVs*)sceGuGetMemory(sizeof(vertTsVs) << 1);
    00508
    00509                tempVerts[0].vertX = inX + i;
    00510                tempVerts[0].vertY = inY;
    00511                tempVerts[0].vertZ = 0;
    00512                tempVerts[0].vertU = i;
    00513                tempVerts[0].vertV = 0;
    00514
    00515                tempVerts[1].vertX = inX + i + tempSliceWidth;
    00516                tempVerts[1].vertY = inY + inHeight;
    00517                tempVerts[1].vertZ = 0;
    00518                tempVerts[1].vertU = i + tempSliceWidth;
    00519                tempVerts[1].vertV = inTex->texHeight;
    00520
    00521                sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, tempVerts);
    00522           }
    00523      } else {
    00524           sceGuTexFilter(GU_LINEAR, GU_LINEAR);
    00525
    00526           vertTsVs* tempVerts = (vertTsVs*)sceGuGetMemory(sizeof(vertTsVs) << 1);
    00527
    00528           tempVerts[0].vertX = inX;
    00529           tempVerts[0].vertY = inY;
    00530           tempVerts[0].vertZ = 0;
    00531           tempVerts[0].vertU = 0;
    00532           tempVerts[0].vertV = 0;
    00533
    00534           tempVerts[1].vertX = inX + inWidth;
    00535           tempVerts[1].vertY = inY + inHeight;
    00536           tempVerts[1].vertZ = 0;
    00537           tempVerts[1].vertU = inTex->texWidth;
    00538           tempVerts[1].vertV = inTex->texHeight;
    00539
    00540           sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, tempVerts);
    00541      }
    00542
    00543      sceGuEnable(GU_DEPTH_TEST);
    00544 }
    00545
    00546 void graphics2dDrawTextureSection(int inX, int inY, int inWidth, int inHeight, Texture* inTex, unsigned int inSrcX, unsigned int inSrcY, unsigned int inSrcWidth, unsigned int inSrcHeight) {
    00547      #if (FL_GRAPHICS_2D_USEDMA != 0) && (FL_TEXTURE_PRESERVENONALPHA != 0)
    00548      if(!inTex->texAlpha && (inTex->texPixelFormat == GU_PSM_8888)) {
    00549           if((inWidth == inSrcWidth) && (inHeight == inSrcHeight)) {
    00550                #if FL_MEMORY != 0
    00551                sceGuCopyImage(GU_PSM_8888, inSrcX, inSrcY, inSrcWidth, inSrcHeight, inTex->texStride, inTex->texData, inX, inY, SCREEN_PITCH, vmemAbsolutePtr(graphicsDrawBuffer));
    00552                #else
    00553                sceGuCopyImage(GU_PSM_8888, inSrcX, inSrcY, inSrcWidth, inSrcHeight, inTex->texStride, inTex->texData, inX, inY, SCREEN_PITCH, (void*)((unsigned int)graphicsDrawBuffer | 0x04000000));
    00554                #endif
    00555                return;
    00556           }
    00557      }
    00558      #endif
    00559
    00560      sceGuDisable(GU_DEPTH_TEST);
    00561
    00562      texBind(inTex);
    00563      sceGuTexEnvColor(0xFFFFFFFF);
    00564      sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
    00565      if((inWidth == inSrcWidth) && (inHeight == inSrcHeight))
    00566           sceGuTexFilter(GU_NEAREST, GU_NEAREST);
    00567      else
    00568           sceGuTexFilter(GU_LINEAR, GU_LINEAR);
    00569
    00570      vertTsVs* tempVerts = (vertTsVs*)sceGuGetMemory(sizeof(vertTsVs) << 1);
    00571
    00572      tempVerts[0].vertX = inX;
    00573      tempVerts[0].vertY = inY;
    00574      tempVerts[0].vertZ = 0;
    00575      tempVerts[0].vertU = inSrcX;
    00576      tempVerts[0].vertV = inSrcY;
    00577
    00578      tempVerts[1].vertX = inX + inWidth;
    00579      tempVerts[1].vertY = inY + inHeight;
    00580      tempVerts[1].vertZ = 0;
    00581      tempVerts[1].vertU = inSrcX + inSrcWidth;
    00582      tempVerts[1].vertV = inSrcY + inSrcHeight;
    00583
    00584      sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, tempVerts);
    00585
    00586      sceGuEnable(GU_DEPTH_TEST);
    00587 }
    00588 #endif
    00589
    00590 #endif