this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added sprite-stress-demo for testing future blit optimizations.

+156 -21
+12 -21
SDL_gpu/Android.mk
··· 4 4 5 5 LOCAL_MODULE := SDL2_gpu 6 6 7 - RENDERER_DIR := OpenGLES_1 8 - SOIL_DIR := externals/SOIL 9 - VASE_REND_DIR := externals/vase_rend 7 + SDL_GPU_DIR := ./ 8 + RENDERER_DIR := $(SDL_GPU_DIR)/OpenGL_common 9 + STB_IMAGE_DIR := $(SDL_GPU_DIR)/externals/stb_image 10 10 11 - LOCAL_CFLAGS := -I$(LOCAL_PATH)/../SDL/include -I$(LOCAL_PATH)/$(RENDERER_DIR) -I$(LOCAL_PATH)/$(SOIL_DIR) -I$(LOCAL_PATH)/$(VASE_REND_DIR) 11 + LOCAL_CFLAGS := -I$(LOCAL_PATH)/../SDL/include -I$(LOCAL_PATH)/$(SDL_GPU_DIR) -I$(LOCAL_PATH)/$(RENDERER_DIR) -I$(LOCAL_PATH)/$(STB_IMAGE_DIR) 12 12 13 + LOCAL_SRC_FILES := $(SDL_GPU_DIR)/SDL_gpu.c \ 14 + $(SDL_GPU_DIR)/SDL_gpu_Renderer.c \ 15 + $(SDL_GPU_DIR)/SDL_gpuShapes.c \ 16 + $(RENDERER_DIR)/SDL_gpu_OpenGL.c \ 17 + $(RENDERER_DIR)/SDL_gpuShapes_OpenGL.c \ 18 + $(STB_IMAGE_DIR)/stb_image.c \ 19 + $(STB_IMAGE_DIR)/stb_image_write.c 13 20 14 - BASE_FILES := $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/*.c)) 15 - RENDERER_FILES := $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(RENDERER_DIR)/*.c)) 16 21 17 - $(info Local: $(LOCAL_PATH)) 18 - $(info Soil: $(SOIL_DIR)) 19 - $(info Something: $(RENDERER_FILES)) 20 - 21 - LOCAL_SRC_FILES := $(BASE_FILES) \ 22 - $(RENDERER_DIR)/SDL_gpu_OpenGLES_1.c \ 23 - $(RENDERER_DIR)/SDL_gpuShapes_OpenGLES_1.c \ 24 - $(SOIL_DIR)/image_DXT.c \ 25 - $(SOIL_DIR)/image_helper.c \ 26 - $(SOIL_DIR)/SOIL.c \ 27 - $(SOIL_DIR)/stb_image.c \ 28 - $(SOIL_DIR)/stb_image_write.c 29 - 30 - 31 - LOCAL_CFLAGS += -DSDL_GPU_USE_OPENGLES_1 -DSTBI_FAILURE_USERMSG 22 + LOCAL_CFLAGS += -DSDL_GPU_USE_OPENGLES -DSTBI_FAILURE_USERMSG -O3 32 23 LOCAL_LDLIBS += -llog -lGLESv1_CM 33 24 34 25 LOCAL_SHARED_LIBRARIES := SDL2
+3
demos/CMakeLists.txt
··· 14 14 add_executable(sprite-demo sprite/main.c) 15 15 target_link_libraries (sprite-demo SDL_gpu) 16 16 17 + add_executable(sprite-stress-demo sprite-stress/main.c) 18 + target_link_libraries (sprite-stress-demo SDL_gpu) 19 + 17 20 add_executable(rotate-demo rotate/main.c) 18 21 target_link_libraries (rotate-demo SDL_gpu) 19 22
+141
demos/sprite-stress/main.c
··· 1 + #include "SDL.h" 2 + #include "SDL_gpu.h" 3 + 4 + void printRenderers(void) 5 + { 6 + const char* renderers[GPU_GetNumRegisteredRenderers()]; 7 + GPU_GetRegisteredRendererList(renderers); 8 + 9 + printf("Available renderers:\n"); 10 + int i; 11 + for(i = 0; i < GPU_GetNumRegisteredRenderers(); i++) 12 + { 13 + printf("%d) %s\n", i+1, renderers[i]); 14 + } 15 + } 16 + 17 + int main(int argc, char* argv[]) 18 + { 19 + printRenderers(); 20 + 21 + GPU_Target* screen = GPU_Init(NULL, 800, 600, 0); 22 + if(screen == NULL) 23 + return -1; 24 + 25 + printf("Using renderer: %s\n", GPU_GetCurrentRendererID()); 26 + 27 + GPU_Image* image = GPU_LoadImage("data/test3.png"); 28 + if(image == NULL) 29 + return -1; 30 + 31 + 32 + float dt = 0.010f; 33 + 34 + Uint32 startTime = SDL_GetTicks(); 35 + long frameCount = 0; 36 + 37 + int maxSprites = 50000; 38 + int numSprites = 101; 39 + 40 + float* x = (float*)malloc(sizeof(float)*maxSprites); 41 + float* y = (float*)malloc(sizeof(float)*maxSprites); 42 + float* velx = (float*)malloc(sizeof(float)*maxSprites); 43 + float* vely = (float*)malloc(sizeof(float)*maxSprites); 44 + int i; 45 + for(i = 0; i < maxSprites; i++) 46 + { 47 + x[i] = rand()%screen->w; 48 + y[i] = rand()%screen->h; 49 + velx[i] = 10 + rand()%screen->w/10; 50 + vely[i] = 10 + rand()%screen->h/10; 51 + } 52 + 53 + 54 + Uint8 done = 0; 55 + SDL_Event event; 56 + while(!done) 57 + { 58 + while(SDL_PollEvent(&event)) 59 + { 60 + if(event.type == SDL_QUIT) 61 + done = 1; 62 + else if(event.type == SDL_KEYDOWN) 63 + { 64 + if(event.key.keysym.sym == SDLK_ESCAPE) 65 + done = 1; 66 + else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS) 67 + { 68 + if(numSprites < maxSprites) 69 + numSprites += 100; 70 + GPU_LogError("Sprites: %d\n", numSprites); 71 + } 72 + else if(event.key.keysym.sym == SDLK_MINUS) 73 + { 74 + if(numSprites > 1) 75 + numSprites -= 100; 76 + if(numSprites < 1) 77 + numSprites = 1; 78 + GPU_LogError("Sprites: %d\n", numSprites); 79 + } 80 + } 81 + } 82 + 83 + for(i = 0; i < numSprites; i++) 84 + { 85 + x[i] += velx[i]*dt; 86 + y[i] += vely[i]*dt; 87 + if(x[i] < 0) 88 + { 89 + x[i] = 0; 90 + velx[i] = -velx[i]; 91 + } 92 + else if(x[i]> screen->w) 93 + { 94 + x[i] = screen->w; 95 + velx[i] = -velx[i]; 96 + } 97 + 98 + if(y[i] < 0) 99 + { 100 + y[i] = 0; 101 + vely[i] = -vely[i]; 102 + } 103 + else if(y[i]> screen->h) 104 + { 105 + y[i] = screen->h; 106 + vely[i] = -vely[i]; 107 + } 108 + } 109 + 110 + GPU_Clear(screen); 111 + 112 + for(i = 0; i < numSprites; i++) 113 + { 114 + GPU_Blit(image, NULL, screen, x[i], y[i]); 115 + } 116 + 117 + GPU_Flip(); 118 + 119 + frameCount++; 120 + if(SDL_GetTicks() - startTime > 5000) 121 + { 122 + printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); 123 + frameCount = 0; 124 + startTime = SDL_GetTicks(); 125 + } 126 + } 127 + 128 + printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); 129 + 130 + free(x); 131 + free(y); 132 + free(velx); 133 + free(vely); 134 + 135 + GPU_FreeImage(image); 136 + GPU_Quit(); 137 + 138 + return 0; 139 + } 140 + 141 +