comparison src/video/win32/SDL_d3drender.c @ 3536:0267b8b1595c

Added interfaces for batch drawing of points, lines and rects: SDL_DrawPoints() SDL_BlendPoints() SDL_BlendLines() SDL_DrawLines() SDL_FillRects() SDL_BlendRects() SDL_RenderPoints() SDL_RenderLines() SDL_RenderRects() Renamed SDL_RenderFill() to SDL_RenderRect()
author Sam Lantinga <slouken@libsdl.org>
date Wed, 09 Dec 2009 15:56:56 +0000
parents 444cb12cadb6
children 686f0e69cd37
comparison
equal deleted inserted replaced
3535:b403f790df65 3536:0267b8b1595c
64 const SDL_Rect * rect, int markDirty, 64 const SDL_Rect * rect, int markDirty,
65 void **pixels, int *pitch); 65 void **pixels, int *pitch);
66 static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); 66 static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
67 static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, 67 static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
68 int numrects, const SDL_Rect * rects); 68 int numrects, const SDL_Rect * rects);
69 static int D3D_RenderPoint(SDL_Renderer * renderer, int x, int y); 69 static int D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
70 static int D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, 70 int count);
71 int y2); 71 static int D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
72 static int D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); 72 int count);
73 static int D3D_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
74 int count);
73 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 75 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
74 const SDL_Rect * srcrect, const SDL_Rect * dstrect); 76 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
75 static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, 77 static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
76 Uint32 format, void * pixels, int pitch); 78 Uint32 format, void * pixels, int pitch);
77 static int D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, 79 static int D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
405 renderer->SetTextureScaleMode = D3D_SetTextureScaleMode; 407 renderer->SetTextureScaleMode = D3D_SetTextureScaleMode;
406 renderer->UpdateTexture = D3D_UpdateTexture; 408 renderer->UpdateTexture = D3D_UpdateTexture;
407 renderer->LockTexture = D3D_LockTexture; 409 renderer->LockTexture = D3D_LockTexture;
408 renderer->UnlockTexture = D3D_UnlockTexture; 410 renderer->UnlockTexture = D3D_UnlockTexture;
409 renderer->DirtyTexture = D3D_DirtyTexture; 411 renderer->DirtyTexture = D3D_DirtyTexture;
410 renderer->RenderPoint = D3D_RenderPoint; 412 renderer->RenderPoints = D3D_RenderPoints;
411 renderer->RenderLine = D3D_RenderLine; 413 renderer->RenderLines = D3D_RenderLines;
412 renderer->RenderFill = D3D_RenderFill; 414 renderer->RenderRects = D3D_RenderRects;
413 renderer->RenderCopy = D3D_RenderCopy; 415 renderer->RenderCopy = D3D_RenderCopy;
414 renderer->RenderReadPixels = D3D_RenderReadPixels; 416 renderer->RenderReadPixels = D3D_RenderReadPixels;
415 renderer->RenderWritePixels = D3D_RenderWritePixels; 417 renderer->RenderWritePixels = D3D_RenderWritePixels;
416 renderer->RenderPresent = D3D_RenderPresent; 418 renderer->RenderPresent = D3D_RenderPresent;
417 renderer->DestroyTexture = D3D_DestroyTexture; 419 renderer->DestroyTexture = D3D_DestroyTexture;
925 break; 927 break;
926 } 928 }
927 } 929 }
928 930
929 static int 931 static int
930 D3D_RenderPoint(SDL_Renderer * renderer, int x, int y) 932 D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
931 { 933 {
932 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; 934 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
933 DWORD color; 935 DWORD color;
934 Vertex vertices[1]; 936 Vertex *vertices;
937 int i;
935 HRESULT result; 938 HRESULT result;
936 939
937 if (data->beginScene) { 940 if (data->beginScene) {
938 IDirect3DDevice9_BeginScene(data->device); 941 IDirect3DDevice9_BeginScene(data->device);
939 data->beginScene = SDL_FALSE; 942 data->beginScene = SDL_FALSE;
940 } 943 }
941
942 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
943
944 vertices[0].x = (float) x;
945 vertices[0].y = (float) y;
946 vertices[0].z = 0.0f;
947 vertices[0].rhw = 1.0f;
948 vertices[0].color = color;
949 vertices[0].u = 0.0f;
950 vertices[0].v = 0.0f;
951 944
952 D3D_SetBlendMode(data, renderer->blendMode); 945 D3D_SetBlendMode(data, renderer->blendMode);
953 946
954 result = 947 result =
955 IDirect3DDevice9_SetTexture(data->device, 0, 948 IDirect3DDevice9_SetTexture(data->device, 0,
956 (IDirect3DBaseTexture9 *) 0); 949 (IDirect3DBaseTexture9 *) 0);
957 if (FAILED(result)) { 950 if (FAILED(result)) {
958 D3D_SetError("SetTexture()", result); 951 D3D_SetError("SetTexture()", result);
959 return -1; 952 return -1;
960 } 953 }
954
955 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
956
957 vertices = SDL_stack_alloc(Vertex, count);
958 for (i = 0; i < count; ++i) {
959 vertices[i].x = (float) points[i].x;
960 vertices[i].y = (float) points[i].y;
961 vertices[i].z = 0.0f;
962 vertices[i].rhw = 1.0f;
963 vertices[i].color = color;
964 vertices[i].u = 0.0f;
965 vertices[i].v = 0.0f;
966 }
961 result = 967 result =
962 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, 968 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, count,
963 vertices, sizeof(*vertices)); 969 vertices, sizeof(*vertices));
970 SDL_stack_free(vertices);
964 if (FAILED(result)) { 971 if (FAILED(result)) {
965 D3D_SetError("DrawPrimitiveUP()", result); 972 D3D_SetError("DrawPrimitiveUP()", result);
966 return -1; 973 return -1;
967 } 974 }
968 return 0; 975 return 0;
969 } 976 }
970 977
971 static int 978 static int
972 D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) 979 D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
973 { 980 {
974 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; 981 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
975 DWORD color; 982 DWORD color;
976 Vertex vertices[2]; 983 Vertex *vertices;
984 int i;
977 HRESULT result; 985 HRESULT result;
978 986
979 if (data->beginScene) { 987 if (data->beginScene) {
980 IDirect3DDevice9_BeginScene(data->device); 988 IDirect3DDevice9_BeginScene(data->device);
981 data->beginScene = SDL_FALSE; 989 data->beginScene = SDL_FALSE;
982 } 990 }
983
984 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
985
986 vertices[0].x = (float) x1;
987 vertices[0].y = (float) y1;
988 vertices[0].z = 0.0f;
989 vertices[0].rhw = 1.0f;
990 vertices[0].color = color;
991 vertices[0].u = 0.0f;
992 vertices[0].v = 0.0f;
993
994 vertices[1].x = (float) x2;
995 vertices[1].y = (float) y2;
996 vertices[1].z = 0.0f;
997 vertices[1].rhw = 1.0f;
998 vertices[1].color = color;
999 vertices[1].u = 0.0f;
1000 vertices[1].v = 0.0f;
1001 991
1002 D3D_SetBlendMode(data, renderer->blendMode); 992 D3D_SetBlendMode(data, renderer->blendMode);
1003 993
1004 result = 994 result =
1005 IDirect3DDevice9_SetTexture(data->device, 0, 995 IDirect3DDevice9_SetTexture(data->device, 0,
1006 (IDirect3DBaseTexture9 *) 0); 996 (IDirect3DBaseTexture9 *) 0);
1007 if (FAILED(result)) { 997 if (FAILED(result)) {
1008 D3D_SetError("SetTexture()", result); 998 D3D_SetError("SetTexture()", result);
1009 return -1; 999 return -1;
1010 } 1000 }
1001
1002 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
1003
1004 vertices = SDL_stack_alloc(Vertex, count);
1005 for (i = 0; i < count; ++i) {
1006 vertices[i].x = (float) points[i].x;
1007 vertices[i].y = (float) points[i].y;
1008 vertices[i].z = 0.0f;
1009 vertices[i].rhw = 1.0f;
1010 vertices[i].color = color;
1011 vertices[i].u = 0.0f;
1012 vertices[i].v = 0.0f;
1013 }
1011 result = 1014 result =
1012 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINELIST, 1, 1015 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, count,
1013 vertices, sizeof(*vertices)); 1016 vertices, sizeof(*vertices));
1017 SDL_stack_free(vertices);
1014 if (FAILED(result)) { 1018 if (FAILED(result)) {
1015 D3D_SetError("DrawPrimitiveUP()", result); 1019 D3D_SetError("DrawPrimitiveUP()", result);
1016 return -1; 1020 return -1;
1017 } 1021 }
1018 return 0; 1022 return 0;
1019 } 1023 }
1020 1024
1021 static int 1025 static int
1022 D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) 1026 D3D_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
1023 { 1027 {
1024 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; 1028 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
1029 DWORD color;
1030 int i;
1025 float minx, miny, maxx, maxy; 1031 float minx, miny, maxx, maxy;
1026 DWORD color;
1027 Vertex vertices[4]; 1032 Vertex vertices[4];
1028 HRESULT result; 1033 HRESULT result;
1029 1034
1030 if (data->beginScene) { 1035 if (data->beginScene) {
1031 IDirect3DDevice9_BeginScene(data->device); 1036 IDirect3DDevice9_BeginScene(data->device);
1032 data->beginScene = SDL_FALSE; 1037 data->beginScene = SDL_FALSE;
1033 } 1038 }
1034
1035 minx = (float) rect->x;
1036 miny = (float) rect->y;
1037 maxx = (float) rect->x + rect->w;
1038 maxy = (float) rect->y + rect->h;
1039
1040 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
1041
1042 vertices[0].x = minx;
1043 vertices[0].y = miny;
1044 vertices[0].z = 0.0f;
1045 vertices[0].rhw = 1.0f;
1046 vertices[0].color = color;
1047 vertices[0].u = 0.0f;
1048 vertices[0].v = 0.0f;
1049
1050 vertices[1].x = maxx;
1051 vertices[1].y = miny;
1052 vertices[1].z = 0.0f;
1053 vertices[1].rhw = 1.0f;
1054 vertices[1].color = color;
1055 vertices[1].u = 0.0f;
1056 vertices[1].v = 0.0f;
1057
1058 vertices[2].x = maxx;
1059 vertices[2].y = maxy;
1060 vertices[2].z = 0.0f;
1061 vertices[2].rhw = 1.0f;
1062 vertices[2].color = color;
1063 vertices[2].u = 0.0f;
1064 vertices[2].v = 0.0f;
1065
1066 vertices[3].x = minx;
1067 vertices[3].y = maxy;
1068 vertices[3].z = 0.0f;
1069 vertices[3].rhw = 1.0f;
1070 vertices[3].color = color;
1071 vertices[3].u = 0.0f;
1072 vertices[3].v = 0.0f;
1073 1039
1074 D3D_SetBlendMode(data, renderer->blendMode); 1040 D3D_SetBlendMode(data, renderer->blendMode);
1075 1041
1076 result = 1042 result =
1077 IDirect3DDevice9_SetTexture(data->device, 0, 1043 IDirect3DDevice9_SetTexture(data->device, 0,
1078 (IDirect3DBaseTexture9 *) 0); 1044 (IDirect3DBaseTexture9 *) 0);
1079 if (FAILED(result)) { 1045 if (FAILED(result)) {
1080 D3D_SetError("SetTexture()", result); 1046 D3D_SetError("SetTexture()", result);
1081 return -1; 1047 return -1;
1082 } 1048 }
1083 result = 1049
1084 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, 1050 color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
1085 vertices, sizeof(*vertices)); 1051
1086 if (FAILED(result)) { 1052 for (i = 0; i < count; ++i) {
1087 D3D_SetError("DrawPrimitiveUP()", result); 1053 const SDL_Rect *rect = rects[i];
1088 return -1; 1054
1055 minx = (float) rect->x;
1056 miny = (float) rect->y;
1057 maxx = (float) rect->x + rect->w;
1058 maxy = (float) rect->y + rect->h;
1059
1060 vertices[0].x = minx;
1061 vertices[0].y = miny;
1062 vertices[0].z = 0.0f;
1063 vertices[0].rhw = 1.0f;
1064 vertices[0].color = color;
1065 vertices[0].u = 0.0f;
1066 vertices[0].v = 0.0f;
1067
1068 vertices[1].x = maxx;
1069 vertices[1].y = miny;
1070 vertices[1].z = 0.0f;
1071 vertices[1].rhw = 1.0f;
1072 vertices[1].color = color;
1073 vertices[1].u = 0.0f;
1074 vertices[1].v = 0.0f;
1075
1076 vertices[2].x = maxx;
1077 vertices[2].y = maxy;
1078 vertices[2].z = 0.0f;
1079 vertices[2].rhw = 1.0f;
1080 vertices[2].color = color;
1081 vertices[2].u = 0.0f;
1082 vertices[2].v = 0.0f;
1083
1084 vertices[3].x = minx;
1085 vertices[3].y = maxy;
1086 vertices[3].z = 0.0f;
1087 vertices[3].rhw = 1.0f;
1088 vertices[3].color = color;
1089 vertices[3].u = 0.0f;
1090 vertices[3].v = 0.0f;
1091
1092 result =
1093 IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN,
1094 2, vertices, sizeof(*vertices));
1095 if (FAILED(result)) {
1096 D3D_SetError("DrawPrimitiveUP()", result);
1097 return -1;
1098 }
1089 } 1099 }
1090 return 0; 1100 return 0;
1091 } 1101 }
1092 1102
1093 static int 1103 static int