static inline void dumpArbProgramUniforms(JSONWriter &json, GLenum target, const char *prefix) { if (!glIsEnabled(target)) { return; } GLint program_parameters = 0; glGetProgramivARB(target, GL_PROGRAM_PARAMETERS_ARB, &program_parameters); if (!program_parameters) { return; } GLint max_program_local_parameters = 0; glGetProgramivARB(target, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &max_program_local_parameters); for (GLint index = 0; index < max_program_local_parameters; ++index) { GLdouble params[4] = {0, 0, 0, 0}; glGetProgramLocalParameterdvARB(target, index, params); if (!params[0] && !params[1] && !params[2] && !params[3]) { continue; } char name[256]; snprintf(name, sizeof name, "%sprogram.local[%i]", prefix, index); json.beginMember(name); json.beginArray(); json.writeFloat(params[0]); json.writeFloat(params[1]); json.writeFloat(params[2]); json.writeFloat(params[3]); json.endArray(); json.endMember(); } GLint max_program_env_parameters = 0; glGetProgramivARB(target, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &max_program_env_parameters); for (GLint index = 0; index < max_program_env_parameters; ++index) { GLdouble params[4] = {0, 0, 0, 0}; glGetProgramEnvParameterdvARB(target, index, params); if (!params[0] && !params[1] && !params[2] && !params[3]) { continue; } char name[256]; snprintf(name, sizeof name, "%sprogram.env[%i]", prefix, index); json.beginMember(name); json.beginArray(); json.writeFloat(params[0]); json.writeFloat(params[1]); json.writeFloat(params[2]); json.writeFloat(params[3]); json.endArray(); json.endMember(); } }
/** * Dump images of current draw drawable/window. */ static void dumpDrawableImages(JSONWriter &json, Context &context) { GLint width, height; if (!getDrawableBounds(&width, &height)) { return; } GLint draw_buffer = GL_NONE; if (context.ES) { draw_buffer = GL_BACK; } else { glGetIntegerv(GL_DRAW_BUFFER, &draw_buffer); glReadBuffer(draw_buffer); } if (draw_buffer != GL_NONE) { GLint read_buffer = GL_NONE; if (!context.ES) { glGetIntegerv(GL_READ_BUFFER, &read_buffer); } GLint alpha_bits = 0; #if 0 // XXX: Ignore alpha until we are able to match the traced visual glGetIntegerv(GL_ALPHA_BITS, &alpha_bits); #endif GLenum format = alpha_bits ? GL_RGBA : GL_RGB; json.beginMember(enumToString(draw_buffer)); dumpReadBufferImage(json, width, height, format); json.endMember(); if (!context.ES) { glReadBuffer(read_buffer); } } if (!context.ES) { GLint depth_bits = 0; glGetIntegerv(GL_DEPTH_BITS, &depth_bits); if (depth_bits) { json.beginMember("GL_DEPTH_COMPONENT"); dumpReadBufferImage(json, width, height, GL_DEPTH_COMPONENT); json.endMember(); } GLint stencil_bits = 0; glGetIntegerv(GL_STENCIL_BITS, &stencil_bits); if (stencil_bits) { json.beginMember("GL_STENCIL_INDEX"); dumpReadBufferImage(json, width, height, GL_STENCIL_INDEX); json.endMember(); } } }
void dumpFramebuffer(JSONWriter &json, ID3D11DeviceContext *pDevice) { json.beginMember("framebuffer"); json.beginObject(); ID3D11RenderTargetView *pRenderTargetViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; ID3D11DepthStencilView *pDepthStencilView; pDevice->OMGetRenderTargets(ARRAYSIZE(pRenderTargetViews), pRenderTargetViews, &pDepthStencilView); for (UINT i = 0; i < ARRAYSIZE(pRenderTargetViews); ++i) { if (!pRenderTargetViews[i]) { continue; } image::Image *image; DXGI_FORMAT dxgiFormat; image = getRenderTargetViewImage(pDevice, pRenderTargetViews[i], &dxgiFormat); if (image) { char label[64]; _snprintf(label, sizeof label, "RENDER_TARGET_%u", i); JSONWriter::ImageDesc imgDesc; imgDesc.depth = 1; imgDesc.format = getDXGIFormatName(dxgiFormat); json.beginMember(label); json.writeImage(image, imgDesc); json.endMember(); // RENDER_TARGET_* delete image; } pRenderTargetViews[i]->Release(); } if (pDepthStencilView) { image::Image *image; DXGI_FORMAT dxgiFormat; image = getDepthStencilViewImage(pDevice, pDepthStencilView, &dxgiFormat); if (image) { JSONWriter::ImageDesc imgDesc; imgDesc.depth = 1; imgDesc.format = getDXGIFormatName(dxgiFormat); json.beginMember("DEPTH_STENCIL"); json.writeImage(image, imgDesc); json.endMember(); delete image; } pDepthStencilView->Release(); } json.endObject(); json.endMember(); // framebuffer }
void dumpFramebuffer(JSONWriter &json, IDirect3DDevice9 *pDevice) { HRESULT hr; json.beginMember("framebuffer"); json.beginObject(); D3DCAPS9 Caps; pDevice->GetDeviceCaps(&Caps); for (UINT i = 0; i < Caps.NumSimultaneousRTs; ++i) { IDirect3DSurface9 *pRenderTarget = NULL; hr = pDevice->GetRenderTarget(i, &pRenderTarget); if (FAILED(hr)) { continue; } if (!pRenderTarget) { continue; } image::Image *image; image = getRenderTargetImage(pDevice, pRenderTarget); if (image) { char label[64]; _snprintf(label, sizeof label, "RENDER_TARGET_%u", i); json.beginMember(label); json.writeImage(image, "UNKNOWN"); json.endMember(); // RENDER_TARGET_* } pRenderTarget->Release(); } IDirect3DSurface9 *pDepthStencil = NULL; hr = pDevice->GetDepthStencilSurface(&pDepthStencil); if (SUCCEEDED(hr) && pDepthStencil) { image::Image *image; image = getSurfaceImage(pDevice, pDepthStencil); if (image) { json.beginMember("DEPTH_STENCIL"); json.writeImage(image, "UNKNOWN"); json.endMember(); // RENDER_TARGET_* } } json.endObject(); json.endMember(); // framebuffer }
static void dumpShaderObj(JSONWriter &json, GLhandleARB shaderObj) { if (!shaderObj) { return; } GLint shader_type = 0; glGetObjectParameterivARB(shaderObj, GL_OBJECT_TYPE_ARB, &shader_type); if (!shader_type) { return; } GLint source_length = 0; glGetObjectParameterivARB(shaderObj, GL_OBJECT_SHADER_SOURCE_LENGTH_ARB, &source_length); if (!source_length) { return; } GLcharARB *source = new GLcharARB[source_length]; GLsizei length = 0; source[0] = 0; glGetShaderSource(shaderObj, source_length, &length, source); json.beginMember(enumToString(shader_type)); json.writeString(source); json.endMember(); delete [] source; }
static void dumpShader(JSONWriter &json, GLuint shader) { if (!shader) { return; } GLint shader_type = 0; glGetShaderiv(shader, GL_SHADER_TYPE, &shader_type); if (!shader_type) { return; } GLint source_length = 0; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &source_length); if (!source_length) { return; } GLchar *source = new GLchar[source_length]; GLsizei length = 0; source[0] = 0; glGetShaderSource(shader, source_length, &length, source); json.beginMember(enumToString(shader_type)); json.writeString(source); json.endMember(); delete [] source; }
static inline void dumpProgram(JSONWriter &json, GLint program) { GLint attached_shaders = 0; glGetProgramiv(program, GL_ATTACHED_SHADERS, &attached_shaders); if (!attached_shaders) { return; } ShaderMap shaderMap; GLuint *shaders = new GLuint[attached_shaders]; GLsizei count = 0; glGetAttachedShaders(program, attached_shaders, &count, shaders); std::sort(shaders, shaders + count); for (GLsizei i = 0; i < count; ++ i) { getShaderSource(shaderMap, shaders[i]); } delete [] shaders; for (ShaderMap::const_iterator it = shaderMap.begin(); it != shaderMap.end(); ++it) { json.beginMember(it->first); json.writeString(it->second); json.endMember(); } }
void dumpTextures(JSONWriter &json, Context &context) { json.beginMember("textures"); json.beginObject(); GLint active_texture = GL_TEXTURE0; glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); GLint max_texture_coords = 0; glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords); GLint max_combined_texture_image_units = 0; glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_combined_texture_image_units); GLint max_units = std::max(max_combined_texture_image_units, max_texture_coords); /* * At least the Android software GL implementation doesn't return the * proper value for this, but rather returns 0. The GL(ES) specification * mandates a minimum value of 2, so use this as a fall-back value. */ max_units = std::max(max_units, 2); for (GLint unit = 0; unit < max_units; ++unit) { GLenum texture = GL_TEXTURE0 + unit; glActiveTexture(texture); dumpTexture(json, context, GL_TEXTURE_1D, GL_TEXTURE_BINDING_1D); dumpTexture(json, context, GL_TEXTURE_2D, GL_TEXTURE_BINDING_2D); dumpTexture(json, context, GL_TEXTURE_3D, GL_TEXTURE_BINDING_3D); dumpTexture(json, context, GL_TEXTURE_RECTANGLE, GL_TEXTURE_BINDING_RECTANGLE); dumpTexture(json, context, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BINDING_CUBE_MAP); } glActiveTexture(active_texture); json.endObject(); json.endMember(); // textures }
/** * Dump the image of the currently bound read buffer. */ static inline void dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format, GLint internalFormat = GL_NONE) { GLint channels = _gl_format_channels(format); if (internalFormat == GL_NONE) { internalFormat = format; } Context context; json.beginObject(); // Tell the GUI this is no ordinary object, but an image json.writeStringMember("__class__", "image"); json.writeNumberMember("__width__", width); json.writeNumberMember("__height__", height); json.writeNumberMember("__depth__", 1); json.writeStringMember("__format__", enumToString(internalFormat)); // Hardcoded for now, but we could chose types more adequate to the // texture internal format json.writeStringMember("__type__", "uint8"); json.writeBoolMember("__normalized__", true); json.writeNumberMember("__channels__", channels); GLenum type = GL_UNSIGNED_BYTE; #if DEPTH_AS_RGBA if (format == GL_DEPTH_COMPONENT) { type = GL_UNSIGNED_INT; channels = 4; } #endif GLubyte *pixels = new GLubyte[width*height*channels]; // TODO: reset imaging state too context.resetPixelPackState(); glReadPixels(0, 0, width, height, format, type, pixels); context.restorePixelPackState(); json.beginMember("__data__"); char *pngBuffer; int pngBufferSize; image::writePixelsToBuffer(pixels, width, height, channels, true, &pngBuffer, &pngBufferSize); //std::cerr <<" Before = "<<(width * height * channels * sizeof *pixels) // <<", after = "<<pngBufferSize << ", ratio = " << double(width * height * channels * sizeof *pixels)/pngBufferSize; json.writeBase64(pngBuffer, pngBufferSize); free(pngBuffer); json.endMember(); // __data__ delete [] pixels; json.endObject(); }
inline void dumpShader(JSONWriter &json, const char *name, T *pShader) { if (!pShader) { return; } /* * There is no method to get the shader byte code, so the creator is supposed to * attach it via the SetPrivateData method. */ std::vector<BYTE> ShaderBytecode = getPrivateData(pShader, GUID_D3DSTATE); if (ShaderBytecode.empty()) { return; } com_ptr<IDisassemblyBuffer> pDisassembly; HRESULT hr; hr = DisassembleShader(&ShaderBytecode[0], ShaderBytecode.size(), &pDisassembly); if (SUCCEEDED(hr)) { json.beginMember(name); json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */); json.endMember(); } }
void dumpTextures(JSONWriter &json, ID3D11DeviceContext *pDevice) { json.beginMember("textures"); json.beginObject(); ID3D11ShaderResourceView *pShaderResourceViews[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT]; pDevice->VSGetShaderResources(0, ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); dumpStageTextures(json, pDevice, "VS", ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); pDevice->HSGetShaderResources(0, ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); dumpStageTextures(json, pDevice, "HS", ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); pDevice->DSGetShaderResources(0, ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); dumpStageTextures(json, pDevice, "DS", ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); pDevice->GSGetShaderResources(0, ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); dumpStageTextures(json, pDevice, "GS", ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); pDevice->PSGetShaderResources(0, ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); dumpStageTextures(json, pDevice, "PS", ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); json.endObject(); json.endMember(); // textures }
inline void dumpShader(JSONWriter &json, const char *name, T *pShader) { if (!pShader) { return; } HRESULT hr; UINT SizeOfData = 0; hr = pShader->GetFunction(NULL, &SizeOfData); if (SUCCEEDED(hr)) { void *pData; pData = malloc(SizeOfData); if (pData) { hr = pShader->GetFunction(pData, &SizeOfData); if (SUCCEEDED(hr)) { com_ptr<IDisassemblyBuffer> pDisassembly; hr = DisassembleShader((const DWORD *)pData, &pDisassembly); if (SUCCEEDED(hr)) { json.beginMember(name); json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */); json.endMember(); } } free(pData); } } }
static inline void dumpTextures(JSONWriter &json) { json.beginMember("textures"); json.beginObject(); GLint active_texture = GL_TEXTURE0; glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); GLint max_texture_coords = 0; glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords); GLint max_combined_texture_image_units = 0; glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_combined_texture_image_units); GLint max_units = std::max(max_combined_texture_image_units, max_texture_coords); for (GLint unit = 0; unit < max_units; ++unit) { GLenum texture = GL_TEXTURE0 + unit; glActiveTexture(texture); dumpTexture(json, GL_TEXTURE_1D, GL_TEXTURE_BINDING_1D); dumpTexture(json, GL_TEXTURE_2D, GL_TEXTURE_BINDING_2D); dumpTexture(json, GL_TEXTURE_3D, GL_TEXTURE_BINDING_3D); dumpTexture(json, GL_TEXTURE_RECTANGLE, GL_TEXTURE_BINDING_RECTANGLE); dumpTexture(json, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BINDING_CUBE_MAP); } glActiveTexture(active_texture); json.endObject(); json.endMember(); // textures }
static void dumpShaders(JSONWriter &json, ID3D10Device *pDevice) { json.beginMember("shaders"); json.beginObject(); com_ptr<ID3D10VertexShader> pVertexShader; pDevice->VSGetShader(&pVertexShader); if (pVertexShader) { dumpShader<ID3D10DeviceChild>(json, "VS", pVertexShader); } com_ptr<ID3D10GeometryShader> pGeometryShader; pDevice->GSGetShader(&pGeometryShader); if (pGeometryShader) { dumpShader<ID3D10DeviceChild>(json, "GS", pGeometryShader); } com_ptr<ID3D10PixelShader> pPixelShader; pDevice->PSGetShader(&pPixelShader); if (pPixelShader) { dumpShader<ID3D10DeviceChild>(json, "PS", pPixelShader); } json.endObject(); json.endMember(); // shaders }
void dumpTextures(JSONWriter &json, IDirect3DDevice9 *pDevice) { HRESULT hr; json.beginMember("textures"); json.beginObject(); for (DWORD Stage = 0; Stage < 16; ++Stage) { com_ptr<IDirect3DBaseTexture9> pTexture; hr = pDevice->GetTexture(Stage, &pTexture); if (FAILED(hr)) { continue; } if (!pTexture) { continue; } D3DRESOURCETYPE Type = pTexture->GetType(); DWORD NumFaces = Type == D3DRTYPE_CUBETEXTURE ? 6 : 1; DWORD NumLevels = pTexture->GetLevelCount(); for (DWORD Face = 0; Face < NumFaces; ++Face) { for (DWORD Level = 0; Level < NumLevels; ++Level) { image::Image *image; image = getTextureImage(pDevice, pTexture, static_cast<D3DCUBEMAP_FACES>(Face), Level); if (image) { char label[128]; if (Type == D3DRTYPE_CUBETEXTURE) { _snprintf(label, sizeof label, "PS_RESOURCE_%lu_FACE_%lu_LEVEL_%lu", Stage, Face, Level); } else { _snprintf(label, sizeof label, "PS_RESOURCE_%lu_LEVEL_%lu", Stage, Level); } json.beginMember(label); json.writeImage(image); json.endMember(); // PS_RESOURCE_* } } } } json.endObject(); json.endMember(); // textures }
void dumpTextures(JSONWriter &json, IDirect3DDevice7 *pDevice) { json.beginMember("textures"); json.beginObject(); json.endObject(); json.endMember(); // textures }
void dumpFramebuffer(JSONWriter &json, ID3D10Device *pDevice) { json.beginMember("framebuffer"); json.beginObject(); ID3D10RenderTargetView *pRenderTargetViews[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT]; ID3D10DepthStencilView *pDepthStencilView; pDevice->OMGetRenderTargets(ARRAYSIZE(pRenderTargetViews), pRenderTargetViews, &pDepthStencilView); for (UINT i = 0; i < ARRAYSIZE(pRenderTargetViews); ++i) { if (!pRenderTargetViews[i]) { continue; } image::Image *image; image = getRenderTargetViewImage(pDevice, pRenderTargetViews[i]); if (image) { char label[64]; _snprintf(label, sizeof label, "RENDER_TARGET_%u", i); json.beginMember(label); json.writeImage(image); json.endMember(); // RENDER_TARGET_* delete image; } pRenderTargetViews[i]->Release(); } if (pDepthStencilView) { image::Image *image; image = getDepthStencilViewImage(pDevice, pDepthStencilView); if (image) { json.beginMember("DEPTH_STENCIL"); json.writeImage(image); json.endMember(); delete image; } pDepthStencilView->Release(); } json.endObject(); json.endMember(); // framebuffer }
/** * Dump images of current draw drawable/window. */ static void dumpDrawableImages(JSONWriter &json) { GLint width, height; if (!getDrawableBounds(&width, &height)) { return; } GLint draw_buffer = GL_NONE; glGetIntegerv(GL_DRAW_BUFFER, &draw_buffer); glReadBuffer(draw_buffer); if (draw_buffer != GL_NONE) { GLint read_buffer = GL_NONE; glGetIntegerv(GL_READ_BUFFER, &read_buffer); GLint alpha_bits = 0; glGetIntegerv(GL_ALPHA_BITS, &alpha_bits); GLenum format = alpha_bits ? GL_RGBA : GL_RGB; json.beginMember(enumToString(draw_buffer)); dumpReadBufferImage(json, width, height, format); json.endMember(); glReadBuffer(read_buffer); } GLint depth_bits = 0; glGetIntegerv(GL_DEPTH_BITS, &depth_bits); if (depth_bits) { json.beginMember("GL_DEPTH_COMPONENT"); dumpReadBufferImage(json, width, height, GL_DEPTH_COMPONENT); json.endMember(); } GLint stencil_bits = 0; glGetIntegerv(GL_STENCIL_BITS, &stencil_bits); if (stencil_bits) { json.beginMember("GL_STENCIL_INDEX"); dumpReadBufferImage(json, width, height, GL_STENCIL_INDEX); json.endMember(); } }
static void dumpRasterizerState(JSONWriter &json, ID3D11DeviceContext *pDeviceContext) { com_ptr<ID3D11RasterizerState> pRasterizerState; pDeviceContext->RSGetState(&pRasterizerState); json.beginMember("RasterizerState"); dumpStateObjectDesc(json, pRasterizerState); json.endMember(); // RasterizerState }
static inline void dumpShaders(JSONWriter &json) { json.beginMember("shaders"); json.beginObject(); dumpCurrentProgram(json); dumpArbProgram(json, GL_FRAGMENT_PROGRAM_ARB); dumpArbProgram(json, GL_VERTEX_PROGRAM_ARB); json.endObject(); json.endMember(); //shaders }
static void dumpProgramUniformsStage(JSONWriter &json, GLint program, const char *stage) { if (program) { json.beginMember(stage); json.beginObject(); dumpProgramUniforms(json, program); json.endObject(); json.endMember(); } }
static void dumpDepthStencilState(JSONWriter &json, ID3D11DeviceContext *pDeviceContext) { com_ptr<ID3D11DepthStencilState> pDepthStencilState; UINT stencilRef; pDeviceContext->OMGetDepthStencilState(&pDepthStencilState, &stencilRef); json.beginMember("DepthStencilState"); dumpStateObjectDesc(json, pDepthStencilState); json.endMember(); // DepthStencilState json.writeIntMember("StencilRef", stencilRef); }
/** * Dump the specified framebuffer attachment. * * In the case of a color attachment, it assumes it is already bound for read. */ static void dumpFramebufferAttachment(JSONWriter &json, Context &context, GLenum target, GLenum attachment, GLenum format) { ImageDesc desc; if (!getFramebufferAttachmentDesc(context, target, attachment, desc)) { return; } json.beginMember(enumToString(attachment)); dumpReadBufferImage(json, desc.width, desc.height, format, desc.internalFormat); json.endMember(); }
/** * Dump the specified framebuffer attachment. * * In the case of a color attachment, it assumes it is already bound for read. */ static void dumpFramebufferAttachment(JSONWriter &json, GLenum target, GLenum attachment, GLenum format) { GLint width = 0, height = 0; if (!getFramebufferAttachmentSize(target, attachment, &width, &height)) { return; } json.beginMember(enumToString(attachment)); dumpReadBufferImage(json, width, height, format); json.endMember(); }
void dumpFramebuffer(JSONWriter &json, IDirect3DDevice7 *pDevice) { HRESULT hr; json.beginMember("framebuffer"); json.beginObject(); com_ptr<IDirectDrawSurface7> pRenderTarget; hr = pDevice->GetRenderTarget(&pRenderTarget); if (SUCCEEDED(hr) && pRenderTarget) { image::Image *image; image = getSurfaceImage(pDevice, pRenderTarget); if (image) { json.beginMember("RENDER_TARGET_0"); json.writeImage(image); json.endMember(); // RENDER_TARGET_* } // Search for a depth-stencil attachment DDSCAPS2 ddsCaps; ZeroMemory(&ddsCaps, sizeof ddsCaps); ddsCaps.dwCaps = DDSCAPS_ZBUFFER; com_ptr<IDirectDrawSurface7> pDepthStencil; hr = pRenderTarget->GetAttachedSurface(&ddsCaps, &pDepthStencil); if (SUCCEEDED(hr) && pDepthStencil) { std::cerr << "found ZS!!\n"; image = getSurfaceImage(pDevice, pDepthStencil); if (image) { json.beginMember("DEPTH_STENCIL"); json.writeImage(image); json.endMember(); // DEPTH_STENCIL } } } json.endObject(); json.endMember(); // framebuffer }
static void dumpParameters(JSONWriter &json, ID3D11DeviceContext *pDeviceContext) { // TODO: dump description of current bound state json.beginMember("parameters"); json.beginObject(); dumpRasterizerState(json, pDeviceContext); dumpBlendState(json, pDeviceContext); dumpDepthStencilState(json, pDeviceContext); json.endObject(); json.endMember(); // parameters }
static void dumpBlendState(JSONWriter &json, ID3D11DeviceContext *pDeviceContext) { com_ptr<ID3D11BlendState> pBlendState; FLOAT BlendFactor[4]; UINT SampleMask; pDeviceContext->OMGetBlendState(&pBlendState, BlendFactor, &SampleMask); json.beginMember("BlendState"); dumpStateObjectDesc(json, pBlendState); json.endMember(); // BlendState json.beginMember("BlendFactor"); json.beginArray(); json.writeFloat(BlendFactor[0]); json.writeFloat(BlendFactor[1]); json.writeFloat(BlendFactor[2]); json.writeFloat(BlendFactor[3]); json.endArray(); json.endMember(); // BlendFactor json.writeIntMember("SampleMask", SampleMask); }
/** * Dump the image of the currently bound read buffer. */ static inline void dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format) { GLint channels = __gl_format_channels(format); json.beginObject(); // Tell the GUI this is no ordinary object, but an image json.writeStringMember("__class__", "image"); json.writeNumberMember("__width__", width); json.writeNumberMember("__height__", height); json.writeNumberMember("__depth__", 1); // Hardcoded for now, but we could chose types more adequate to the // texture internal format json.writeStringMember("__type__", "uint8"); json.writeBoolMember("__normalized__", true); json.writeNumberMember("__channels__", channels); GLubyte *pixels = new GLubyte[width*height*channels]; resetPixelPackState(); glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, pixels); restorePixelPackState(); json.beginMember("__data__"); char *pngBuffer; int pngBufferSize; Image::writePixelsToBuffer(pixels, width, height, channels, false, &pngBuffer, &pngBufferSize); //std::cerr <<" Before = "<<(width * height * channels * sizeof *pixels) // <<", after = "<<pngBufferSize << ", ratio = " << double(width * height * channels * sizeof *pixels)/pngBufferSize; json.writeBase64(pngBuffer, pngBufferSize); free(pngBuffer); json.endMember(); // __data__ delete [] pixels; json.endObject(); }
static void dumpShaders(JSONWriter &json, ID3D11DeviceContext *pDeviceContext) { json.beginMember("shaders"); json.beginObject(); com_ptr<ID3D11VertexShader> pVertexShader; pDeviceContext->VSGetShader(&pVertexShader, NULL, NULL); if (pVertexShader) { dumpShader<ID3D11DeviceChild>(json, "VS", pVertexShader); } com_ptr<ID3D11HullShader> pHullShader; pDeviceContext->HSGetShader(&pHullShader, NULL, NULL); if (pHullShader) { dumpShader<ID3D11DeviceChild>(json, "HS", pHullShader); } com_ptr<ID3D11DomainShader> pDomainShader; pDeviceContext->DSGetShader(&pDomainShader, NULL, NULL); if (pDomainShader) { dumpShader<ID3D11DeviceChild>(json, "DS", pDomainShader); } com_ptr<ID3D11GeometryShader> pGeometryShader; pDeviceContext->GSGetShader(&pGeometryShader, NULL, NULL); if (pGeometryShader) { dumpShader<ID3D11DeviceChild>(json, "GS", pGeometryShader); } com_ptr<ID3D11PixelShader> pPixelShader; pDeviceContext->PSGetShader(&pPixelShader, NULL, NULL); if (pPixelShader) { dumpShader<ID3D11DeviceChild>(json, "PS", pPixelShader); } json.endObject(); json.endMember(); // shaders }
static void dumpAttribArray(JSONWriter &json, const std::string & name, const AttribDesc &desc, const GLbyte *data) { json.beginMember(name); if (desc.size > 1) { json.beginArray(); } for (GLint i = 0; i < desc.size; ++i) { const GLbyte *row = data + desc.arrayStride*i; dumpAttrib(json, desc, row); } if (desc.size > 1) { json.endArray(); } json.endMember(); }