Move Cg Context to render_chain.cpp

This commit is contained in:
twinaphex 2015-04-05 17:59:03 +02:00
parent 2ae20608e8
commit 1a7d3e3ea0
4 changed files with 50 additions and 51 deletions

View File

@ -110,15 +110,7 @@ static void d3d_deinit_shader(void *data)
(void)d3d; (void)d3d;
(void)data; (void)data;
#ifdef HAVE_CG renderchain_deinit_shader();
if (!d3d->cgCtx)
return;
cgD3D9UnloadAllPrograms();
cgD3D9SetDevice(NULL);
cgDestroyContext(d3d->cgCtx);
d3d->cgCtx = NULL;
#endif
} }
static bool d3d_init_shader(void *data) static bool d3d_init_shader(void *data)
@ -144,16 +136,7 @@ static bool d3d_init_shader(void *data)
return d3d->shader->init(d3d, shader_path); return d3d->shader->init(d3d, shader_path);
#elif defined(HAVE_CG) #elif defined(HAVE_CG)
d3d->cgCtx = cgCreateContext(); return renderchain_init_shader(d3d);
if (!d3d->cgCtx)
return false;
RARCH_LOG("[D3D]: Created shader context.\n");
HRESULT ret = cgD3D9SetDevice(d3d->dev);
if (FAILED(ret))
return false;
return true;
#else #else
return false; return false;
#endif #endif
@ -767,9 +750,6 @@ static void *d3d_init(const video_info_t *info,
vid->dev = NULL; vid->dev = NULL;
vid->dev_rotation = 0; vid->dev_rotation = 0;
vid->needs_restore = false; vid->needs_restore = false;
#ifdef HAVE_CG
vid->cgCtx = NULL;
#endif
#ifdef HAVE_OVERLAY #ifdef HAVE_OVERLAY
vid->overlays_enabled = false; vid->overlays_enabled = false;
#endif #endif
@ -1016,11 +996,6 @@ static bool d3d_init_chain(d3d_video_t *d3d, const video_info_t *video_info)
return false; return false;
if (!renderchain_init(d3d->chain, &d3d->video_info, d3dr, if (!renderchain_init(d3d->chain, &d3d->video_info, d3dr,
#ifdef HAVE_CG
d3d->cgCtx,
#else
NULL,
#endif
&d3d->final_viewport, &link_info, &d3d->final_viewport, &link_info,
d3d->video_info.rgb32 ? RETRO_PIXEL_FORMAT_XRGB8888 : RETRO_PIXEL_FORMAT_RGB565)) d3d->video_info.rgb32 ? RETRO_PIXEL_FORMAT_XRGB8888 : RETRO_PIXEL_FORMAT_RGB565))
{ {

View File

@ -140,9 +140,6 @@ typedef struct d3d_video
bool needs_restore; bool needs_restore;
#ifdef HAVE_CG
CGcontext cgCtx;
#endif
RECT font_rect; RECT font_rect;
RECT font_rect_shifted; RECT font_rect_shifted;

View File

@ -28,9 +28,6 @@ struct lut_info
typedef struct renderchain typedef struct renderchain
{ {
LPDIRECT3DDEVICE dev; LPDIRECT3DDEVICE dev;
#ifdef HAVE_CG
CGcontext cgCtx;
#endif
unsigned pixel_size; unsigned pixel_size;
const video_info_t *video_info; const video_info_t *video_info;
state_tracker_t *tracker; state_tracker_t *tracker;
@ -55,6 +52,8 @@ typedef struct renderchain
std::vector<unsigned> bound_vert; std::vector<unsigned> bound_vert;
} renderchain_t; } renderchain_t;
static CGcontext cgCtx;
static INLINE D3DTEXTUREFILTERTYPE translate_filter(unsigned type) static INLINE D3DTEXTUREFILTERTYPE translate_filter(unsigned type)
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
@ -183,33 +182,33 @@ bool renderchain_compile_shaders(void *data, void *fragment_data,
if (shader.length() > 0) if (shader.length() > 0)
{ {
RARCH_LOG("[D3D Cg]: Compiling shader: %s.\n", shader.c_str()); RARCH_LOG("[D3D Cg]: Compiling shader: %s.\n", shader.c_str());
*fPrg = cgCreateProgramFromFile(chain->cgCtx, CG_SOURCE, *fPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE,
shader.c_str(), fragment_profile, "main_fragment", fragment_opts); shader.c_str(), fragment_profile, "main_fragment", fragment_opts);
if (cgGetLastListing(chain->cgCtx)) if (cgGetLastListing(cgCtx))
RARCH_ERR("[D3D Cg]: Fragment error:\n%s\n", cgGetLastListing(chain->cgCtx)); RARCH_ERR("[D3D Cg]: Fragment error:\n%s\n", cgGetLastListing(cgCtx));
*vPrg = cgCreateProgramFromFile(chain->cgCtx, CG_SOURCE, *vPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE,
shader.c_str(), vertex_profile, "main_vertex", vertex_opts); shader.c_str(), vertex_profile, "main_vertex", vertex_opts);
if (cgGetLastListing(chain->cgCtx)) if (cgGetLastListing(cgCtx))
RARCH_ERR("[D3D Cg]: Vertex error:\n%s\n", cgGetLastListing(chain->cgCtx)); RARCH_ERR("[D3D Cg]: Vertex error:\n%s\n", cgGetLastListing(cgCtx));
} }
else else
{ {
RARCH_LOG("[D3D Cg]: Compiling stock shader.\n"); RARCH_LOG("[D3D Cg]: Compiling stock shader.\n");
*fPrg = cgCreateProgram(chain->cgCtx, CG_SOURCE, stock_program, *fPrg = cgCreateProgram(cgCtx, CG_SOURCE, stock_program,
fragment_profile, "main_fragment", fragment_opts); fragment_profile, "main_fragment", fragment_opts);
if (cgGetLastListing(chain->cgCtx)) if (cgGetLastListing(cgCtx))
RARCH_ERR("[D3D Cg]: Fragment error:\n%s\n", cgGetLastListing(chain->cgCtx)); RARCH_ERR("[D3D Cg]: Fragment error:\n%s\n", cgGetLastListing(cgCtx));
*vPrg = cgCreateProgram(chain->cgCtx, CG_SOURCE, stock_program, *vPrg = cgCreateProgram(cgCtx, CG_SOURCE, stock_program,
vertex_profile, "main_vertex", vertex_opts); vertex_profile, "main_vertex", vertex_opts);
if (cgGetLastListing(chain->cgCtx)) if (cgGetLastListing(cgCtx))
RARCH_ERR("[D3D Cg]: Vertex error:\n%s\n", cgGetLastListing(chain->cgCtx)); RARCH_ERR("[D3D Cg]: Vertex error:\n%s\n", cgGetLastListing(cgCtx));
} }
if (!fPrg || !vPrg) if (!fPrg || !vPrg)
@ -719,6 +718,40 @@ void *renderchain_new(void)
return renderchain; return renderchain;
} }
void renderchain_deinit_shader(void)
{
#ifdef HAVE_CG
if (!cgCtx)
return;
cgD3D9UnloadAllPrograms();
cgD3D9SetDevice(NULL);
cgDestroyContext(d3d->cgCtx);
d3d->cgCtx = NULL;
#endif
}
bool renderchain_init_shader(void *data)
{
d3d_video_t *d3d = (d3d_video_t*)data;
if (!d3d)
return false;
#ifdef HAVE_CG
cgCtx = cgCreateContext();
if (!cgCtx)
return false;
RARCH_LOG("[D3D]: Created shader context.\n");
HRESULT ret = cgD3D9SetDevice(d3d->dev);
if (FAILED(ret))
return false;
#endif
return true;
}
void renderchain_deinit(void *data) void renderchain_deinit(void *data)
{ {
renderchain_t *renderchain = (renderchain_t*)data; renderchain_t *renderchain = (renderchain_t*)data;
@ -731,21 +764,16 @@ void renderchain_deinit(void *data)
bool renderchain_init(void *data, const video_info_t *video_info, bool renderchain_init(void *data, const video_info_t *video_info,
void *dev_, void *dev_,
void *shader_context,
const void *final_viewport_, const void *final_viewport_,
const void *info_data, unsigned fmt) const void *info_data, unsigned fmt)
{ {
const LinkInfo *info = (const LinkInfo*)info_data; const LinkInfo *info = (const LinkInfo*)info_data;
renderchain_t *chain = (renderchain_t*)data; renderchain_t *chain = (renderchain_t*)data;
CGcontext cgCtx_ = (CGcontext)shader_context;
if (!chain) if (!chain)
return false; return false;
chain->dev = (LPDIRECT3DDEVICE)dev_; chain->dev = (LPDIRECT3DDEVICE)dev_;
#ifdef HAVE_CG
chain->cgCtx = cgCtx_;
#endif
chain->video_info = video_info; chain->video_info = video_info;
chain->tracker = NULL; chain->tracker = NULL;
chain->final_viewport = (D3DVIEWPORT*)final_viewport_; chain->final_viewport = (D3DVIEWPORT*)final_viewport_;

View File

@ -68,7 +68,6 @@ void renderchain_deinit(void *data);
bool renderchain_init(void *data, const video_info_t *video_info, bool renderchain_init(void *data, const video_info_t *video_info,
void *dev_, void *dev_,
void *shader_data,
const void *final_viewport_, const void *final_viewport_,
const void *info_data, const void *info_data,
unsigned fmt); unsigned fmt);