Example #1
0
//-----------------------------------------------------------------------------
// utilities
//-----------------------------------------------------------------------------
bool DoGLSection(Environment &env, Signal &sig, Argument &arg, Image *pImage)
{
#if GURA_USE_MSWIN_DIB
	PIXELFORMATDESCRIPTOR pfd = { 
		sizeof(PIXELFORMATDESCRIPTOR), 1,
		PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL, PFD_TYPE_RGBA,
		static_cast<BYTE>(pImage->GetBitsPerPixel()), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		32, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0
	}; 
	HDC hdc = ::CreateCompatibleDC(nullptr);
	HBITMAP hBmp = pImage->GetHBITMAP();
	HBITMAP hBmpOld = reinterpret_cast<HBITMAP>(::SelectObject(hdc, hBmp));
	int iPixelFormat = ::ChoosePixelFormat(hdc, &pfd);
	::SetPixelFormat(hdc, iPixelFormat, &pfd);
	HGLRC hglrc = ::wglCreateContext(hdc);
	::wglMakeCurrent(hdc, hglrc);
	const Expr_Block *pExprBlock = arg.GetBlockCooked(env);
	if (!sig.IsSignalled()) {
		pExprBlock->Exec(env);
	}
	::wglMakeCurrent(nullptr, nullptr);
	::wglDeleteContext(hglrc);
	::SelectObject(hdc, hBmpOld);
	::DeleteDC(hdc);
	return true;
#elif defined(GURA_ON_DARWIN)
	//*****************
	// not working yet.
	//*****************
	GLsizei width = static_cast<GLsizei>(pImage->GetWidth());
	GLsizei height = static_cast<GLsizei>(pImage->GetHeight());
    CGLError errCode = kCGLNoError;
	GLuint texOut = 0;
	CGLContextObj ctx = nullptr;
	CGLContextObj ctxOrg = CGLGetCurrentContext();
	CGLPixelFormatAttribute attributes[4] = {
		kCGLPFAAccelerated,
		kCGLPFAOpenGLProfile,
		(CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core,
		(CGLPixelFormatAttribute)0
	};
	CGLPixelFormatObj pixelFormat = nullptr;
	GLint numPixelFormats = 0;
	errCode = CGLChoosePixelFormat(attributes, &pixelFormat, &numPixelFormats);
	errCode = CGLCreateContext(pixelFormat, nullptr, &ctx);
	errCode = CGLSetCurrentContext(ctx);
	glGenTextures(1, &texOut);
	glBindTexture(GL_TEXTURE_2D, texOut);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, nullptr);
	GLuint frameBuffer = 0;
	glGenFramebuffers(1, &frameBuffer);
	glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texOut, 0);
	GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (status == GL_FRAMEBUFFER_COMPLETE) {
		const Expr_Block *pExprBlock = arg.GetBlockCooked(env);
		if (!sig.IsSignalled()) {
			pExprBlock->Exec(env);
		}
	}
	do {
		GLenum format = GetImageFormat(env, pImage);
		if (sig.IsSignalled()) return false;
		glBindTexture(GL_TEXTURE_2D, texOut);
		glGetTexImage(GL_TEXTURE_2D, 0, format, GL_UNSIGNED_BYTE, pImage->GetBuffer());
	} while (0);
	glDeleteTextures(1, &texOut);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	CGLSetCurrentContext(ctxOrg);
	CGLDestroyContext(ctx);
	return true;
#else
#if 0
	int width = static_cast<int>(pImage->GetWidth());
	int height = static_cast<int>(pImage->GetHeight());
	GLXFBConfig config;
	Pixmap pixmap = ::XCreatePixmap(nullptr, d, width, height, 32);
	GLXPixmap xid = ::glXCreatePixmap(nullptr, config, pixmap, nullptr);
	GLXContext ctx;
	::glXMakeCurrent(nullptr, xid, ctx);
	const Expr_Block *pExprBlock = arg.GetBlockCooked(env);
	if (!sig.IsSignalled()) {
		pExprBlock->Exec(env);
	}
	::glReadPixels(0, 0, width, height, GL_BGRA_EXT,
									GL_UNSIGNED_BYTE, pImage->GetBuffer());
#endif
#endif
	return true;
}
Example #2
0
void ConfigData::ReadFrameConfigData(ConfigParser &parser)
{
  //Get if the outer log section
  const ConfigToken * frameLogToken = parser.GetToken("FrameLog");
  if(!frameLogToken)
  {
    return;
  }
  
  const ConfigToken *frameTestToken;

  //Get if the log is enabled
  frameTestToken = frameLogToken->GetChildToken("LogEnabled");
  if(frameTestToken)
  { 
    frameTestToken->Get(frameLogEnabled);
  }

  //Get the save format
  frameImageFormat = "jpg";
  frameTestToken = frameLogToken->GetChildToken("SaveFormat");
  if(frameTestToken)
  { 
    GetImageFormat(frameTestToken, frameImageFormat);
  }


  //Get if icon frame buffer saving is enabled
  const ConfigToken *frameIconToken = frameLogToken->GetChildToken("FrameIcon");
  if(frameIconToken)
  {
    //Get if icon saving is enabled
    frameTestToken = frameIconToken->GetChildToken("Enabled");
    if(frameTestToken)
    {
      frameTestToken->Get(frameIconSave);
    }

    //Get the size of the icon image
    frameTestToken = frameIconToken->GetChildToken("Size");
    if(frameTestToken)
    {
      frameTestToken->Get(frameIconSize);
    }

    frameTestToken = frameIconToken->GetChildToken("SaveFormat");
    if(frameTestToken)
    {
      GetImageFormat(frameTestToken, frameIconImageFormat);
    }

  }

  //Load the frame movie token data
  const ConfigToken *frameMovieToken = frameLogToken->GetChildToken("FrameMovie");
  if(frameMovieToken)
  {
    //Get if movie saving is enabled
    frameTestToken = frameMovieToken->GetChildToken("Enabled");
    if(frameTestToken)
    {
      frameTestToken->Get(frameMovieEnabled);
    }

    //Get the width/height movie
    frameTestToken = frameMovieToken->GetChildToken("Size");
    if(frameTestToken)
    {
      if(frameTestToken->GetNumValues() != 2)
      {
        LOGERR(("FrameMovie - Config - Need two width/height values for size"));  
      }
      else
      {
        frameTestToken->Get(frameMovieWidth,0);
        frameTestToken->Get(frameMovieHeight,1);
      }
    }

    //Get the frame rate of the movie
    frameTestToken = frameMovieToken->GetChildToken("FrameRate");
    if(frameTestToken)
    {
      frameTestToken->Get(frameMovieRate);
    }

    //Get the compression
    frameTestToken = frameMovieToken->GetChildToken("Compression");
    if(frameTestToken)
    {
      //Loop for all values
      for(uint i=0; i<frameTestToken->GetNumValues(); i++)
      {
        //Get each codec and add to the array
        string newValue;
        frameTestToken->Get(newValue, i);
        frameMovieCodecs.push_back(newValue);
      }
    }

    //Add a no compression value if none are specified
    if(frameMovieCodecs.size() == 0)
    {
      frameMovieCodecs.push_back("none");
    }
  }


  //Get the pre/post color options
  frameTestToken = frameLogToken->GetChildToken("ColorBufferLog");
  if(frameTestToken)
  { 
    ReadFramePrePostOptions(frameTestToken,framePreColorSave,framePostColorSave, frameDiffColorSave);
  }


  //Get the pre/post depth options
  frameTestToken = frameLogToken->GetChildToken("DepthBufferLog");
  if(frameTestToken)
  { 
    ReadFramePrePostOptions(frameTestToken,framePreDepthSave,framePostDepthSave, frameDiffDepthSave);
  }

  //Get the pre/post stencil options
  frameTestToken = frameLogToken->GetChildToken("StencilBufferLog");
  if(frameTestToken)
  { 
    ReadFramePrePostOptions(frameTestToken,framePreStencilSave,framePostStencilSave, frameDiffStencilSave);
  }

  frameTestToken = frameLogToken->GetChildToken("StencilColors");
  if(frameTestToken)
  {
    //Test for the correct number of colors
    if(frameTestToken->GetNumValues() % 2 == 1)
    {
      LOGERR(("ConfigData::ReadFrameConfigData - Uneven number of stencil colors"));
    }
    else
    {
      int currValue =-1;
      int retIndex;
      uint retColor;

      //Loop for all the value pairs
      for(uint i=0;i<frameTestToken->GetNumValues();i+=2)
      {
        //Get the index/color pair
        if(!frameTestToken->Get(retIndex,i) ||
           !frameTestToken->Get(retColor,i+1))
        {
          LOGERR(("ConfigData::ReadFrameConfigData - Error retrieving stencil color value/index"));
          frameStencilColors.empty();
          break;
        }

        //Check that the index data is sorted
        if(retIndex <= currValue)
        {
          LOGERR(("ConfigData::ReadFrameConfigData - Unsorted array of stencil colors"));
          frameStencilColors.empty();
          break;
        }
        
        //Check bounds
        if(retIndex > 255)
        {
          LOGERR(("ConfigData::ReadFrameConfigData - Stencil index is too large: %d",retIndex));
          frameStencilColors.empty();
          break;
        }
        currValue = retIndex;

        //Add the pair to the return array
        frameStencilColors.push_back(retIndex);
        frameStencilColors.push_back(retColor);
      }
    }
  }

}
Example #3
0
void MainWindow::OnOpenFile(wxCommandEvent& event)
{
	wxFileDialog *dialog = new wxFileDialog(this, wxT("Select image file"), wxT(""), wxT(""), GetImageFormat(), wxOPEN);
	if (dialog)
	{
		dialog->ShowModal();
		m_pTC_InputFile->SetValue(dialog->GetPath());
	}
}
Example #4
0
void ConfigData::ReadImageConfigData(ConfigParser &parser)
{
  //Get if the outer log section
  const ConfigToken * imgToken = parser.GetToken("ImageLog");
  if(!imgToken)
  {
    return;
  }
  const ConfigToken *imgTestToken;

  //Get if the log is enabled
  imgTestToken = imgToken->GetChildToken("LogEnabled");
  if(imgTestToken)
  { 
    imgTestToken->Get(imageLogEnabled);
  }

  //Get if we log the state on render calls 
  imgTestToken = imgToken->GetChildToken("RenderCallStateLog");
  if(imgTestToken)
  { 
    imgTestToken->Get(imageRenderCallStateLog);
  }

  //Get if icon image saving is enabled
  const ConfigToken *imgIconToken = imgToken->GetChildToken("ImageIcon");
  if(imgIconToken)
  {
    //Get if icon saving is enabled
    imgTestToken = imgIconToken->GetChildToken("Enabled");
    if(imgTestToken)
    {
      imgTestToken->Get(imageSaveIcon);
    }

    //Get the size of the icon image
    imgTestToken = imgIconToken->GetChildToken("Size");
    if(imgTestToken)
    {
      imgTestToken->Get(imageIconSize);
    }

    //Get the format of the icon file
    imgTestToken = imgIconToken->GetChildToken("SaveFormat");
    imageIconFormat = "jpg";
    if(imgTestToken)
    {
      GetImageFormat(imgTestToken, imageIconFormat);
    }
  }

  //Get the save formats
  imgTestToken = imgToken->GetChildToken("SaveFormats");
  if(imgTestToken)
  { 
    //Reset all save formats
    imageSavePNG  = false;
    imageSaveTGA  = false;
    imageSaveJPG  = false;

    //Loop for the number of values in the token
    for(uint i=0;i<imgTestToken->GetNumValues();i++)
    {
      string value;
      imgTestToken->Get(value,i);

      if(value == "PNG")
      {
        imageSavePNG = true;
      }
      else if(value == "TGA")
      {
        imageSaveTGA = true;
      }
      else if(value == "JPG")
      {
        imageSaveJPG = true;
      }
      else
      {
        LOGERR(("ConfigData::ReadImageConfigData - Unknown texture save format %s",value.c_str()));
      }
    }
  }

  //Get the flip X axis 
  imgTestToken = imgToken->GetChildToken("FlipXAxis");
  if(imgTestToken)
  { 
    imgTestToken->Get(imageFlipXAxis);
  }

  //Get the cube map tile property 
  imgTestToken = imgToken->GetChildToken("TileCubeMaps");
  if(imgTestToken)
  { 
    imgTestToken->Get(imageCubeMapTile);
  }

  //Get the GL texture saveing formats
  imgTestToken = imgToken->GetChildToken("SaveGLTypes");
  if(imgTestToken)
  { 
    //Reset all save formats
    imageSave1D  = false;
    imageSave2D  = false;
    imageSave3D  = false;
    imageSaveCube= false;

    //Loop for the number of values in the token
    for(uint i=0;i<imgTestToken->GetNumValues();i++)
    {
      string value;
      imgTestToken->Get(value,i);

      if(value == "1D")
      {
        imageSave1D = true;
      }
      else if(value == "2D")
      {
        imageSave2D = true;
      }
      else if(value == "3D")
      {
        imageSave3D = true;
      }
      else if(value == "CUBE")
      {
        imageSaveCube = true;
      }
      else
      {
        LOGERR(("ConfigData::ReadImageConfigData - Unknown GL texture format %s",value.c_str()));
      }
    }
  }

  //Get the p-buffer save property
  imgTestToken = imgToken->GetChildToken("SavePbufferTex");
  if(imgTestToken)
  { 
    imgTestToken->Get(imageSavePBufferTex);
  }
}
Resource* DevILImporter::Import( const String& pFilename, const String& /*pParams*/ )
{
    ILuint  imageName;

    // Load the image. DevIL will guess the type of the image file using it's extension and if needed it's header.
    ilGenImages( 1, &imageName );
    ilBindImage( imageName );

    // Load the image.
    if( !ilLoadImage( const_cast<char*>(pFilename.c_str()) ) )
        throw ResourceImportException( ToString(ilGetError()), Here );

    // Get the image params.
    ILint bytesPerPixel   = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL );
    ILint imgFormat       = ilGetInteger( IL_IMAGE_FORMAT );
    ILint imgWidth        = ilGetInteger( IL_IMAGE_WIDTH );
    ILint imgHeight       = ilGetInteger( IL_IMAGE_HEIGHT );

    // We do not support palettized texture currently, so un-palettize them!
    if( imgFormat == IL_COLOR_INDEX )
    {
        switch( ilGetInteger( IL_PALETTE_TYPE ) )
        {
        case IL_PAL_RGB24:
        case IL_PAL_RGB32:
            imgFormat = IL_RGB;
            break;
        case IL_PAL_BGR24:
        case IL_PAL_BGR32:
            imgFormat = IL_BGR;
            break;
        case IL_PAL_RGBA32:
            imgFormat = IL_RGBA;
            break;
        case IL_PAL_BGRA32:
            imgFormat = IL_BGRA;
            break;
        default:
            debugBreak();
        }

        ilConvertImage( imgFormat, IL_UNSIGNED_BYTE );
        bytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL );
        imgFormat     = ilGetInteger( IL_IMAGE_FORMAT );
    }

    // Find what is the gamedesk internal image format that will be used.
    Image::Format gdImgFormat = GetImageFormat( imgFormat, bytesPerPixel );

    Image newImage;
    newImage.Create( imgWidth, imgHeight, gdImgFormat );
    memcpy( newImage.GetData(), ilGetData(), imgWidth*imgHeight*bytesPerPixel );

    Texture* newTexture = NULL;

    // Allocate and create using image.
    if( imgWidth == 1 || imgHeight == 1 )
    {
        Texture1D* tex = Cast<Texture1D>(Texture1D::StaticClass()->AllocateNew( pFilename ));
        tex->Create( newImage );
        newTexture = tex;
    }
    else
    {
        Texture2D* tex = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( pFilename ));
        tex->Create( newImage );
        newTexture = tex;
    }

    // The DevIL copy of the image is not needed anymore, so destroy it.
    ilDeleteImages( 1, &imageName );

    return newTexture;
}