Example #1
0
void ArrayBeyondTest()
{
	Array<int, 5> a;
	a[4] = 5;
	cout << a[4] <<endl;
	
	//无法检测内存越界
	int* p1 = a.GetPtr();
	p1[5] = 6;
	cout << p1[5] <<endl;
	
	//无法使用p[i]
	Array<int, 5> *p2 = a.getptr();

	
	Array<Array<int, 10>,5> b;
	b[4][9] = 6;
	cout << b[4][9] <<endl;
	
	Array<TestStruct, 5> c;
	TestStruct t = {0};
	t.b[4] = 7;
	c[4] = t;
	cout << c[4].b[4] <<endl;
}
Example #2
0
void GLGSRender::Flip()
{
	if(m_read_buffer)
	{
		gcmBuffer* buffers = (gcmBuffer*)Memory.GetMemFromAddr(m_gcm_buffers_addr);
		u32 width = re(buffers[m_gcm_current_buffer].width);
		u32 height = re(buffers[m_gcm_current_buffer].height);
		u32 addr = GetAddress(re(buffers[m_gcm_current_buffer].offset), CELL_GCM_LOCATION_LOCAL);

		if(Memory.IsGoodAddr(addr))
		{
			//TODO
			//buffer rotating
			static Array<u8> pixels;
			pixels.SetCount(width * height * 4);
			u8* src = (u8*)Memory.VirtualToRealAddr(addr);

			for(u32 y=0; y<height; ++y)
			{
				memcpy(pixels + (height - y - 1) * width * 4, src + y * width * 4, width * 4);
			}

			glDrawPixels(width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels.GetPtr());
		}
	}
	else if(m_fbo.IsCreated())
	{
		m_fbo.Bind(GL_READ_FRAMEBUFFER);
		GLfbo::Bind(GL_DRAW_FRAMEBUFFER, 0);
		GLfbo::Blit(
			m_surface_clip_x, m_surface_clip_y, m_surface_clip_x + m_surface_clip_w, m_surface_clip_y + m_surface_clip_h,
			m_surface_clip_x, m_surface_clip_y, m_surface_clip_x + m_surface_clip_w, m_surface_clip_y + m_surface_clip_h,
			GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
		m_fbo.Bind();
	}

	for(uint i=0; i<m_post_draw_objs.GetCount(); ++i)
	{
		m_post_draw_objs[i].Draw();
	}

	m_frame->Flip();

	if(m_fbo.IsCreated())
		m_fbo.Bind();
}