示例#1
0
void gs_texture_2d::InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd,
		const void **data)
{
	uint32_t rowSizeBytes  = width  * gs_get_format_bpp(format);
	uint32_t texSizeBytes  = height * rowSizeBytes / 8;
	size_t   textures      = type == GS_TEXTURE_2D ? 1 : 6;
	uint32_t actual_levels = levels;
	
	if (!actual_levels)
		actual_levels = gs_num_total_levels(width, height);

	rowSizeBytes /= 8;

	for (size_t i = 0; i < textures; i++) {
		uint32_t newRowSize = rowSizeBytes;
		uint32_t newTexSize = texSizeBytes;

		for (uint32_t j = 0; j < actual_levels; j++) {
			D3D11_SUBRESOURCE_DATA newSRD;
			newSRD.pSysMem          = *data;
			newSRD.SysMemPitch      = newRowSize; 
			newSRD.SysMemSlicePitch = newTexSize;
			srd.push_back(newSRD);

			newRowSize /= 2;
			newTexSize /= 4;
			data++;
		}
	}
}
static inline bool upload_texture_cube(struct gs_texture_cube *tex,
		const uint8_t **data)
{
	uint32_t row_size   = tex->size * gs_get_format_bpp(tex->base.format);
	uint32_t tex_size   = tex->size * row_size / 8;
	uint32_t num_levels = tex->base.levels;
	bool     compressed = gs_is_compressed_format(tex->base.format);
	GLenum   gl_type    = get_gl_format_type(tex->base.format);
	bool     success    = true;
	uint32_t i;

	if (!num_levels)
		num_levels = gs_get_total_levels(tex->size, tex->size);

	for (i = 0; i < 6; i++) {
		GLenum target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;

		if (!gl_bind_texture(target, tex->base.texture))
			success = false;

		if (!gl_init_face(target, gl_type, num_levels,
					tex->base.gl_format,
					tex->base.gl_internal_format,
					compressed, tex->size, tex->size,
					tex_size, &data))
			success = false;

		if (!gl_bind_texture(target, 0))
			success = false;

		if (data)
			data++;
	}

	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, num_levels);
	if (!gl_success("glTexParameteri"))
		success = false;

	return success;
}
示例#3
0
stagesurf_t device_create_stagesurface(device_t device, uint32_t width,
		uint32_t height, enum gs_color_format color_format)
{
	struct gs_stage_surface *surf;
	surf = bzalloc(sizeof(struct gs_stage_surface));
	surf->device             = device;
	surf->format             = color_format;
	surf->width              = width;
	surf->height             = height;
	surf->gl_format          = convert_gs_format(color_format);
	surf->gl_internal_format = convert_gs_internal_format(color_format);
	surf->gl_type            = get_gl_format_type(color_format);
	surf->bytes_per_pixel    = gs_get_format_bpp(color_format)/8;

	if (!create_pixel_pack_buffer(surf)) {
		blog(LOG_ERROR, "device_create_stagesurface (GL) failed");
		stagesurface_destroy(surf);
		return NULL;
	}

	return surf;
}