mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-29 21:30:53 +00:00
Extract out some common code from GL_Simple_Triangle
This commit is contained in:
@@ -30,50 +30,6 @@ RD_TEST(GL_Simple_Triangle, OpenGLGraphicsTest)
|
||||
"Just draws a simple triangle, using normal pipeline. Basic test that can be used "
|
||||
"for any dead-simple tests that don't require any particular API use";
|
||||
|
||||
std::string common = R"EOSHADER(
|
||||
|
||||
#version 420 core
|
||||
|
||||
#define v2f v2f_block \
|
||||
{ \
|
||||
vec4 pos; \
|
||||
vec4 col; \
|
||||
vec4 uv; \
|
||||
}
|
||||
|
||||
)EOSHADER";
|
||||
|
||||
std::string vertex = R"EOSHADER(
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 1) in vec4 Color;
|
||||
layout(location = 2) in vec2 UV;
|
||||
|
||||
out v2f vertOut;
|
||||
|
||||
void main()
|
||||
{
|
||||
vertOut.pos = vec4(Position.xyz, 1);
|
||||
gl_Position = vertOut.pos;
|
||||
vertOut.col = Color;
|
||||
vertOut.uv = vec4(UV.xy, 0, 1);
|
||||
}
|
||||
|
||||
)EOSHADER";
|
||||
|
||||
std::string pixel = R"EOSHADER(
|
||||
|
||||
in v2f vertIn;
|
||||
|
||||
layout(location = 0, index = 0) out vec4 Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
Color = vertIn.col;
|
||||
}
|
||||
|
||||
)EOSHADER";
|
||||
|
||||
int main()
|
||||
{
|
||||
// initialise, create window, create context, etc
|
||||
@@ -87,16 +43,9 @@ void main()
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vb);
|
||||
glBufferStorage(GL_ARRAY_BUFFER, sizeof(DefaultTri), DefaultTri, 0);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(0));
|
||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(sizeof(Vec3f)));
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V),
|
||||
(void *)(sizeof(Vec3f) + sizeof(Vec4f)));
|
||||
ConfigureDefaultVAO();
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
GLuint program = MakeProgram(common + vertex, common + pixel);
|
||||
GLuint program = MakeProgram(GLDefaultVertex, GLDefaultPixel);
|
||||
|
||||
// make a simple texture so that the structured data includes texture initial states
|
||||
GLuint tex = MakeTexture();
|
||||
|
||||
@@ -25,6 +25,50 @@
|
||||
#include "gl_test.h"
|
||||
#include <stdio.h>
|
||||
|
||||
std::string common = R"EOSHADER(
|
||||
|
||||
#version 420 core
|
||||
|
||||
#define v2f v2f_block \
|
||||
{ \
|
||||
vec4 pos; \
|
||||
vec4 col; \
|
||||
vec4 uv; \
|
||||
}
|
||||
|
||||
)EOSHADER";
|
||||
|
||||
std::string GLDefaultVertex = common + R"EOSHADER(
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 1) in vec4 Color;
|
||||
layout(location = 2) in vec2 UV;
|
||||
|
||||
out v2f vertOut;
|
||||
|
||||
void main()
|
||||
{
|
||||
vertOut.pos = vec4(Position.xyz, 1);
|
||||
gl_Position = vertOut.pos;
|
||||
vertOut.col = Color;
|
||||
vertOut.uv = vec4(UV.xy, 0, 1);
|
||||
}
|
||||
|
||||
)EOSHADER";
|
||||
|
||||
std::string GLDefaultPixel = common + R"EOSHADER(
|
||||
|
||||
in v2f vertIn;
|
||||
|
||||
layout(location = 0, index = 0) out vec4 Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
Color = vertIn.col;
|
||||
}
|
||||
|
||||
)EOSHADER";
|
||||
|
||||
static void APIENTRY debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity,
|
||||
GLsizei length, const GLchar *message, const void *userParam)
|
||||
{
|
||||
@@ -299,6 +343,18 @@ GLuint OpenGLGraphicsTest::MakeFBO()
|
||||
return fbos[fbos.size() - 1];
|
||||
}
|
||||
|
||||
void OpenGLGraphicsTest::ConfigureDefaultVAO()
|
||||
{
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(0));
|
||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(sizeof(Vec3f)));
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V),
|
||||
(void *)(sizeof(Vec3f) + sizeof(Vec4f)));
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
}
|
||||
|
||||
void OpenGLGraphicsTest::pushMarker(const std::string &name)
|
||||
{
|
||||
if(glPushDebugGroup)
|
||||
|
||||
@@ -53,6 +53,8 @@ struct OpenGLGraphicsTest : public GraphicsTest
|
||||
GLuint MakeVAO();
|
||||
GLuint MakeFBO();
|
||||
|
||||
void ConfigureDefaultVAO();
|
||||
|
||||
void pushMarker(const std::string &name);
|
||||
void setMarker(const std::string &name);
|
||||
void popMarker();
|
||||
@@ -74,3 +76,6 @@ struct OpenGLGraphicsTest : public GraphicsTest
|
||||
std::vector<GLuint> bufs, texs, progs, pipes, vaos, fbos;
|
||||
} managedResources;
|
||||
};
|
||||
|
||||
extern std::string GLDefaultVertex;
|
||||
extern std::string GLDefaultPixel;
|
||||
|
||||
Reference in New Issue
Block a user