Bug Summary

File:Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp
Location:line 118, column 3
Description:Value stored to 'p' is never read

Annotated Source Code

1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "Common.h"
6#include <math.h>
7
8#include "../../Plugin_VideoOGL/Src/GLUtil.h"
9#include "RasterFont.h"
10#include "SWRenderer.h"
11#include "SWStatistics.h"
12
13#include "OnScreenDisplay.h"
14
15static GLuint s_RenderTarget = 0;
16
17static GLint attr_pos = -1, attr_tex = -1;
18static GLint uni_tex = -1;
19static GLuint program;
20
21// Rasterfont isn't compatible with GLES
22// degasus: I think it does, but I can't test it
23#ifndef USE_GLES
24RasterFont* s_pfont = NULL__null;
25#endif
26
27void SWRenderer::Init()
28{
29}
30
31void SWRenderer::Shutdown()
32{
33 glDeleteProgram__glewDeleteProgram(program);
34 glDeleteTextures(1, &s_RenderTarget);
35#ifndef USE_GLES
36 delete s_pfont;
37 s_pfont = 0;
38#endif
39}
40
41void CreateShaders()
42{
43 static const char *fragShaderText =
44 "varying " PREC " vec2 TexCoordOut;\n"
45 "uniform sampler2D Texture;\n"
46 "void main() {\n"
47 " " PREC " vec4 tmpcolor;\n"
48 " tmpcolor = texture2D(Texture, TexCoordOut);\n"
49 " gl_FragColor = tmpcolor;\n"
50 "}\n";
51 static const char *vertShaderText =
52 "attribute vec4 pos;\n"
53 "attribute vec2 TexCoordIn;\n "
54 "varying vec2 TexCoordOut;\n "
55 "void main() {\n"
56 " gl_Position = pos;\n"
57 " TexCoordOut = TexCoordIn;\n"
58 "}\n";
59
60 program = OpenGL_CompileProgram(vertShaderText, fragShaderText);
61
62 glUseProgram__glewUseProgram(program);
63
64 uni_tex = glGetUniformLocation__glewGetUniformLocation(program, "Texture");
65 attr_pos = glGetAttribLocation__glewGetAttribLocation(program, "pos");
66 attr_tex = glGetAttribLocation__glewGetAttribLocation(program, "TexCoordIn");
67}
68
69void SWRenderer::Prepare()
70{
71 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
72 glPixelStorei(GL_UNPACK_ALIGNMENT0x0CF5, 4); // 4-byte pixel alignment
73 glGenTextures(1, &s_RenderTarget);
74
75 CreateShaders();
76 // TODO: Enable for GLES once RasterFont supports GLES
77#ifndef USE_GLES
78 s_pfont = new RasterFont();
79 glEnable(GL_TEXTURE_2D0x0DE1);
80#endif
81 GL_REPORT_ERRORD()(void)0;
82}
83
84void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color)
85{
86#ifndef USE_GLES
87 int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
88 int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight();
89 glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f,
90 ((color>> 0) & 0xff)/255.0f, ((color>>24) & 0xFF)/255.0f);
91 s_pfont->printMultilineText(pstr,
92 left * 2.0f / (float)nBackbufferWidth - 1,
93 1 - top * 2.0f / (float)nBackbufferHeight,
94 0, nBackbufferWidth, nBackbufferHeight);
95#endif
96}
97
98void SWRenderer::DrawDebugText()
99{
100 char debugtext_buffer[8192];
101 char *p = debugtext_buffer;
102 p[0] = 0;
103
104 if (g_SWVideoConfig.bShowStats)
105 {
106 p+=sprintf(p,"Objects: %i\n",swstats.thisFrame.numDrawnObjects);
107 p+=sprintf(p,"Primitives: %i\n",swstats.thisFrame.numPrimatives);
108 p+=sprintf(p,"Vertices Loaded: %i\n",swstats.thisFrame.numVerticesLoaded);
109
110 p+=sprintf(p,"Triangles Input: %i\n",swstats.thisFrame.numTrianglesIn);
111 p+=sprintf(p,"Triangles Rejected: %i\n",swstats.thisFrame.numTrianglesRejected);
112 p+=sprintf(p,"Triangles Culled: %i\n",swstats.thisFrame.numTrianglesCulled);
113 p+=sprintf(p,"Triangles Clipped: %i\n",swstats.thisFrame.numTrianglesClipped);
114 p+=sprintf(p,"Triangles Drawn: %i\n",swstats.thisFrame.numTrianglesDrawn);
115
116 p+=sprintf(p,"Rasterized Pix: %i\n",swstats.thisFrame.rasterizedPixels);
117 p+=sprintf(p,"TEV Pix In: %i\n",swstats.thisFrame.tevPixelsIn);
118 p+=sprintf(p,"TEV Pix Out: %i\n",swstats.thisFrame.tevPixelsOut);
Value stored to 'p' is never read
119 }
120
121 // Render a shadow, and then the text.
122 SWRenderer::RenderText(debugtext_buffer, 21, 21, 0xDD000000);
123 SWRenderer::RenderText(debugtext_buffer, 20, 20, 0xFFFFFF00);
124}
125#ifdef ANDROID
126// XXX: This /really/ shouldn't be here
127// But for now, we don't have a generic way for all backends to draw the buttons on screen.
128// Once that is implemented, we can remove this
129void DrawButton(GLuint tex, float *coords)
130{
131 //Texture rectangle uses pixel coordinates
132#ifndef USE_GLES
133 GLfloat u_max = (GLfloat)width;
134 GLfloat v_max = (GLfloat)height;
135
136 static const GLfloat texverts[4][2] = {
137 {0, v_max},
138 {0, 0},
139 {u_max, 0},
140 {u_max, v_max}
141 };
142#else
143 static const GLfloat texverts[4][2] = {
144 {0, 1},
145 {0, 0},
146 {1, 0},
147 {1, 1}
148 };
149#endif
150 glBindTexture(TEX2D0x84F5, tex);
151
152 glVertexAttribPointer__glewVertexAttribPointer(attr_pos, 2, GL_FLOAT0x1406, GL_FALSE0, 0, coords);
153 glVertexAttribPointer__glewVertexAttribPointer(attr_tex, 2, GL_FLOAT0x1406, GL_FALSE0, 0, texverts);
154 glEnableVertexAttribArray__glewEnableVertexAttribArray(attr_pos);
155 glEnableVertexAttribArray__glewEnableVertexAttribArray(attr_tex);
156 glActiveTexture__glewActiveTexture(GL_TEXTURE00x84C0);
157 glUniform1i__glewUniform1i(uni_tex, 0);
158 glDrawArrays(GL_TRIANGLE_FAN0x0006, 0, 4);
159 glDisableVertexAttribArray__glewDisableVertexAttribArray(attr_pos);
160 glDisableVertexAttribArray__glewDisableVertexAttribArray(attr_tex);
161
162 glBindTexture(TEX2D0x84F5, 0);
163}
164#endif
165void SWRenderer::DrawTexture(u8 *texture, int width, int height)
166{
167 GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth();
168 GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight();
169
170 // Update GLViewPort
171 glViewport(0, 0, glWidth, glHeight);
172 glScissor(0, 0, glWidth, glHeight);
173
174 glBindTexture(GL_TEXTURE_2D0x0DE1, s_RenderTarget);
175
176 glTexImage2D(GL_TEXTURE_2D0x0DE1, 0, GL_RGBA0x1908, (GLsizei)width, (GLsizei)height, 0, GL_RGBA0x1908, GL_UNSIGNED_BYTE0x1401, texture);
177 glTexParameteri(GL_TEXTURE_2D0x0DE1, GL_TEXTURE_MAG_FILTER0x2800, GL_NEAREST0x2600);
178 glTexParameteri(GL_TEXTURE_2D0x0DE1, GL_TEXTURE_MIN_FILTER0x2801, GL_NEAREST0x2600);
179
180 glUseProgram__glewUseProgram(program);
181 static const GLfloat verts[4][2] = {
182 { -1, -1}, // Left top
183 { -1, 1}, // left bottom
184 { 1, 1}, // right bottom
185 { 1, -1} // right top
186 };
187 static const GLfloat texverts[4][2] = {
188 {0, 1},
189 {0, 0},
190 {1, 0},
191 {1, 1}
192 };
193
194 glVertexAttribPointer__glewVertexAttribPointer(attr_pos, 2, GL_FLOAT0x1406, GL_FALSE0, 0, verts);
195 glVertexAttribPointer__glewVertexAttribPointer(attr_tex, 2, GL_FLOAT0x1406, GL_FALSE0, 0, texverts);
196 glEnableVertexAttribArray__glewEnableVertexAttribArray(attr_pos);
197 glEnableVertexAttribArray__glewEnableVertexAttribArray(attr_tex);
198 glUniform1i__glewUniform1i(uni_tex, 0);
199 glActiveTexture__glewActiveTexture(GL_TEXTURE00x84C0);
200 glDrawArrays(GL_TRIANGLE_FAN0x0006, 0, 4);
201 glDisableVertexAttribArray__glewDisableVertexAttribArray(attr_pos);
202 glDisableVertexAttribArray__glewDisableVertexAttribArray(attr_tex);
203
204 glBindTexture(GL_TEXTURE_2D0x0DE1, 0);
205 GL_REPORT_ERRORD()(void)0;
206}
207
208void SWRenderer::SwapBuffer()
209{
210 // Do our OSD callbacks
211 OSD::DoCallbacks(OSD::OSD_ONFRAME);
212
213 DrawDebugText();
214
215 glFlush();
216
217 GLInterface->Swap();
218
219 swstats.ResetFrame();
220
221 glClear(GL_COLOR_BUFFER_BIT0x00004000 | GL_DEPTH_BUFFER_BIT0x00000100);
222
223 GL_REPORT_ERRORD()(void)0;
224}