fixed icon, gamepad, mouse cursor
This commit is contained in:
		| @@ -1,19 +0,0 @@ | ||||
| SHADER(#version 100\n | ||||
|  | ||||
| precision highp float; | ||||
| precision mediump int; | ||||
|  | ||||
| attribute vec2 gpu_Vertex; | ||||
| attribute vec2 gpu_TexCoord; | ||||
| attribute mediump vec4 gpu_Color; | ||||
| uniform mat4 gpu_ModelViewProjectionMatrix; | ||||
|  | ||||
| varying mediump vec4 color; | ||||
| varying vec2 texCoord; | ||||
|  | ||||
| void main(void) | ||||
| { | ||||
| 	color = gpu_Color; | ||||
| 	texCoord = vec2(gpu_TexCoord); | ||||
| 	gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0); | ||||
| }) | ||||
							
								
								
									
										405
									
								
								src/system.c
									
									
									
									
									
								
							
							
						
						
									
										405
									
								
								src/system.c
									
									
									
									
									
								
							| @@ -13,7 +13,7 @@ | ||||
| #endif | ||||
|  | ||||
| #define STUDIO_UI_SCALE 4 | ||||
| #define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ABGR8888 | ||||
| #define STUDIO_PIXEL_FORMAT GPU_FORMAT_RGBA | ||||
| #define TEXTURE_SIZE (TIC80_FULLWIDTH) | ||||
| #define OFFSET_LEFT ((TIC80_FULLWIDTH-TIC80_WIDTH)/2) | ||||
| #define OFFSET_TOP ((TIC80_FULLHEIGHT-TIC80_HEIGHT)/2) | ||||
| @@ -28,7 +28,8 @@ static struct | ||||
| 	{ | ||||
| 		GPU_Target* screen; | ||||
| 		GPU_Image* texture; | ||||
| 		u32 crt_shader; | ||||
| 		u32 shader; | ||||
| 		GPU_ShaderBlock block; | ||||
| 		bool useShader; | ||||
| 	} gpu; | ||||
|  | ||||
| @@ -123,7 +124,7 @@ static void setWindowIcon() | ||||
|  | ||||
| 	SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(pixels, Size, Size, | ||||
| 		sizeof(s32) * BITS_IN_BYTE, Size * sizeof(s32), | ||||
| 		0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); | ||||
| 		0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); | ||||
|  | ||||
| 	SDL_SetWindowIcon(platform.window, surface); | ||||
| 	SDL_FreeSurface(surface); | ||||
| @@ -158,56 +159,53 @@ static void updateGamepadParts() | ||||
| 	platform.gamepad.part.y = (SDL_Point){rect.w - 2*tileSize, 0*tileSize + offset}; | ||||
| } | ||||
|  | ||||
| // static void transparentBlit(u32* out, s32 pitch) | ||||
| // { | ||||
| // 	const u8* in = platform.studio->tic->ram.vram.screen.data; | ||||
| // 	const u8* end = in + sizeof(platform.studio->tic->ram.vram.screen); | ||||
| // 	const u32* pal = tic_palette_blit(&platform.studio->tic->config.palette); | ||||
| // 	const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH); | ||||
|  | ||||
| // 	s32 col = 0; | ||||
|  | ||||
| // 	while(in != end) | ||||
| // 	{ | ||||
| // 		u8 low = *in & 0x0f; | ||||
| // 		u8 hi = (*in & 0xf0) >> TIC_PALETTE_BPP; | ||||
| // 		*out++ = low ? (*(pal + low) | 0xff000000) : 0; | ||||
| // 		*out++ = hi ? (*(pal + hi) | 0xff000000) : 0; | ||||
| // 		in++; | ||||
|  | ||||
| // 		col += BITS_IN_BYTE / TIC_PALETTE_BPP; | ||||
|  | ||||
| // 		if (col == TIC80_WIDTH) | ||||
| // 		{ | ||||
| // 			col = 0; | ||||
| // 			out += Delta; | ||||
| // 		} | ||||
| // 	} | ||||
| // } | ||||
|  | ||||
| static void initTouchGamepad() | ||||
| { | ||||
| 	if (!platform.gpu.screen) | ||||
| 		return; | ||||
| 	platform.studio->tic->api.map(platform.studio->tic, &platform.studio->tic->config.bank0.map, &platform.studio->tic->config.bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); | ||||
|  | ||||
| 	// platform.studio->tic->api.map(platform.studio->tic, &platform.studio->tic->config.bank0.map, &platform.studio->tic->config.bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1); | ||||
| 	if(!platform.gamepad.texture) | ||||
| 	{		 | ||||
| 		platform.gamepad.texture = GPU_CreateImage(TEXTURE_SIZE, TEXTURE_SIZE, STUDIO_PIXEL_FORMAT); | ||||
| 		GPU_SetAnchor(platform.gamepad.texture, 0, 0); | ||||
| 		GPU_SetImageFilter(platform.gamepad.texture, GPU_FILTER_NEAREST); | ||||
| 	} | ||||
|  | ||||
| 	// if(!platform.gamepad.texture) | ||||
| 	// { | ||||
| 	// 	platform.gamepad.texture = SDL_CreateTexture(platform.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, TEXTURE_SIZE, TEXTURE_SIZE); | ||||
| 	// 	SDL_SetTextureBlendMode(platform.gamepad.texture, SDL_BLENDMODE_BLEND); | ||||
| 	// } | ||||
| 	u32* data = SDL_malloc(TEXTURE_SIZE * TEXTURE_SIZE * sizeof(u32)); | ||||
|  | ||||
| 	// { | ||||
| 	// 	void* pixels = NULL; | ||||
| 	// 	s32 pitch = 0; | ||||
| 	if(data) | ||||
| 	{ | ||||
| 		u32* out = data; | ||||
|  | ||||
| 	// 	SDL_LockTexture(platform.gamepad.texture, NULL, &pixels, &pitch); | ||||
| 	// 	transparentBlit(pixels, pitch); | ||||
| 	// 	SDL_UnlockTexture(platform.gamepad.texture); | ||||
| 	// } | ||||
| 		const u8* in = platform.studio->tic->ram.vram.screen.data; | ||||
| 		const u8* end = in + sizeof(platform.studio->tic->ram.vram.screen); | ||||
| 		const u32* pal = tic_palette_blit(&platform.studio->tic->config.palette); | ||||
| 		const u32 Delta = ((TIC80_FULLWIDTH*sizeof(u32))/sizeof *out - TIC80_WIDTH); | ||||
|  | ||||
| 	// updateGamepadParts(); | ||||
| 		s32 col = 0; | ||||
|  | ||||
| 		while(in != end) | ||||
| 		{ | ||||
| 			u8 low = *in & 0x0f; | ||||
| 			u8 hi = (*in & 0xf0) >> TIC_PALETTE_BPP; | ||||
| 			*out++ = low ? *(pal + low) : 0; | ||||
| 			*out++ = hi ? *(pal + hi) : 0; | ||||
| 			in++; | ||||
|  | ||||
| 			col += BITS_IN_BYTE / TIC_PALETTE_BPP; | ||||
|  | ||||
| 			if (col == TIC80_WIDTH) | ||||
| 			{ | ||||
| 				col = 0; | ||||
| 				out += Delta; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		GPU_UpdateImageBytes(platform.gamepad.texture, NULL, (const u8*)data, TEXTURE_SIZE * sizeof(u32)); | ||||
|  | ||||
| 		SDL_free(data); | ||||
|  | ||||
| 		updateGamepadParts(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| static void calcTextureRect(SDL_Rect* rect) | ||||
| @@ -321,49 +319,49 @@ static void processKeyboard() | ||||
|  | ||||
| static bool checkTouch(const SDL_Rect* rect, s32* x, s32* y) | ||||
| { | ||||
| 	// s32 devices = SDL_GetNumTouchDevices(); | ||||
| 	// s32 width = 0, height = 0; | ||||
| 	// SDL_GetWindowSize(platform.window, &width, &height); | ||||
| 	s32 devices = SDL_GetNumTouchDevices(); | ||||
| 	s32 width = 0, height = 0; | ||||
| 	SDL_GetWindowSize(platform.window, &width, &height); | ||||
|  | ||||
| 	// for (s32 i = 0; i < devices; i++) | ||||
| 	// { | ||||
| 	// 	SDL_TouchID id = SDL_GetTouchDevice(i); | ||||
| 	for (s32 i = 0; i < devices; i++) | ||||
| 	{ | ||||
| 		SDL_TouchID id = SDL_GetTouchDevice(i); | ||||
|  | ||||
| 	// 	// very strange, but on Android id always == 0 | ||||
| 	// 	//if (id) | ||||
| 	// 	{ | ||||
| 	// 		s32 fingers = SDL_GetNumTouchFingers(id); | ||||
| 		// very strange, but on Android id always == 0 | ||||
| 		//if (id) | ||||
| 		{ | ||||
| 			s32 fingers = SDL_GetNumTouchFingers(id); | ||||
|  | ||||
| 	// 		if(fingers) | ||||
| 	// 		{ | ||||
| 	// 			platform.gamepad.counter = 0; | ||||
| 			if(fingers) | ||||
| 			{ | ||||
| 				platform.gamepad.counter = 0; | ||||
|  | ||||
| 	// 			if (!platform.gamepad.show) | ||||
| 	// 			{ | ||||
| 	// 				platform.gamepad.alpha = platform.studio->config()->theme.gamepad.touch.alpha; | ||||
| 	// 				SDL_SetTextureAlphaMod(platform.gamepad.texture, platform.gamepad.alpha); | ||||
| 	// 				platform.gamepad.show = true; | ||||
| 	// 				return false; | ||||
| 	// 			} | ||||
| 	// 		} | ||||
| 				if (!platform.gamepad.show) | ||||
| 				{ | ||||
| 					platform.gamepad.alpha = platform.studio->config()->theme.gamepad.touch.alpha; | ||||
| 					GPU_SetRGBA(platform.gamepad.texture, 0xff, 0xff, 0xff, platform.gamepad.alpha); | ||||
| 					platform.gamepad.show = true; | ||||
| 					return false; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 	// 		for (s32 f = 0; f < fingers; f++) | ||||
| 	// 		{ | ||||
| 	// 			SDL_Finger* finger = SDL_GetTouchFinger(id, f); | ||||
| 			for (s32 f = 0; f < fingers; f++) | ||||
| 			{ | ||||
| 				SDL_Finger* finger = SDL_GetTouchFinger(id, f); | ||||
|  | ||||
| 	// 			if (finger && finger->pressure > 0.0f) | ||||
| 	// 			{ | ||||
| 	// 				SDL_Point point = { (s32)(finger->x * width), (s32)(finger->y * height) }; | ||||
| 	// 				if (SDL_PointInRect(&point, rect)) | ||||
| 	// 				{ | ||||
| 	// 					*x = point.x; | ||||
| 	// 					*y = point.y; | ||||
| 	// 					return true; | ||||
| 	// 				} | ||||
| 	// 			} | ||||
| 	// 		} | ||||
| 	// 	} | ||||
| 	// } | ||||
| 				if (finger && finger->pressure > 0.0f) | ||||
| 				{ | ||||
| 					SDL_Point point = { (s32)(finger->x * width), (s32)(finger->y * height) }; | ||||
| 					if (SDL_PointInRect(&point, rect)) | ||||
| 					{ | ||||
| 						*x = point.x; | ||||
| 						*y = point.y; | ||||
| 						return true; | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return false; | ||||
| } | ||||
| @@ -675,104 +673,99 @@ static void blitSound() | ||||
|  | ||||
| static void renderGamepad() | ||||
| { | ||||
| 	// if(platform.gamepad.show || platform.gamepad.alpha); else return; | ||||
| 	if(platform.gamepad.show || platform.gamepad.alpha); else return; | ||||
|  | ||||
| 	// const s32 tileSize = platform.gamepad.part.size; | ||||
| 	// const SDL_Point axis = platform.gamepad.part.axis; | ||||
| 	// typedef struct { bool press; s32 x; s32 y;} Tile; | ||||
| 	// const Tile Tiles[] = | ||||
| 	// { | ||||
| 	// 	{platform.studio->tic->ram.input.gamepads.first.up, 	axis.x + 1*tileSize, axis.y + 0*tileSize}, | ||||
| 	// 	{platform.studio->tic->ram.input.gamepads.first.down, 	axis.x + 1*tileSize, axis.y + 2*tileSize}, | ||||
| 	// 	{platform.studio->tic->ram.input.gamepads.first.left, 	axis.x + 0*tileSize, axis.y + 1*tileSize}, | ||||
| 	// 	{platform.studio->tic->ram.input.gamepads.first.right, 	axis.x + 2*tileSize, axis.y + 1*tileSize}, | ||||
| 	const s32 tileSize = platform.gamepad.part.size; | ||||
| 	const SDL_Point axis = platform.gamepad.part.axis; | ||||
| 	typedef struct { bool press; s32 x; s32 y;} Tile; | ||||
| 	const Tile Tiles[] = | ||||
| 	{ | ||||
| 		{platform.studio->tic->ram.input.gamepads.first.up, 	axis.x + 1*tileSize, axis.y + 0*tileSize}, | ||||
| 		{platform.studio->tic->ram.input.gamepads.first.down, 	axis.x + 1*tileSize, axis.y + 2*tileSize}, | ||||
| 		{platform.studio->tic->ram.input.gamepads.first.left, 	axis.x + 0*tileSize, axis.y + 1*tileSize}, | ||||
| 		{platform.studio->tic->ram.input.gamepads.first.right, 	axis.x + 2*tileSize, axis.y + 1*tileSize}, | ||||
|  | ||||
| 	// 	{platform.studio->tic->ram.input.gamepads.first.a, 		platform.gamepad.part.a.x, platform.gamepad.part.a.y}, | ||||
| 	// 	{platform.studio->tic->ram.input.gamepads.first.b, 		platform.gamepad.part.b.x, platform.gamepad.part.b.y}, | ||||
| 	// 	{platform.studio->tic->ram.input.gamepads.first.x, 		platform.gamepad.part.x.x, platform.gamepad.part.x.y}, | ||||
| 	// 	{platform.studio->tic->ram.input.gamepads.first.y, 		platform.gamepad.part.y.x, platform.gamepad.part.y.y}, | ||||
| 	// }; | ||||
| 		{platform.studio->tic->ram.input.gamepads.first.a, 		platform.gamepad.part.a.x, platform.gamepad.part.a.y}, | ||||
| 		{platform.studio->tic->ram.input.gamepads.first.b, 		platform.gamepad.part.b.x, platform.gamepad.part.b.y}, | ||||
| 		{platform.studio->tic->ram.input.gamepads.first.x, 		platform.gamepad.part.x.x, platform.gamepad.part.x.y}, | ||||
| 		{platform.studio->tic->ram.input.gamepads.first.y, 		platform.gamepad.part.y.x, platform.gamepad.part.y.y}, | ||||
| 	}; | ||||
|  | ||||
| 	// enum {ButtonsCount = 8}; | ||||
| 	enum {ButtonsCount = 8}; | ||||
|  | ||||
| 	// for(s32 i = 0; i < COUNT_OF(Tiles); i++) | ||||
| 	// { | ||||
| 	// 	const Tile* tile = Tiles + i; | ||||
| 	// 	SDL_Rect src = {(tile->press ? ButtonsCount + i : i) * TIC_SPRITESIZE, 0, TIC_SPRITESIZE, TIC_SPRITESIZE}; | ||||
| 	// 	SDL_Rect dest = {tile->x, tile->y, tileSize, tileSize}; | ||||
| 	for(s32 i = 0; i < COUNT_OF(Tiles); i++) | ||||
| 	{ | ||||
| 		const Tile* tile = Tiles + i; | ||||
| 		GPU_Rect src = {(tile->press ? ButtonsCount + i : i) * TIC_SPRITESIZE, 0, TIC_SPRITESIZE, TIC_SPRITESIZE}; | ||||
| 		GPU_Rect dest = {tile->x, tile->y, tileSize, tileSize}; | ||||
|  | ||||
| 	// 	SDL_RenderCopy(platform.renderer, platform.gamepad.texture, &src, &dest); | ||||
| 	// } | ||||
| 		GPU_BlitScale(platform.gamepad.texture, &src, platform.gpu.screen, dest.x, dest.y, | ||||
| 			(float)dest.w / TIC_SPRITESIZE, (float)dest.h / TIC_SPRITESIZE); | ||||
| 	} | ||||
|  | ||||
| 	// if(!platform.gamepad.show && platform.gamepad.alpha) | ||||
| 	// { | ||||
| 	// 	enum {Step = 3}; | ||||
| 	if(!platform.gamepad.show && platform.gamepad.alpha) | ||||
| 	{ | ||||
| 		enum {Step = 3}; | ||||
|  | ||||
| 	// 	if(platform.gamepad.alpha - Step >= 0) platform.gamepad.alpha -= Step; | ||||
| 	// 	else platform.gamepad.alpha = 0; | ||||
| 		if(platform.gamepad.alpha - Step >= 0) platform.gamepad.alpha -= Step; | ||||
| 		else platform.gamepad.alpha = 0; | ||||
|  | ||||
| 	// 	SDL_SetTextureAlphaMod(platform.gamepad.texture, platform.gamepad.alpha); | ||||
| 	// } | ||||
| 		GPU_SetRGBA(platform.gamepad.texture, 0xff, 0xff, 0xff, platform.gamepad.alpha); | ||||
| 	} | ||||
|  | ||||
| 	// platform.gamepad.counter = platform.gamepad.touch.data ? 0 : platform.gamepad.counter+1; | ||||
| 	platform.gamepad.counter = platform.gamepad.touch.data ? 0 : platform.gamepad.counter+1; | ||||
|  | ||||
| 	// // wait 5 seconds and hide touch gamepad | ||||
| 	// if(platform.gamepad.counter >= 5 * TIC_FRAMERATE) | ||||
| 	// 	platform.gamepad.show = false; | ||||
| 	// wait 5 seconds and hide touch gamepad | ||||
| 	if(platform.gamepad.counter >= 5 * TIC_FRAMERATE) | ||||
| 		platform.gamepad.show = false; | ||||
| } | ||||
|  | ||||
| static void blitCursor(const u8* in) | ||||
| { | ||||
| 	// if(!platform.mouse.texture) | ||||
| 	// { | ||||
| 	// 	platform.mouse.texture = SDL_CreateTexture(platform.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, TIC_SPRITESIZE, TIC_SPRITESIZE); | ||||
| 	// 	SDL_SetTextureBlendMode(platform.mouse.texture, SDL_BLENDMODE_BLEND); | ||||
| 	// } | ||||
| 	if(!platform.mouse.texture) | ||||
| 	{ | ||||
| 		platform.mouse.texture = GPU_CreateImage(TIC_SPRITESIZE, TIC_SPRITESIZE, STUDIO_PIXEL_FORMAT); | ||||
| 		GPU_SetAnchor(platform.mouse.texture, 0, 0); | ||||
| 		GPU_SetImageFilter(platform.mouse.texture, GPU_FILTER_NEAREST); | ||||
| 	} | ||||
|  | ||||
| 	// if(platform.mouse.src != in) | ||||
| 	// { | ||||
| 	// 	platform.mouse.src = in; | ||||
| 	if(platform.mouse.src != in) | ||||
| 	{ | ||||
| 		platform.mouse.src = in; | ||||
|  | ||||
| 	// 	void* pixels = NULL; | ||||
| 	// 	s32 pitch = 0; | ||||
| 	// 	SDL_LockTexture(platform.mouse.texture, NULL, &pixels, &pitch); | ||||
| 		const u8* end = in + sizeof(tic_tile); | ||||
| 		const u32* pal = tic_palette_blit(&platform.studio->tic->ram.vram.palette); | ||||
| 		static u32 data[TIC_SPRITESIZE*TIC_SPRITESIZE]; | ||||
| 		u32* out = data; | ||||
|  | ||||
| 	// 	{ | ||||
| 	// 		const u8* end = in + sizeof(tic_tile); | ||||
| 	// 		const u32* pal = tic_palette_blit(&platform.studio->tic->ram.vram.palette); | ||||
| 	// 		u32* out = pixels; | ||||
| 		while(in != end) | ||||
| 		{ | ||||
| 			u8 low = *in & 0x0f; | ||||
| 			u8 hi = (*in & 0xf0) >> TIC_PALETTE_BPP; | ||||
| 			*out++ = low ? *(pal + low) : 0; | ||||
| 			*out++ = hi ? *(pal + hi) : 0; | ||||
|  | ||||
| 	// 		while(in != end) | ||||
| 	// 		{ | ||||
| 	// 			u8 low = *in & 0x0f; | ||||
| 	// 			u8 hi = (*in & 0xf0) >> TIC_PALETTE_BPP; | ||||
| 	// 			*out++ = low ? (*(pal + low) | 0xff000000) : 0; | ||||
| 	// 			*out++ = hi ? (*(pal + hi) | 0xff000000) : 0; | ||||
| 			in++; | ||||
| 		} | ||||
|  | ||||
| 	// 			in++; | ||||
| 	// 		} | ||||
| 	// 	} | ||||
| 		GPU_UpdateImageBytes(platform.mouse.texture, NULL, (const u8*)data, TIC_SPRITESIZE * sizeof(u32)); | ||||
| 	} | ||||
|  | ||||
| 	// 	SDL_UnlockTexture(platform.mouse.texture); | ||||
| 	// } | ||||
| 	SDL_Rect rect = {0, 0, 0, 0}; | ||||
| 	calcTextureRect(&rect); | ||||
| 	s32 scale = rect.w / TIC80_WIDTH; | ||||
|  | ||||
| 	// SDL_Rect rect = {0, 0, 0, 0}; | ||||
| 	// calcTextureRect(&rect); | ||||
| 	// s32 scale = rect.w / TIC80_WIDTH; | ||||
| 	s32 mx, my; | ||||
| 	SDL_GetMouseState(&mx, &my); | ||||
|  | ||||
| 	// SDL_Rect src = {0, 0, TIC_SPRITESIZE, TIC_SPRITESIZE}; | ||||
| 	// SDL_Rect dst = {0, 0, TIC_SPRITESIZE * scale, TIC_SPRITESIZE * scale}; | ||||
| 	if(platform.studio->config()->theme.cursor.pixelPerfect) | ||||
| 	{ | ||||
| 		mx -= (mx - rect.x) % scale; | ||||
| 		my -= (my - rect.y) % scale; | ||||
| 	} | ||||
|  | ||||
| 	// SDL_GetMouseState(&dst.x, &dst.y); | ||||
|  | ||||
| 	// if(platform.studio->config()->theme.cursor.pixelPerfect) | ||||
| 	// { | ||||
| 	// 	dst.x -= (dst.x - rect.x) % scale; | ||||
| 	// 	dst.y -= (dst.y - rect.y) % scale; | ||||
| 	// } | ||||
|  | ||||
| 	// if(SDL_GetWindowFlags(platform.window) & SDL_WINDOW_MOUSE_FOCUS) | ||||
| 	// 	SDL_RenderCopy(platform.renderer, platform.mouse.texture, &src, &dst); | ||||
| 	if(SDL_GetWindowFlags(platform.window) & SDL_WINDOW_MOUSE_FOCUS) | ||||
| 		GPU_BlitScale(platform.mouse.texture, NULL, platform.gpu.screen, mx, my, (float)scale, (float)scale); | ||||
| } | ||||
|  | ||||
| static void renderCursor() | ||||
| @@ -891,7 +884,6 @@ static u64 getPerformanceFrequency() | ||||
| static void goFullscreen() | ||||
| { | ||||
| 	GPU_SetFullscreen(GPU_GetFullscreen() ? false : true, true); | ||||
| 	// SDL_SetWindowFullscreen(platform.window, SDL_GetWindowFlags(platform.window) & SDL_WINDOW_FULLSCREEN_DESKTOP ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); | ||||
| } | ||||
|  | ||||
| static void showMessageBox(const char* title, const char* message) | ||||
| @@ -994,38 +986,42 @@ static void gpuTick() | ||||
|  | ||||
| 	{ | ||||
| 		platform.studio->tick(); | ||||
| 		renderCursor(); | ||||
| 		renderGamepad(); | ||||
|  | ||||
| 		GPU_UpdateImageBytes(platform.gpu.texture, NULL, (const u8*)tic->screen, TIC80_FULLWIDTH * sizeof(u32)); | ||||
|  | ||||
| 		{ | ||||
|  | ||||
| 			if(platform.gpu.useShader) | ||||
| 			{ | ||||
| 				SDL_Rect rect = {0, 0, 0, 0}; | ||||
| 				calcTextureRect(&rect); | ||||
|  | ||||
| 				GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.crt_shader, "trg_x"), rect.x); | ||||
| 				GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.crt_shader, "trg_y"), rect.y); | ||||
| 				GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.crt_shader, "trg_w"), rect.w); | ||||
| 				GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.crt_shader, "trg_h"), rect.h); | ||||
| 				GPU_ActivateShaderProgram(platform.gpu.shader, &platform.gpu.block); | ||||
|  | ||||
| 				GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.shader, "trg_x"), rect.x); | ||||
| 				GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.shader, "trg_y"), rect.y); | ||||
| 				GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.shader, "trg_w"), rect.w); | ||||
| 				GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.shader, "trg_h"), rect.h); | ||||
|  | ||||
| 				{ | ||||
| 					s32 w, h; | ||||
| 					SDL_GetWindowSize(platform.window, &w, &h); | ||||
| 					GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.crt_shader, "scr_w"), w); | ||||
| 					GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.crt_shader, "scr_h"), h); | ||||
| 					GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.shader, "scr_w"), w); | ||||
| 					GPU_SetUniformf(GPU_GetUniformLocation(platform.gpu.shader, "scr_h"), h); | ||||
| 				} | ||||
|  | ||||
| 				GPU_BlitScale(platform.gpu.texture, NULL, platform.gpu.screen, rect.x, rect.y, (float)rect.w / TIC80_FULLWIDTH, (float)rect.h / TIC80_FULLHEIGHT); | ||||
| 				GPU_BlitScale(platform.gpu.texture, NULL, platform.gpu.screen, rect.x, rect.y,  | ||||
| 					(float)rect.w / TIC80_FULLWIDTH, (float)rect.h / TIC80_FULLHEIGHT); | ||||
|  | ||||
| 				GPU_ActivateShaderProgram(0, NULL); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				blitGpuTexture(platform.gpu.screen, platform.gpu.texture); | ||||
| 			} | ||||
|  | ||||
| 		} | ||||
|  | ||||
| 		renderCursor(); | ||||
| 		renderGamepad(); | ||||
| 	} | ||||
|  | ||||
| 	GPU_Flip(platform.gpu.screen); | ||||
| @@ -1083,40 +1079,53 @@ static void emsGpuTick() | ||||
|  | ||||
| #define SHADER(...) #__VA_ARGS__ | ||||
|  | ||||
| u32 load_shader_program() | ||||
| static void loadCrtShader() | ||||
| { | ||||
| 	static const char* VertexShader =  | ||||
| 		#include "ext/shader/common.vert" | ||||
| 	; | ||||
| 	static const char* VertexShader = "#version 100\n\ | ||||
| 		precision highp float;\n\ | ||||
| 		precision mediump int;\n\ | ||||
| 		attribute vec2 gpu_Vertex;\n\ | ||||
| 		attribute vec2 gpu_TexCoord;\n\ | ||||
| 		attribute mediump vec4 gpu_Color;\n\ | ||||
| 		uniform mat4 gpu_ModelViewProjectionMatrix;\n\ | ||||
| 		varying mediump vec4 color;\n\ | ||||
| 		varying vec2 texCoord;\n\ | ||||
| 		void main(void)\n\ | ||||
| 		{\n\ | ||||
| 			color = gpu_Color;\n\ | ||||
| 			texCoord = vec2(gpu_TexCoord);\n\ | ||||
| 			gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\ | ||||
| 		}"; | ||||
|  | ||||
| 	u32 v = GPU_CompileShader(GPU_VERTEX_SHADER, VertexShader); | ||||
| 	u32 vertex = GPU_CompileShader(GPU_VERTEX_SHADER, VertexShader); | ||||
| 	 | ||||
| 	if(!v) | ||||
| 	if(!vertex) | ||||
| 	{ | ||||
| 		GPU_LogError("Failed to load vertex shader: %s\n", GPU_GetShaderMessage()); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	static const char* PixelShader =  | ||||
| 		#include "ext/shader/crt-lottes.frag" | ||||
| 	; | ||||
|  | ||||
| 	u32 f = GPU_CompileShader(GPU_PIXEL_SHADER, PixelShader); | ||||
| 	u32 fragment = GPU_CompileShader(GPU_PIXEL_SHADER, PixelShader); | ||||
| 	 | ||||
| 	if(!f) | ||||
| 	if(!fragment) | ||||
| 	{ | ||||
| 		GPU_LogError("Failed to load fragment shader: %s\n", GPU_GetShaderMessage()); | ||||
| 		return; | ||||
| 	} | ||||
| 	 | ||||
| 	u32 p = GPU_LinkShaders(v, f); | ||||
| 	platform.gpu.shader = GPU_LinkShaders(vertex, fragment); | ||||
| 	 | ||||
| 	if(!p) | ||||
| 	if(platform.gpu.shader) | ||||
| 	{ | ||||
| 		platform.gpu.block = GPU_LoadShaderBlock(platform.gpu.shader, "gpu_Vertex", "gpu_TexCoord", "gpu_Color", "gpu_ModelViewProjectionMatrix"); | ||||
| 		GPU_ActivateShaderProgram(platform.gpu.shader, &platform.gpu.block); | ||||
| 	} | ||||
| 	else | ||||
| 		GPU_LogError("Failed to link shader program: %s\n", GPU_GetShaderMessage()); | ||||
| 		return p; | ||||
| 	} | ||||
| 	 | ||||
| 	{ | ||||
| 		GPU_ShaderBlock block = GPU_LoadShaderBlock(p, "gpu_Vertex", "gpu_TexCoord", "gpu_Color", "gpu_ModelViewProjectionMatrix"); | ||||
| 		GPU_ActivateShaderProgram(p, &block); | ||||
|  | ||||
| 		return p; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| static s32 start(s32 argc, char **argv, const char* folder) | ||||
| @@ -1129,8 +1138,6 @@ static s32 start(s32 argc, char **argv, const char* folder) | ||||
|  | ||||
| 	platform.studio = studioInit(argc, argv, platform.audio.spec.freq, folder, &systemInterface); | ||||
|  | ||||
| 	initTouchGamepad(); | ||||
|  | ||||
| 	enum{Width = TIC80_FULLWIDTH * STUDIO_UI_SCALE, Height = TIC80_FULLHEIGHT * STUDIO_UI_SCALE}; | ||||
|  | ||||
| 	platform.window = SDL_CreateWindow( TIC_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, | ||||
| @@ -1142,14 +1149,16 @@ static s32 start(s32 argc, char **argv, const char* folder) | ||||
|  | ||||
| 	platform.gpu.screen = GPU_Init(Width, Height, GPU_INIT_DISABLE_VSYNC); | ||||
|  | ||||
| 	platform.gpu.texture = GPU_CreateImage(TIC80_FULLWIDTH, TIC80_FULLHEIGHT, GPU_FORMAT_RGBA); | ||||
| 	initTouchGamepad(); | ||||
|  | ||||
| 	platform.gpu.texture = GPU_CreateImage(TIC80_FULLWIDTH, TIC80_FULLHEIGHT, STUDIO_PIXEL_FORMAT); | ||||
| 	GPU_SetAnchor(platform.gpu.texture, 0, 0); | ||||
| 	GPU_SetImageFilter(platform.gpu.texture, GPU_FILTER_NEAREST); | ||||
|  | ||||
| 	platform.gpu.useShader = true; | ||||
|  | ||||
| 	if(platform.gpu.useShader) | ||||
| 		platform.gpu.crt_shader = load_shader_program(); | ||||
| 		loadCrtShader(); | ||||
|  | ||||
| #if defined(__EMSCRIPTEN__) | ||||
|  | ||||
| @@ -1187,9 +1196,12 @@ static s32 start(s32 argc, char **argv, const char* folder) | ||||
|  | ||||
| 	closeNet(platform.net); | ||||
|  | ||||
| 	SDL_CloseAudioDevice(platform.audio.device); | ||||
| 	if(platform.audio.cvt.buf) | ||||
| 		SDL_free(platform.audio.cvt.buf); | ||||
|  | ||||
| 	if(platform.gpu.shader) | ||||
| 		GPU_FreeShaderProgram(platform.gpu.shader); | ||||
|  | ||||
| 	GPU_FreeShaderProgram(platform.gpu.crt_shader); | ||||
| 	GPU_FreeImage(platform.gpu.texture); | ||||
|  | ||||
| 	if(platform.gamepad.texture) | ||||
| @@ -1198,6 +1210,9 @@ static s32 start(s32 argc, char **argv, const char* folder) | ||||
| 	if(platform.mouse.texture) | ||||
| 		GPU_FreeImage(platform.mouse.texture); | ||||
|  | ||||
| 	SDL_DestroyWindow(platform.window); | ||||
| 	SDL_CloseAudioDevice(platform.audio.device); | ||||
|  | ||||
| 	GPU_Quit(); | ||||
|  | ||||
| 	return 0; | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
| #include <time.h> | ||||
| #include <SDL.h> | ||||
|  | ||||
| #define STUDIO_UI_SCALE 3 | ||||
| #define STUDIO_UI_SCALE 2 | ||||
| #define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ABGR8888 | ||||
| #define TEXTURE_SIZE (TIC80_FULLWIDTH) | ||||
| #define OFFSET_LEFT ((TIC80_FULLWIDTH-TIC80_WIDTH)/2) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 BADIM-PC\Vadim
					BADIM-PC\Vadim