Texture2D_D3D11_Base::Texture2D_D3D11_Base(ID3D11Device* device, ID3D11DeviceContext* context, D3D11_USAGE usage, int width, int height, PixelFormat format, void const* data)
{
    m_context = context;
    m_context->AddRef();

    D3D11_TEXTURE2D_DESC desc = {0};
    desc.Width = (UINT)width;
    desc.Height = (UINT)height;
    desc.MipLevels = desc.ArraySize = 1;
    desc.Format = cFormatMap[int(format)];
    desc.SampleDesc.Count = 1;
    desc.Usage = usage;
    desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    desc.MiscFlags = 0;

    D3D11_SUBRESOURCE_DATA InitData = {0}; 
    InitData.pSysMem = data;
    InitData.SysMemPitch = width * cFormatSize[int(format)];

    bool useInitData = (data != nullptr);

    if (usage == D3D11_USAGE_DYNAMIC)
    {
        useInitData = false;
        desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    }

    m_texture = nullptr;
    device->CreateTexture2D( &desc, useInitData ? &InitData : nullptr, &m_texture );

    if (usage == D3D11_USAGE_DYNAMIC && data)
    {
        Update2D(data);
    }

    device->CreateShaderResourceView(m_texture, nullptr, &m_resourceView);

    m_width = width;
    m_height = height;
    m_bytesPerPixel = cFormatSize[int(format)];
}
Exemple #2
0
int main(){

	Jread = new Map();
	Jread->ReadJSON("world.json");

	int shmid;
	key_t key;
	double *shm;

	int Time = 0;
	double *ez = ez_;
	key = 5678;

	if ((shmid = shmget(key, SHMSZ*sizeof(double), 0666)) < 0) {
	        perror("shmget");
	        exit(1);
	    }

	if ((shm =(double*) shmat(shmid, NULL, 0)) == (double *) -1) {
	        perror("shmat");
	        exit(1);
	    }


	/* solid struct */
	int Cx = 50;
	int Cy = 200;
	int p = 40;
	int valor_metal=0;

	for(Time = 0; Time < fin_time; Time++){

		/*for(int i = 0; i < 100; i++){
			Ez(Cx-p+i,int(round(Cy+2*sqrt(p*i))))=valor_metal;
			Ez(Cx-p+i,int(round(Cy-2*sqrt(p*i))))=valor_metal;
			for(int j = 2*sqrt(p*(i)); j <= 2*(sqrt(p*(i+1))); j++){
				Ez( Cx-p+int(round((j*j)/(4*p))),  Cy+j) = valor_metal;
				Ez( Cx-p+int(round((j*j)/(4*p))),  Cy-j) = valor_metal;
			}
*/
		Jread->ModifyMap(ez);
			/*Ez(Cx-p+i+1,int(round(Cy-2*sqrt(p*i))))=valor_metal;
			Ez(Cx-p+i+1,int(round(Cy+2*sqrt(p*i))))=valor_metal;
			for(int j = 0; j <= ceil(2*(sqrt(p*(i+1))-sqrt(p*(i)))); j++){
					Ez( Cx-p+1+int(round((j*j)/(4*p))),  Cy+j) = valor_metal;
					Ez( Cx-p+1+int(round((j*j)/(4*p))), -(Cy+j)) = valor_metal;
			}
			Ez(Cx-p+i-1,int(round(Cy-2*sqrt(p*i))))=valor_metal;
			Ez(Cx-p+i-1,int(round(Cy+2*sqrt(p*i))))=valor_metal;*/
		//}

		/*if(Time==0){
			for( int i = 0; i < SIZE*SIZE ; i++){
				printf("%.0f ",ez_[i]);
			}
			fflush(stdout);
		}*/
		/*
		for(int i = 0; i < 200; i++){
			for (int j = 0; j < 100; j++){
				Ez(50+i,	150	) = 0;
				Ez(50 , 	150+j) = 0;
				//Ez(250 , 	150+j) = 0;
				Ez(50+i,	250	) = 0;
			}

		}*/

		Update2D(ez_,hx_, hy_);
		//Ez(SIZE/2, SIZE/2) += 10*sin(Time);
		//Ez(SIZE/2, SIZE/2) += 10*exp(-(Time - 30.0) *(Time - 30.0) / 50.0);
		//Ez(Cx, Cy) += 10*exp(-(Time - 30.0) *(Time - 30.0) / 50.0);
		Jread->UpdateSources(ez, Time);

		//Ez(100, 200) += 10*sin(Cdtds/10*Time);
		//printf("Time: %i\n", Time);

		//printf("new\n\n");

		usleep(40000);
		//getchar();

		memcpy(shm, ez_, SIZE*SIZE*sizeof(double));

	}
	return 0;

}