⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameswf_render_handler_xbox.cpp

📁 一个开源的Flash 播放器,可以在Windows/Linux 上运行
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#endif // 0	}	};	// end struct render_handler_xbox// bitmap_info_xbox implementationbitmap_info_xbox::bitmap_info_xbox(create_empty e){	// A null texture.  Needs to be initialized later.}bitmap_info_xbox::bitmap_info_xbox(image::rgb* im)// Image with no alpha.{	assert(im);	// Rescale.	m_original_width = im->m_width;	m_original_height = im->m_height;	int	w = 1; while (w < im->m_width) { w <<= 1; }	int	h = 1; while (h < im->m_height) { h <<= 1; }	image::rgb*	rescaled = image::create_rgb(w, h);	image::resample(rescaled, 0, 0, w - 1, h - 1,			im, 0, 0, (float) im->m_width, (float) im->m_height);	// Need to insert a dummy alpha byte in the image data, for	// D3DXLoadSurfaceFromMemory.	// @@ this sucks :(	int	pixel_count = w * h;	Uint8*	expanded_data = new Uint8[pixel_count * 4];	for (int y = 0; y < h; y++)	{		Uint8*	scanline = image::scanline(rescaled, y);		for (int x = 0; x < w; x++)		{			expanded_data[((y * w) + x) * 4 + 0] = scanline[x * 3 + 0];	// red			expanded_data[((y * w) + x) * 4 + 1] = scanline[x * 3 + 1];	// green			expanded_data[((y * w) + x) * 4 + 2] = scanline[x * 3 + 2];	// blue			expanded_data[((y * w) + x) * 4 + 3] = 255;	// alpha		}	}	// Create the texture.	s_d3d_textures.push_back(NULL);	m_texture_id = s_d3d_textures.size() - 1;	IDirect3DTexture8*	tex;	HRESULT	result = IDirect3DDevice8::CreateTexture(		w,		h,		0,		D3DUSAGE_BORDERSOURCE_TEXTURE,		D3DFMT_DXT1,		NULL,		&tex);	if (result != S_OK)	{		gameswf::log_error("error: can't create texture\n");		return;	}	s_d3d_textures.back() = tex;	IDirect3DSurface8*	surf = NULL;	result = tex->GetSurfaceLevel(0, &surf);	if (result != S_OK)	{		gameswf::log_error("error: can't get surface\n");		return;	}	assert(surf);	RECT	source_rect;	source_rect.left = 0;	source_rect.top = 0;	source_rect.right = w;	source_rect.bottom = h;	result = D3DXLoadSurfaceFromMemory(		surf,		NULL,		NULL,		expanded_data,		D3DFMT_LIN_A8B8G8R8,		w * 4,		NULL,		&source_rect,		D3DX_FILTER_POINT,		0);	delete [] expanded_data;	if (result != S_OK)	{		gameswf::log_error("error: can't load surface from memory, result = %d\n", result);		return;	}	if (surf) { surf->Release(); }#if 0	glEnable(GL_TEXTURE_2D);	glGenTextures(1, (GLuint*)&m_texture_id);	glBindTexture(GL_TEXTURE_2D, m_texture_id);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST /* LINEAR_MIPMAP_LINEAR */);	m_original_width = im->m_width;	m_original_height = im->m_height;	int	w = 1; while (w < im->m_width) { w <<= 1; }	int	h = 1; while (h < im->m_height) { h <<= 1; }	image::rgb*	rescaled = image::create_rgb(w, h);	image::resample(rescaled, 0, 0, w - 1, h - 1,			im, 0, 0, (float) im->m_width, (float) im->m_height);	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, rescaled->m_data);	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rescaled->m_width, rescaled->m_height, GL_RGB, GL_UNSIGNED_BYTE, rescaled->m_data);	delete [] rescaled;#endif // 0}bitmap_info_xbox::bitmap_info_xbox(image::rgba* im)// Version of the constructor that takes an image with alpha.{	assert(im);	m_original_width = im->m_width;	m_original_height = im->m_height;	int	w = 1; while (w < im->m_width) { w <<= 1; }	int	h = 1; while (h < im->m_height) { h <<= 1; }	// Create the texture.	s_d3d_textures.push_back(NULL);	m_texture_id = s_d3d_textures.size() - 1;	IDirect3DTexture8*	tex;	HRESULT	result = IDirect3DDevice8::CreateTexture(		w,		h,		0,		D3DUSAGE_BORDERSOURCE_TEXTURE,		D3DFMT_DXT1,		NULL,		&tex);	if (result != S_OK)	{		gameswf::log_error("error: can't create texture\n");		return;	}	s_d3d_textures.back() = tex;	IDirect3DSurface8*	surf = NULL;	result = tex->GetSurfaceLevel(0, &surf);	if (result != S_OK)	{		gameswf::log_error("error: can't get surface\n");		return;	}	assert(surf);	RECT	source_rect;	source_rect.left = 0;	source_rect.top = 0;	source_rect.right = w;	source_rect.bottom = h;	// Set the actual data.	if (w != im->m_width	    || h != im->m_height)	{		image::rgba*	rescaled = image::create_rgba(w, h);		image::resample(rescaled, 0, 0, w - 1, h - 1,				im, 0, 0, (float) im->m_width, (float) im->m_height);		result = D3DXLoadSurfaceFromMemory(			surf,			NULL,			NULL,			rescaled->m_data,			D3DFMT_LIN_A8B8G8R8,			rescaled->m_pitch,			NULL,			&source_rect,			D3DX_FILTER_POINT,			0);		if (result != S_OK)		{			gameswf::log_error("error: can't load surface from memory, result = %d\n", result);			return;		}//		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, rescaled->m_data);		delete [] rescaled;	}	else	{		// Use original image directly.		result = D3DXLoadSurfaceFromMemory(			surf,			NULL,			NULL,			im->m_data,			D3DFMT_LIN_A8B8G8R8,			im->m_pitch,			NULL,			&source_rect,			D3DX_FILTER_POINT,			0);		if (result != S_OK)		{			gameswf::log_error("error: can't load surface from memory, result = %d\n", result);			return;		}//		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, im->m_data);	}	if (surf) { surf->Release(); }#if 0	// Create the texture.	glEnable(GL_TEXTURE_2D);	glGenTextures(1, (GLuint*)&m_texture_id);	glBindTexture(GL_TEXTURE_2D, m_texture_id);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// GL_NEAREST ?	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST /* LINEAR_MIPMAP_LINEAR */);	m_original_width = im->m_width;	m_original_height = im->m_height;	int	w = 1; while (w < im->m_width) { w <<= 1; }	int	h = 1; while (h < im->m_height) { h <<= 1; }	if (w != im->m_width	    || h != im->m_height)	{		image::rgba*	rescaled = image::create_rgba(w, h);		image::resample(rescaled, 0, 0, w - 1, h - 1,				im, 0, 0, (float) im->m_width, (float) im->m_height);		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, rescaled->m_data);		delete [] rescaled;	}	else	{		// Use original image directly.		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, im->m_data);	}#endif // 0}void bitmap_info_xbox::set_alpha_image(int width, int height, Uint8* data)// Initialize this bitmap_info to an alpha image// containing the specified data (1 byte per texel).//// !! Munges *data in order to create mipmaps !!{	assert(m_texture_id == 0);	// only call this on an empty bitmap_info	assert(data);		// Create the texture.		m_original_width = width;	m_original_height = height;	#ifndef NDEBUG	// You must use power-of-two dimensions!!	int	w = 1; while (w < width) { w <<= 1; }	int	h = 1; while (h < height) { h <<= 1; }	assert(w == width);	assert(h == height);	#endif // not NDEBUG	s_d3d_textures.push_back(NULL);	m_texture_id = s_d3d_textures.size() - 1;	IDirect3DTexture8*	tex;	HRESULT	result = IDirect3DDevice8::CreateTexture(		width,		height,		0,		D3DUSAGE_BORDERSOURCE_TEXTURE,		D3DFMT_A8,		NULL,		&tex);	if (result != S_OK)	{		gameswf::log_error("error: can't create texture\n");		return;	}	s_d3d_textures.back() = tex;	IDirect3DSurface8*	surf = NULL;	result = tex->GetSurfaceLevel(0, &surf);	if (result != S_OK)	{		gameswf::log_error("error: can't get surface\n");		return;	}	assert(surf);	RECT	source_rect;	source_rect.left = 0;	source_rect.top = 0;	source_rect.right = width;	source_rect.bottom = height;	result = D3DXLoadSurfaceFromMemory(		surf,		NULL,		NULL,		data,		D3DFMT_LIN_A8,		width,		NULL,		&source_rect,		D3DX_FILTER_POINT,		0);	if (result != S_OK)	{		gameswf::log_error("error: can't load surface from memory, result = %d\n", result);		return;	}	if (surf) { surf->Release(); }//	glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);// 	// Build mips.// 	int	level = 1;// 	while (width > 1 || height > 1)// 	{// 		render_handler_xbox::make_next_miplevel(&width, &height, data);// 		glTexImage2D(GL_TEXTURE_2D, level, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);// 		level++;// 	}#if 0	glEnable(GL_TEXTURE_2D);	glGenTextures(1, (GLuint*)&m_texture_id);	glBindTexture(GL_TEXTURE_2D, m_texture_id);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// GL_NEAREST ?	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	m_original_width = width;	m_original_height = height;	#ifndef NDEBUG	// You must use power-of-two dimensions!!	int	w = 1; while (w < width) { w <<= 1; }	int	h = 1; while (h < height) { h <<= 1; }	assert(w == width);	assert(h == height);	#endif // not NDEBUG	glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);	// Build mips.	int	level = 1;	while (width > 1 || height > 1)	{		render_handler_xbox::make_next_miplevel(&width, &height, data);		glTexImage2D(GL_TEXTURE_2D, level, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);		level++;	}#endif // 0}gameswf::render_handler*	gameswf::create_render_handler_xbox()// Factory.{	return new render_handler_xbox;}#endif // _XBOX// Local Variables:// mode: C++// c-basic-offset: 8 // tab-width: 8// indent-tabs-mode: t// End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -