summaryrefslogtreecommitdiffstats
path: root/tools/render-test/render-gl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/render-test/render-gl.cpp')
-rw-r--r--tools/render-test/render-gl.cpp131
1 files changed, 65 insertions, 66 deletions
diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp
index 7f6e401e5..9c77fe7ba 100644
--- a/tools/render-test/render-gl.cpp
+++ b/tools/render-test/render-gl.cpp
@@ -77,28 +77,28 @@ public:
// Renderer implementation
virtual SlangResult initialize(void* inWindowHandle) override;
- virtual void setClearColor(float const* color) override;
+ virtual void setClearColor(const float color[4]) override;
virtual void clearFrame() override;
virtual void presentFrame() override;
virtual SlangResult captureScreenShot(char const* outputPath) override;
- virtual void serializeOutput(BindingState* state, const char * fileName) override;
- virtual Buffer* createBuffer(BufferDesc const& desc) override;
- virtual InputLayout* createInputLayout(InputElementDesc const* inputElements, UInt inputElementCount) override;
- virtual BindingState * createBindingState(const ShaderInputLayout & layout) override;
+ virtual void serializeOutput(BindingState* state, const char* fileName) override;
+ virtual Buffer* createBuffer(const BufferDesc& desc) override;
+ virtual InputLayout* createInputLayout(const InputElementDesc* inputElements, UInt inputElementCount) override;
+ virtual BindingState * createBindingState(const ShaderInputLayout& layout) override;
virtual ShaderCompiler* getShaderCompiler() override;
virtual void* map(Buffer* buffer, MapFlavor flavor) override;
virtual void unmap(Buffer* buffer) override;
virtual void setInputLayout(InputLayout* inputLayout) override;
virtual void setPrimitiveTopology(PrimitiveTopology topology) override;
- virtual void setBindingState(BindingState * state);
- virtual void setVertexBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* strides, UInt const* offsets) override;
+ virtual void setBindingState(BindingState* state);
+ virtual void setVertexBuffers(UInt startSlot, UInt slotCount, Buffer*const* buffers, const UInt* strides, const UInt* offsets) override;
virtual void setShaderProgram(ShaderProgram* inProgram) override;
- virtual void setConstantBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) override;
+ virtual void setConstantBuffers(UInt startSlot, UInt slotCount, Buffer*const* buffers, const UInt* offsets) override;
virtual void draw(UInt vertexCount, UInt startVertex) override;
virtual void dispatchCompute(int x, int y, int z) override;
// ShaderCompiler implementation
- virtual ShaderProgram* compileProgram(ShaderCompileRequest const& request) override;
+ virtual ShaderProgram* compileProgram(const ShaderCompileRequest& request) override;
protected:
enum
@@ -140,27 +140,26 @@ public:
List<BindingEntryImpl> entries;
};
- void bindBufferImpl(int target, UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets);
+ void bindBufferImpl(int target, UInt startSlot, UInt slotCount, Buffer*const* buffers, const UInt* offsets);
void flushStateForDraw();
GLuint loadShader(GLenum stage, char const* source);
void createInputBuffer(BindingEntryImpl& rs, InputBufferDesc bufDesc, List<unsigned int>& bufferData);
- void debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, GLchar const* message);
+ void debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message);
void createInputTexture(BindingEntryImpl& rs, InputTextureDesc texDesc, InputSamplerDesc samplerDesc);
void createInputSampler(BindingEntryImpl& rs, InputSamplerDesc samplerDesc);
- static void APIENTRY staticDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, GLchar const* message, void const* userParam);
+ static void APIENTRY staticDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam);
static VertexAttributeFormat getVertexAttributeFormat(Format format);
- InputLayoutImpl* boundInputLayout = nullptr;
-
- GLenum boundPrimitiveTopology = GL_TRIANGLES;
-
- HDC deviceContext;
- HGLRC glContext;
- float clearColor[4] = { 0, 0, 0, 0 };
- GLuint boundVertexStreamBuffers[kMaxVertexStreams];
- UInt boundVertexStreamStrides[kMaxVertexStreams];
- UInt boundVertexStreamOffsets[kMaxVertexStreams];
+ HDC m_hdc;
+ HGLRC m_glContext;
+ float m_clearColor[4] = { 0, 0, 0, 0 };
+
+ InputLayoutImpl* m_boundInputLayout = nullptr;
+ GLenum m_boundPrimitiveTopology = GL_TRIANGLES;
+ GLuint m_boundVertexStreamBuffers[kMaxVertexStreams];
+ UInt m_boundVertexStreamStrides[kMaxVertexStreams];
+ UInt m_boundVertexStreamOffsets[kMaxVertexStreams];
// Declare a function pointer for each OpenGL
// extension function we need to load
@@ -174,7 +173,7 @@ Renderer* createGLRenderer()
return new GLRenderer();
}
-void GLRenderer::debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, GLchar const* message)
+void GLRenderer::debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message)
{
::OutputDebugStringA("GL: ");
::OutputDebugStringA(message);
@@ -189,7 +188,7 @@ void GLRenderer::debugCallback(GLenum source, GLenum type, GLuint id, GLenum sev
}
}
-/* static */void APIENTRY GLRenderer::staticDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, GLchar const* message, void const* userParam)
+/* static */void APIENTRY GLRenderer::staticDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
{
((GLRenderer*)userParam)->debugCallback(source, type, id, severity, length, message);
}
@@ -209,7 +208,7 @@ void GLRenderer::debugCallback(GLenum source, GLenum type, GLuint id, GLenum sev
}
}
-void GLRenderer::bindBufferImpl(int target, UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets)
+void GLRenderer::bindBufferImpl(int target, UInt startSlot, UInt slotCount, Buffer*const* buffers, const UInt* offsets)
{
for (UInt ii = 0; ii < slotCount; ++ii)
{
@@ -226,7 +225,7 @@ void GLRenderer::bindBufferImpl(int target, UInt startSlot, UInt slotCount, Buff
void GLRenderer::flushStateForDraw()
{
- auto layout = this->boundInputLayout;
+ auto layout = m_boundInputLayout;
auto attrCount = layout->attributeCount;
for (UInt ii = 0; ii < attrCount; ++ii)
{
@@ -234,15 +233,15 @@ void GLRenderer::flushStateForDraw()
auto streamIndex = attr.streamIndex;
- glBindBuffer(GL_ARRAY_BUFFER, boundVertexStreamBuffers[streamIndex]);
+ glBindBuffer(GL_ARRAY_BUFFER, m_boundVertexStreamBuffers[streamIndex]);
glVertexAttribPointer(
(GLuint)ii,
attr.format.componentCount,
attr.format.componentType,
attr.format.normalized,
- (GLsizei)boundVertexStreamStrides[streamIndex],
- (GLvoid*)(attr.offset + boundVertexStreamOffsets[streamIndex]));
+ (GLsizei)m_boundVertexStreamStrides[streamIndex],
+ (GLvoid*)(attr.offset + m_boundVertexStreamOffsets[streamIndex]));
glEnableVertexAttribArray((GLuint)ii);
}
@@ -252,7 +251,7 @@ void GLRenderer::flushStateForDraw()
}
}
-GLuint GLRenderer::loadShader(GLenum stage, char const* source)
+GLuint GLRenderer::loadShader(GLenum stage, const char* source)
{
// GLSL is monumentally stupid. It officially requires the `#version` directive
// to be the first thing in the file, which wouldn't be so bad but the API
@@ -262,12 +261,12 @@ GLuint GLRenderer::loadShader(GLenum stage, char const* source)
// We are going to solve this problem by doing some surgery on the source
// that was passed in.
- char const* sourceBegin = source;
- char const* sourceEnd = source + strlen(source);
+ const char* sourceBegin = source;
+ const char* sourceEnd = source + strlen(source);
// Look for a version directive in the user-provided source.
- char const* versionBegin = strstr(source, "#version");
- char const* versionEnd = nullptr;
+ const char* versionBegin = strstr(source, "#version");
+ const char* versionEnd = nullptr;
if (versionBegin)
{
// If we found a directive, then scan for the end-of-line
@@ -291,12 +290,12 @@ GLuint GLRenderer::loadShader(GLenum stage, char const* source)
}
enum { kMaxSourceStringCount = 16 };
- GLchar const* sourceStrings[kMaxSourceStringCount];
+ const GLchar* sourceStrings[kMaxSourceStringCount];
GLint sourceStringLengths[kMaxSourceStringCount];
int sourceStringCount = 0;
- char const* stagePrelude = "\n";
+ const char* stagePrelude = "\n";
switch (stage)
{
#define CASE(NAME) case GL_##NAME##_SHADER: stagePrelude = "#define __GLSL_" #NAME "__ 1\n"; break
@@ -311,7 +310,7 @@ GLuint GLRenderer::loadShader(GLenum stage, char const* source)
#undef CASE
}
- char const* prelude =
+ const char* prelude =
"#define __GLSL__ 1\n"
;
@@ -353,7 +352,7 @@ GLuint GLRenderer::loadShader(GLenum stage, char const* source)
if (infoSize > 0)
{
fprintf(stderr, "%s", infoBuffer);
- OutputDebugStringA(infoBuffer);
+ ::OutputDebugStringA(infoBuffer);
}
glDeleteShader(shaderID);
@@ -488,7 +487,7 @@ SlangResult GLRenderer::initialize(void* inWindowHandle)
{
auto windowHandle = (HWND)inWindowHandle;
- deviceContext = ::GetDC(windowHandle);
+ m_hdc = ::GetDC(windowHandle);
PIXELFORMATDESCRIPTOR pixelFormatDesc = { sizeof(PIXELFORMATDESCRIPTOR) };
pixelFormatDesc.nVersion = 1;
@@ -499,11 +498,11 @@ SlangResult GLRenderer::initialize(void* inWindowHandle)
pixelFormatDesc.cStencilBits = 8;
pixelFormatDesc.iLayerType = PFD_MAIN_PLANE;
- int pixelFormatIndex = ChoosePixelFormat(deviceContext, &pixelFormatDesc);
- SetPixelFormat(deviceContext, pixelFormatIndex, &pixelFormatDesc);
+ int pixelFormatIndex = ChoosePixelFormat(m_hdc, &pixelFormatDesc);
+ SetPixelFormat(m_hdc, pixelFormatIndex, &pixelFormatDesc);
- glContext = wglCreateContext(deviceContext);
- wglMakeCurrent(deviceContext, glContext);
+ m_glContext = wglCreateContext(m_hdc);
+ wglMakeCurrent(m_hdc, m_glContext);
auto renderer = glGetString(GL_RENDERER);
auto extensions = glGetString(GL_EXTENSIONS);
@@ -528,7 +527,7 @@ SlangResult GLRenderer::initialize(void* inWindowHandle)
return SLANG_OK;
}
-void GLRenderer::setClearColor(float const* color)
+void GLRenderer::setClearColor(const float color[4])
{
glClearColor(color[0], color[1], color[2], color[3]);
}
@@ -541,10 +540,10 @@ void GLRenderer::clearFrame()
void GLRenderer::presentFrame()
{
glFlush();
- ::SwapBuffers(deviceContext);
+ ::SwapBuffers(m_hdc);
}
-SlangResult GLRenderer::captureScreenShot(char const* outputPath)
+SlangResult GLRenderer::captureScreenShot(const char* outputPath)
{
int width = gWindowWidth;
int height = gWindowHeight;
@@ -595,7 +594,7 @@ ShaderCompiler* GLRenderer::getShaderCompiler()
return this;
}
-Buffer* GLRenderer::createBuffer(BufferDesc const& desc)
+Buffer* GLRenderer::createBuffer(const BufferDesc& desc)
{
// TODO: should derive target from desc...
GLenum target = GL_UNIFORM_BUFFER;
@@ -612,9 +611,9 @@ Buffer* GLRenderer::createBuffer(BufferDesc const& desc)
return (Buffer*)(uintptr_t)bufferID;
}
-InputLayout* GLRenderer::createInputLayout(InputElementDesc const* inputElements, UInt inputElementCount)
+InputLayout* GLRenderer::createInputLayout(const InputElementDesc* inputElements, UInt inputElementCount)
{
- InputLayoutImpl* inputLayout = new InputLayoutImpl();
+ InputLayoutImpl* inputLayout = new InputLayoutImpl;
inputLayout->attributeCount = inputElementCount;
for (UInt ii = 0; ii < inputElementCount; ++ii)
@@ -662,7 +661,7 @@ void GLRenderer::unmap(Buffer* buffer)
void GLRenderer::setInputLayout(InputLayout* inputLayout)
{
- boundInputLayout = (InputLayoutImpl*)inputLayout;
+ m_boundInputLayout = (InputLayoutImpl*)inputLayout;
}
void GLRenderer::setPrimitiveTopology(PrimitiveTopology topology)
@@ -676,10 +675,10 @@ void GLRenderer::setPrimitiveTopology(PrimitiveTopology topology)
#undef CASE
}
- boundPrimitiveTopology = glTopology;
+ m_boundPrimitiveTopology = glTopology;
}
-void GLRenderer::setVertexBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* strides, UInt const* offsets)
+void GLRenderer::setVertexBuffers(UInt startSlot, UInt slotCount, Buffer*const* buffers, const UInt* strides, const UInt* offsets)
{
for (UInt ii = 0; ii < slotCount; ++ii)
{
@@ -688,9 +687,9 @@ void GLRenderer::setVertexBuffers(UInt startSlot, UInt slotCount, Buffer* const*
Buffer* buffer = buffers[ii];
GLuint bufferID = (GLuint)(uintptr_t)buffer;
- boundVertexStreamBuffers[slot] = bufferID;
- boundVertexStreamStrides[slot] = strides[ii];
- boundVertexStreamOffsets[slot] = offsets[ii];
+ m_boundVertexStreamBuffers[slot] = bufferID;
+ m_boundVertexStreamStrides[slot] = strides[ii];
+ m_boundVertexStreamOffsets[slot] = offsets[ii];
}
}
@@ -700,7 +699,7 @@ void GLRenderer::setShaderProgram(ShaderProgram* program)
glUseProgram(programID);
}
-void GLRenderer::setConstantBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets)
+void GLRenderer::setConstantBuffers(UInt startSlot, UInt slotCount, Buffer*const* buffers, const UInt* offsets)
{
bindBufferImpl(GL_UNIFORM_BUFFER, startSlot, slotCount, buffers, offsets);
}
@@ -709,7 +708,7 @@ void GLRenderer::draw(UInt vertexCount, UInt startVertex = 0)
{
flushStateForDraw();
- glDrawArrays(boundPrimitiveTopology, (GLint)startVertex, (GLsizei)vertexCount);
+ glDrawArrays(m_boundPrimitiveTopology, (GLint)startVertex, (GLsizei)vertexCount);
}
void GLRenderer::dispatchCompute(int x, int y, int z)
@@ -717,9 +716,9 @@ void GLRenderer::dispatchCompute(int x, int y, int z)
glDispatchCompute(x, y, z);
}
-BindingState* GLRenderer::createBindingState(const ShaderInputLayout & layout)
+BindingState* GLRenderer::createBindingState(const ShaderInputLayout& layout)
{
- BindingStateImpl * rs = new BindingStateImpl();
+ BindingStateImpl* rs = new BindingStateImpl;
for (auto & entry : layout.entries)
{
BindingEntryImpl rsEntry;
@@ -746,10 +745,10 @@ BindingState* GLRenderer::createBindingState(const ShaderInputLayout & layout)
return (BindingState*)rs;
}
-void GLRenderer::setBindingState(BindingState * state)
+void GLRenderer::setBindingState(BindingState* stateIn)
{
- BindingStateImpl * glState = (BindingStateImpl*)state;
- for (auto & entry : glState->entries)
+ BindingStateImpl* state = (BindingStateImpl*)stateIn;
+ for (auto & entry : state->entries)
{
switch (entry.type)
{
@@ -769,12 +768,12 @@ void GLRenderer::setBindingState(BindingState * state)
}
}
-void GLRenderer::serializeOutput(BindingState* state, const char * fileName)
+void GLRenderer::serializeOutput(BindingState* stateIn, const char* fileName)
{
- BindingStateImpl * glState = (BindingStateImpl*)state;
+ BindingStateImpl * state = (BindingStateImpl*)stateIn;
FILE * f;
fopen_s(&f, fileName, "wt");
- for (auto & entry : glState->entries)
+ for (auto & entry : state->entries)
{
if (entry.isOutput)
{
@@ -791,7 +790,7 @@ void GLRenderer::serializeOutput(BindingState* state, const char * fileName)
// ShaderCompiler interface
-ShaderProgram* GLRenderer::compileProgram(ShaderCompileRequest const& request)
+ShaderProgram* GLRenderer::compileProgram(const ShaderCompileRequest& request)
{
auto programID = glCreateProgram();
if (request.computeShader.name)